SlideShare a Scribd company logo
1 of 20
Download to read offline
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

Bt0074, oops with java
Bt0074, oops with javaBt0074, oops with java
Bt0074, oops with javasmumbahelp
 
Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6solutionjug4
 
Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6helpido9
 
MC0078 SMU 2013 Fall session
MC0078 SMU 2013 Fall sessionMC0078 SMU 2013 Fall session
MC0078 SMU 2013 Fall sessionNarinder Kumar
 
Unit of competency
Unit of competencyUnit of competency
Unit of competencyloidasacueza
 
Interface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementationInterface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementationHoneyChintal
 
What are Generics in Java | Java Generics Tutorial | Edureka
What are Generics in Java | Java Generics Tutorial | EdurekaWhat are Generics in Java | Java Generics Tutorial | Edureka
What are Generics in Java | Java Generics Tutorial | EdurekaEdureka!
 
Object Oriented Programming - 3. Java Programming
Object Oriented Programming - 3. Java ProgrammingObject Oriented Programming - 3. Java Programming
Object Oriented Programming - 3. Java ProgrammingAndiNurkholis1
 
Java interfaces
Java interfacesJava interfaces
Java interfacesjehan1987
 
Chapter 9 Interface
Chapter 9 InterfaceChapter 9 Interface
Chapter 9 InterfaceOUM SAOKOSAL
 
Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6ashhadiqbal
 
Xamarin: Inheritance and Polymorphism
Xamarin: Inheritance and PolymorphismXamarin: Inheritance and Polymorphism
Xamarin: Inheritance and PolymorphismEng Teong Cheah
 
Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1sotlsoc
 
Exception Handling in C#
Exception Handling in C#Exception Handling in C#
Exception Handling in C#Abid Kohistani
 

What's hot (19)

Bt0074, oops with java
Bt0074, oops with javaBt0074, oops with java
Bt0074, oops with java
 
Annotations
AnnotationsAnnotations
Annotations
 
Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6
 
Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6
 
Interface in java
Interface in javaInterface in java
Interface in java
 
MC0078 SMU 2013 Fall session
MC0078 SMU 2013 Fall sessionMC0078 SMU 2013 Fall session
MC0078 SMU 2013 Fall session
 
Unit of competency
Unit of competencyUnit of competency
Unit of competency
 
Interface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementationInterface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementation
 
What are Generics in Java | Java Generics Tutorial | Edureka
What are Generics in Java | Java Generics Tutorial | EdurekaWhat are Generics in Java | Java Generics Tutorial | Edureka
What are Generics in Java | Java Generics Tutorial | Edureka
 
Object Oriented Programming - 3. Java Programming
Object Oriented Programming - 3. Java ProgrammingObject Oriented Programming - 3. Java Programming
Object Oriented Programming - 3. Java Programming
 
Analyzing Java Program
Analyzing Java Program Analyzing Java Program
Analyzing Java Program
 
Chapter 09
Chapter 09Chapter 09
Chapter 09
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Chapter 9 Interface
Chapter 9 InterfaceChapter 9 Interface
Chapter 9 Interface
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6
 
Xamarin: Inheritance and Polymorphism
Xamarin: Inheritance and PolymorphismXamarin: Inheritance and Polymorphism
Xamarin: Inheritance and Polymorphism
 
Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1
 
Exception Handling in C#
Exception Handling in C#Exception Handling in C#
Exception Handling in C#
 

Similar to Basics of java 1

Similar to Basics of java 1 (20)

01slide
01slide01slide
01slide
 
01slide
01slide01slide
01slide
 
Java intro
Java introJava intro
Java intro
 
01slide
01slide01slide
01slide
 
Core java-introduction
Core java-introductionCore java-introduction
Core java-introduction
 
01slide (1)ffgfefge
01slide (1)ffgfefge01slide (1)ffgfefge
01slide (1)ffgfefge
 
Intro to programing with java-lecture 1
Intro to programing with java-lecture 1Intro to programing with java-lecture 1
Intro to programing with java-lecture 1
 
Java for Mainframers
Java for MainframersJava for Mainframers
Java for Mainframers
 
Professional-core-java-training
Professional-core-java-trainingProfessional-core-java-training
Professional-core-java-training
 
lecture 6
 lecture 6 lecture 6
lecture 6
 
Introduction to computer science
Introduction to computer scienceIntroduction to computer science
Introduction to computer science
 
Professional-core-java-training
Professional-core-java-trainingProfessional-core-java-training
Professional-core-java-training
 
Intro Java Rev010
Intro Java Rev010Intro Java Rev010
Intro Java Rev010
 
Java lab1 manual
Java lab1 manualJava lab1 manual
Java lab1 manual
 
Classes and Objects
Classes and ObjectsClasses and Objects
Classes and Objects
 
Java Standard edition(Java ) programming Basics for beginner's
Java Standard edition(Java ) programming Basics  for beginner'sJava Standard edition(Java ) programming Basics  for beginner's
Java Standard edition(Java ) programming Basics for beginner's
 
01slide
01slide01slide
01slide
 
Chapter1pp
Chapter1ppChapter1pp
Chapter1pp
 
Understanding And Using Reflection
Understanding And Using ReflectionUnderstanding And Using Reflection
Understanding And Using Reflection
 
Java syntax-and-grammars-oct8
Java syntax-and-grammars-oct8Java syntax-and-grammars-oct8
Java syntax-and-grammars-oct8
 

Recently uploaded

Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Jeffrey Haguewood
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Karmanjay Verma
 
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...itnewsafrica
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialJoão Esperancinha
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsYoss Cohen
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Nikki Chapple
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 

Recently uploaded (20)

Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#
 
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorial
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platforms
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 

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

  1. 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.