SlideShare a Scribd company logo
Basics of JAVA
Course Objectives
 Create, compile, and run Java programs
 JAVA Anatomy
 I/O
 Java Collections Framework Methods
 Threads
 Reflection
 Serialization
 Networking
 RMI
 JDBC
2
Course Objectives, cont.
You will be able to
 Write simple programs using primitive data types,
control statements, methods, and arrays.
 Create and use methods
 Establish a firm foundation on Java concepts
3
Getting Started with Java
Programming
A Simple Java Application
Compiling Programs
Executing Applications
4
A Simple Application
Example 1.1
//This application program prints Welcome
//to Java!
package chapter1;
public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}
5
RunRunSourceSource
NOTE: To run the program,
install slide files on hard
disk.
Creating and Compiling Programs
 On command line
 javac file.java
6
Source Code
Create/Modify Source Code
Compile Source Code
i.e. javac Welcome.java
Bytecode
Run Byteode
i.e. java Welcome
Result
If compilation errors
If runtime errors or incorrect result
Executing Applications
 On command line
 java classname
7
Java
Interpreter
on Windows
Java
Interpreter
on Sun Solaris
Java
Interpreter
on Linux
Bytecode
...
Example
javac Welcome.java
java Welcome
output:...
8
Compiling and Running a Program
9
Where are the files
stored in the
directory?
c:example
Package
1
Welcome.class
Welcome.java
Package2
.
.
.
Java source files and class files for topic 2
packagex Java source files and class files for topicx
Welcome.java~
Anatomy of a Java Program
 Comments
 Package
 Reserved words
 Modifiers
 Statements
 Blocks
 Classes
 Methods
 The main method
10
Comments
 In Java, comments are preceded by two slashes
(//) in a line, or enclosed between /* and */ in one
or multiple lines. When the compiler sees //, it ignores
all text after // in the same line. When it sees /*, it
scans for the next */ and ignores any text
between /* and */.
11
Package
 The second line in the program (package
chapter1;) specifies a package name, chapter1, for
the class Welcome. Forte compiles the source code
in Welcome.java, generates Welcome.class, and
stores Welcome.class in the chapter1 folder.
12
Reserved Words
 Reserved words or keywords are words that have a
specific meaning to the compiler and cannot be used
for other purposes in the program. For example, when
the compiler sees the word class, it understands that the
word after class is the name for the class. Other reserved
words in Example 1.1 are public, static, and void.
13
Modifiers
Java uses certain reserved words called modifiers that
specify the properties of the data, methods, and
classes and how they can be used. Examples of
modifiers are public and static. Other modifiers are
private, final, abstract, and protected. A public
datum, method, or class can be accessed by other
programs. A private datum or method cannot be
accessed by other programs.
14
Statements
A statement represents an action or a sequence of
actions. The statement System.out.println("Welcome to
Java!") in the program in Example 1.1 is a statement to
display the greeting "Welcome to Java!" Every
statement in Java ends with a semicolon (;).
15
Blocks
16
A pair of braces in a program forms a block that
groups components of a program.
public class Test {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}
Class block
Method block
Classes
The class is the essential Java construct. A class is a
template or blueprint for objects. To program in Java, you
must understand classes and be able to write and use
them. The mystery of the class will continue to be
unveiled throughout this book. For now, though,
understand that a program is defined by using one or
more classes.
17
Methods
What is System.out.println? It is a method: a collection
of statements that performs a sequence of operations
to display a message on the console. It can be used
even without fully understanding the details of how it
works. It is used by invoking a statement with a string
argument. The string argument is enclosed within
parentheses. In this case, the argument is "Welcome
to Java!" You can call the same println method with a
different argument to print a different message.
18
main Method
The main method provides the control of program
flow. The Java interpreter executes the application by
invoking the main method.
 
The main method looks like this:
 
public static void main(String[] args) {
// Statements;
}
19
The exit Method
Use Exit to terminate the program and stop all threads.
NOTE: When your program starts, a thread is spawned
to run the program. When the showMessageDialog is
invoked, a separate thread is spawned to run this
method. The thread is not terminated even you close
the dialog box. To terminate the thread, you have to
invoke the exit method.
20

More Related Content

What's hot (19)

DOCX
Bt0074, oops with java
smumbahelp
 
PPTX
Annotations
swapna reniguntla
 
DOCX
Cis 355 i lab 1 of 6
solutionjug4
 
DOCX
Cis 355 i lab 1 of 6
helpido9
 
PPT
Interface in java
Lovely Professional University
 
DOC
MC0078 SMU 2013 Fall session
Narinder Kumar
 
DOCX
Unit of competency
loidasacueza
 
PPTX
Interface in java ,multiple inheritance in java, interface implementation
HoneyChintal
 
PDF
What are Generics in Java | Java Generics Tutorial | Edureka
Edureka!
 
PDF
Object Oriented Programming - 3. Java Programming
AndiNurkholis1
 
DOCX
Analyzing Java Program
cristy nazareno
 
PPT
Chapter 09
Graham Royce
 
PPTX
Java interfaces
jehan1987
 
PPT
Chapter 9 Interface
OUM SAOKOSAL
 
PPTX
Interface in java
PhD Research Scholar
 
DOCX
Cis 355 ilab 1 of 6
ashhadiqbal
 
PDF
Xamarin: Inheritance and Polymorphism
Eng Teong Cheah
 
PPTX
Chapter 2.1
sotlsoc
 
PPTX
Exception Handling in C#
Abid Kohistani
 
Bt0074, oops with java
smumbahelp
 
Annotations
swapna reniguntla
 
Cis 355 i lab 1 of 6
solutionjug4
 
Cis 355 i lab 1 of 6
helpido9
 
MC0078 SMU 2013 Fall session
Narinder Kumar
 
Unit of competency
loidasacueza
 
Interface in java ,multiple inheritance in java, interface implementation
HoneyChintal
 
What are Generics in Java | Java Generics Tutorial | Edureka
Edureka!
 
Object Oriented Programming - 3. Java Programming
AndiNurkholis1
 
Analyzing Java Program
cristy nazareno
 
Chapter 09
Graham Royce
 
Java interfaces
jehan1987
 
Chapter 9 Interface
OUM SAOKOSAL
 
Interface in java
PhD Research Scholar
 
Cis 355 ilab 1 of 6
ashhadiqbal
 
Xamarin: Inheritance and Polymorphism
Eng Teong Cheah
 
Chapter 2.1
sotlsoc
 
Exception Handling in C#
Abid Kohistani
 

Similar to Basics of java 1 (20)

PPT
Java intro
husnara mohammad
 
PPT
01slide
cdclabs_123
 
PPT
01slide
Usha Sri
 
PPT
Core java-introduction
Ramlal Pawar
 
PPT
Java Standard edition(Java ) programming Basics for beginner's
momin6
 
PPT
01slide
Horesh Kumar
 
PPT
01slide (1)ffgfefge
bsnl007
 
PPT
Java introduction
logeswarisaravanan
 
PPTX
objectorientedprogrammingCHAPTER 2 (OOP).pptx
tutorialclassroomhit
 
PDF
Core Java Tutorial
eMexo Technologies
 
PDF
Professional-core-java-training
Vibrant Technologies & Computers
 
PPT
Java course-in-mumbai
vibrantuser
 
PPTX
1.Intro--Why Java.pptx
YounasKhan542109
 
PPTX
JAVA PROGRAMING NOTE FOR BEGINNERS 20242
boatengsolo963
 
PPT
Chapter 1 java
ahmed abugharsa
 
PPT
Professional-core-java-training
Vibrant Technologies & Computers
 
PPT
INTRODUCTION TO JAVA APPLICATION
Ajit Yadav
 
PPTX
VMC___JAVA-THIRD QUARTER-SHS TWELVE.pptx
michellebacayplacide
 
PPTX
Java programmingjsjdjdjdjdjdjdjdjdiidiei
rajputtejaswa12
 
Java intro
husnara mohammad
 
01slide
cdclabs_123
 
01slide
Usha Sri
 
Core java-introduction
Ramlal Pawar
 
Java Standard edition(Java ) programming Basics for beginner's
momin6
 
01slide
Horesh Kumar
 
01slide (1)ffgfefge
bsnl007
 
Java introduction
logeswarisaravanan
 
objectorientedprogrammingCHAPTER 2 (OOP).pptx
tutorialclassroomhit
 
Core Java Tutorial
eMexo Technologies
 
Professional-core-java-training
Vibrant Technologies & Computers
 
Java course-in-mumbai
vibrantuser
 
1.Intro--Why Java.pptx
YounasKhan542109
 
JAVA PROGRAMING NOTE FOR BEGINNERS 20242
boatengsolo963
 
Chapter 1 java
ahmed abugharsa
 
Professional-core-java-training
Vibrant Technologies & Computers
 
INTRODUCTION TO JAVA APPLICATION
Ajit Yadav
 
VMC___JAVA-THIRD QUARTER-SHS TWELVE.pptx
michellebacayplacide
 
Java programmingjsjdjdjdjdjdjdjdjdiidiei
rajputtejaswa12
 
Ad

Recently uploaded (20)

PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
Ad

Basics of java 1

  • 2. Course Objectives  Create, compile, and run Java programs  JAVA Anatomy  I/O  Java Collections Framework Methods  Threads  Reflection  Serialization  Networking  RMI  JDBC 2
  • 3. Course Objectives, cont. You will be able to  Write simple programs using primitive data types, control statements, methods, and arrays.  Create and use methods  Establish a firm foundation on Java concepts 3
  • 4. Getting Started with Java Programming A Simple Java Application Compiling Programs Executing Applications 4
  • 5. A Simple Application Example 1.1 //This application program prints Welcome //to Java! package chapter1; public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } } 5 RunRunSourceSource NOTE: To run the program, install slide files on hard disk.
  • 6. Creating and Compiling Programs  On command line  javac file.java 6 Source Code Create/Modify Source Code Compile Source Code i.e. javac Welcome.java Bytecode Run Byteode i.e. java Welcome Result If compilation errors If runtime errors or incorrect result
  • 7. Executing Applications  On command line  java classname 7 Java Interpreter on Windows Java Interpreter on Sun Solaris Java Interpreter on Linux Bytecode ...
  • 9. Compiling and Running a Program 9 Where are the files stored in the directory? c:example Package 1 Welcome.class Welcome.java Package2 . . . Java source files and class files for topic 2 packagex Java source files and class files for topicx Welcome.java~
  • 10. Anatomy of a Java Program  Comments  Package  Reserved words  Modifiers  Statements  Blocks  Classes  Methods  The main method 10
  • 11. Comments  In Java, comments are preceded by two slashes (//) in a line, or enclosed between /* and */ in one or multiple lines. When the compiler sees //, it ignores all text after // in the same line. When it sees /*, it scans for the next */ and ignores any text between /* and */. 11
  • 12. Package  The second line in the program (package chapter1;) specifies a package name, chapter1, for the class Welcome. Forte compiles the source code in Welcome.java, generates Welcome.class, and stores Welcome.class in the chapter1 folder. 12
  • 13. Reserved Words  Reserved words or keywords are words that have a specific meaning to the compiler and cannot be used for other purposes in the program. For example, when the compiler sees the word class, it understands that the word after class is the name for the class. Other reserved words in Example 1.1 are public, static, and void. 13
  • 14. Modifiers Java uses certain reserved words called modifiers that specify the properties of the data, methods, and classes and how they can be used. Examples of modifiers are public and static. Other modifiers are private, final, abstract, and protected. A public datum, method, or class can be accessed by other programs. A private datum or method cannot be accessed by other programs. 14
  • 15. Statements A statement represents an action or a sequence of actions. The statement System.out.println("Welcome to Java!") in the program in Example 1.1 is a statement to display the greeting "Welcome to Java!" Every statement in Java ends with a semicolon (;). 15
  • 16. Blocks 16 A pair of braces in a program forms a block that groups components of a program. public class Test { public static void main(String[] args) { System.out.println("Welcome to Java!"); } } Class block Method block
  • 17. Classes The class is the essential Java construct. A class is a template or blueprint for objects. To program in Java, you must understand classes and be able to write and use them. The mystery of the class will continue to be unveiled throughout this book. For now, though, understand that a program is defined by using one or more classes. 17
  • 18. Methods What is System.out.println? It is a method: a collection of statements that performs a sequence of operations to display a message on the console. It can be used even without fully understanding the details of how it works. It is used by invoking a statement with a string argument. The string argument is enclosed within parentheses. In this case, the argument is "Welcome to Java!" You can call the same println method with a different argument to print a different message. 18
  • 19. main Method The main method provides the control of program flow. The Java interpreter executes the application by invoking the main method.   The main method looks like this:   public static void main(String[] args) { // Statements; } 19
  • 20. The exit Method Use Exit to terminate the program and stop all threads. NOTE: When your program starts, a thread is spawned to run the program. When the showMessageDialog is invoked, a separate thread is spawned to run this method. The thread is not terminated even you close the dialog box. To terminate the thread, you have to invoke the exit method. 20

Editor's Notes

  • #2: First Class: Introduction, Prerequisites, Advices, Syllabus Lab 1: Create a Java Project, Compile, and Run. Show syntax errors Print program Capture screen shots, and save it in Word, and print it. Homework One: Check in the class randomly.