SlideShare a Scribd company logo
1 of 34
Introduction to
Java Programming, 4E

    Y. Daniel Liang
Introduction
3 Course Objectives
3 Organization of the Book




                             2
Course Objectives
3   Upon completing the course, you will understand
    –   Create, compile, and run Java programs
    –   Primitive data types
    –   Java control flow
    –   Methods
    –   Arrays (for teaching Java in two semesters, this could be the end)
    –   Object-oriented programming
    –   Core Java classes (Swing, exception, internationalization,
        multithreading, multimedia, I/O, networking, Java
        Collections Framework)


                                                                        3
Course Objectives, cont.
3   You will be able to
    – Develop programs using Forte
    – Write simple programs using primitive data
      types, control statements, methods, and arrays.
    – Create and use methods
    – Develop a GUI interface and Java applets
    – Write interesting projects
    – Establish a firm foundation on Java concepts


                                                        4
Book Chapters
3   Part I: Fundamentals of Programming

    – Chapter 1 Introduction to Java
    – Chapter 2 Primitive Data Types and Operations
    – Chapter 3 Control Statements
    – Chapter 4 Methods
    – Chapter 5 Arrays



                                                      5
Book Chapters, cont.
3   Part II: Object-Oriented Programming

    – Chapter 6 Objects and Classes
    – Chapter 7 Strings
    – Chapter 8 Class Inheritance and Interfaces
    – Chapter 9 Object-Oriented Software Development




                                                   6
Book Chapters, cont.
3   Part III: GUI Programming

    – Chapter 10 Getting Started with GUI Programming
    – Chapter 11 Creating User Interfaces
    – Chapter 12 Applets and Advanced GUI




                                                   7
Book Chapters, cont.
3   Part IV: Developing Comprehensive Projects

    – Chapter 13 Exception Handling
    – Chapter 14 Internationalization
    – Chapter 15 Multithreading
    – Chapter 16 Multimedia
    – Chapter 17 Input and Output
    – Chapter 18 Networking
    – Chapter 19 Java Data Structures


                                                 8
Chapter 1 Introduction to Java
              and Forte
3 What Is Java?
3 Getting Started With Java Programming
    – Create, Compile and Running a Java
      Application




                                           9
What Is Java?
3   History
3   Characteristics of Java




                               10
History
3   James Gosling and Sun Microsystems
3   Oak
3   Java, May 20, 1995, Sun World
3   HotJava
    – The first Java-enabled Web browser
3   JDK Evolutions
3   J2SE, J2ME, and J2EE (not mentioned in the
    book, but could discuss here optionally)
                                            11
Characteristics of Java
3   Java is simple
3   Java is object-oriented
3   Java is distributed
3   Java is interpreted
3   Java is robust
3   Java is secure
3   Java is architecture-neutral
3   Java is portable
3   Java’s performance
3   Java is multithreaded
3   Java is dynamic

                                       12
JDK Versions
3   JDK 1.02 (1995)
3   JDK 1.1 (1996)
3   Java 2 SDK v 1.2 (a.k.a JDK 1.2, 1998)
3   Java 2 SDK v 1.3 (a.k.a JDK 1.3, 2000)
3   Java 2 SDK v 1.4 (a.k.a JDK 1.4, 2002)




                                             13
JDK Editions
3   Java Standard Edition (J2SE)
    – J2SE can be used to develop client-side standalone
      applications or applets.
3   Java Enterprise Edition (J2EE)
    – J2EE can be used to develop server-side applications
      such as Java servlets and Java ServerPages.
3   Java Micro Edition (J2ME).
    – J2ME can be used to develop applications for mobile
      devices such as cell phones.


This book uses J2SE to introduce Java
 programming.
                                                       14
Java IDE Tools
3   Forte by Sun MicroSystems
3   Borland JBuilder
3   Microsoft Visual J++
3   WebGain Café
3   IBM Visual Age for Java




                                15
Getting Started with Java
             Programming
3A   Simple Java Application
3 Compiling   Programs
3 Executing   Applications




                                   16
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!");
  }
}
       Source                   Run
                       NOTE: To run the program,
                         install slide files on hard
                         disk.                         17
Creating and Compiling Programs
                        Create/Modify Source Code

3   On command line
    – javac file.java
                              Source Code




                          Compile Source Code
                         i.e. javac Welcome.java

                                       If compilation errors




                                Bytecode




                               Run Byteode
                            i.e. java Welcome




                                 Result




                                       If runtime errors or incorrect result


                                                                          18
Executing Applications
3   On command line
    – java classname


                                 Bytecode




        Java          Java                             Java
     Interpreter   Interpreter                      Interpreter
                                            ...
    on Windows      on Linux                      on Sun Solaris




                                                                   19
Example
javac Welcome.java

java Welcome

output:...




                         20
Compiling and Running a Program
                                                              Where are the files
                                 Welcome.java
                                                              stored in the
c:example                                                    directory?
                 chapter1        Welcome.class

                                 Welcome.java~


                 chapter2    Java source files and class files for Chapter 2


             .
             .
             .
                 chapter19   Java source files and class files for Chapter 19




                                                                                21
Anatomy of a Java Program
3 Comments
3 Package
3 Reserved words
3 Modifiers
3 Statements
3 Blocks
3 Classes
3 Methods
3 The main method

                                22
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 /*,
                          23
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.
                                   24
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
                            25
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. Modifiers are discussed in
Chapter 6, "Objects and Classes."       26
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
                          27
Blocks
A pair of braces in a program
forms a block that groups
components of a program.
  public class Test {
                                                               Class block
    public static void main(String[] args) {
      System.out.println("Welcome to Java!");   Method block
    }
  }




                                                                   28
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   29
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     30
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) {                     31
Displaying Text in a Message
            Dialog Box
you can use the showMessageDialog
method in the JOptionPane class.
JOptionPane is one of the many
predefined classes in the Java system,
which can be reused rather than
“reinventing the wheel.”
        Source            Run
                                     32
The showMessageDialog Method
JOptionPane.showMessageDialog(null, "Welcome
to Java!",
  "Example 1.2",
JOptionPane.INFORMATION_MESSAGE));




                                         33
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.
                                         34

More Related Content

What's hot

Introducción a la progrogramación orientada a objetos con Java
Introducción a la progrogramación orientada a objetos con JavaIntroducción a la progrogramación orientada a objetos con Java
Introducción a la progrogramación orientada a objetos con JavaFacultad de Ciencias y Sistemas
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to javajayc8586
 
Introduction to java
Introduction to java Introduction to java
Introduction to java Java Lover
 
Introduction to Java Programming
Introduction to Java Programming Introduction to Java Programming
Introduction to Java Programming Saravanakumar R
 
Introduction to Java Programming Language
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Languagejaimefrozr
 
1 Introduction To Java Technology
1 Introduction To Java Technology 1 Introduction To Java Technology
1 Introduction To Java Technology dM Technologies
 
Java Lecture 1
Java Lecture 1Java Lecture 1
Java Lecture 1Qualys
 
Training on java niit (sahil gupta 9068557926)
Training on java niit (sahil gupta 9068557926)Training on java niit (sahil gupta 9068557926)
Training on java niit (sahil gupta 9068557926)Sahil Gupta
 

What's hot (19)

Introducción a la progrogramación orientada a objetos con Java
Introducción a la progrogramación orientada a objetos con JavaIntroducción a la progrogramación orientada a objetos con Java
Introducción a la progrogramación orientada a objetos con Java
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
Java notes
Java notesJava notes
Java notes
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
 
Introduction to Java Programming
Introduction to Java Programming Introduction to Java Programming
Introduction to Java Programming
 
JAVA Program Examples
JAVA Program ExamplesJAVA Program Examples
JAVA Program Examples
 
Introduction to Java Programming Language
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Language
 
Learn Java Part 1
Learn Java Part 1Learn Java Part 1
Learn Java Part 1
 
1 Introduction To Java Technology
1 Introduction To Java Technology 1 Introduction To Java Technology
1 Introduction To Java Technology
 
Java programming course for beginners
Java programming course for beginnersJava programming course for beginners
Java programming course for beginners
 
Java Lecture 1
Java Lecture 1Java Lecture 1
Java Lecture 1
 
Java essential notes
Java essential notesJava essential notes
Java essential notes
 
Java ms harsha
Java ms harshaJava ms harsha
Java ms harsha
 
Java Notes
Java Notes Java Notes
Java Notes
 
Core java tutorial
Core java tutorialCore java tutorial
Core java tutorial
 
Training on java niit (sahil gupta 9068557926)
Training on java niit (sahil gupta 9068557926)Training on java niit (sahil gupta 9068557926)
Training on java niit (sahil gupta 9068557926)
 
Introducing Java 7
Introducing Java 7Introducing Java 7
Introducing Java 7
 
Features of java
Features of javaFeatures of java
Features of java
 

Viewers also liked

Viewers also liked (7)

01slide
01slide01slide
01slide
 
Computer science education week or csed week
Computer science education week or csed weekComputer science education week or csed week
Computer science education week or csed week
 
JavaYDL16
JavaYDL16JavaYDL16
JavaYDL16
 
JavaYDL3
JavaYDL3JavaYDL3
JavaYDL3
 
JavaYDL5
JavaYDL5JavaYDL5
JavaYDL5
 
JavaYDL4
JavaYDL4JavaYDL4
JavaYDL4
 
JavaYDL6
JavaYDL6JavaYDL6
JavaYDL6
 

Similar to 01slide

Similar to 01slide (20)

Core java-introduction
Core java-introductionCore java-introduction
Core java-introduction
 
01slide
01slide01slide
01slide
 
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 (1)ffgfefge
01slide (1)ffgfefge01slide (1)ffgfefge
01slide (1)ffgfefge
 
Java intro
Java introJava intro
Java intro
 
Java course-in-mumbai
Java course-in-mumbaiJava course-in-mumbai
Java course-in-mumbai
 
OOP with Java
OOP with JavaOOP with Java
OOP with Java
 
01slide
01slide01slide
01slide
 
01slide
01slide01slide
01slide
 
Basics of java 1
Basics of java 1Basics of java 1
Basics of java 1
 
Professional-core-java-training
Professional-core-java-trainingProfessional-core-java-training
Professional-core-java-training
 
Java introduction
Java introductionJava introduction
Java introduction
 
CORE JAVA
CORE JAVACORE JAVA
CORE JAVA
 
Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...
 
Java chapter 1
Java   chapter 1Java   chapter 1
Java chapter 1
 
Unit of competency
Unit of competencyUnit of competency
Unit of competency
 
Chapter 1.3
Chapter 1.3Chapter 1.3
Chapter 1.3
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language
 
Intoduction to java
Intoduction to javaIntoduction to java
Intoduction to java
 
Dr. Rajeshree Khande :Intoduction to java
Dr. Rajeshree Khande :Intoduction to javaDr. Rajeshree Khande :Intoduction to java
Dr. Rajeshree Khande :Intoduction to java
 

Recently uploaded

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 

Recently uploaded (20)

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 

01slide

  • 2. Introduction 3 Course Objectives 3 Organization of the Book 2
  • 3. Course Objectives 3 Upon completing the course, you will understand – Create, compile, and run Java programs – Primitive data types – Java control flow – Methods – Arrays (for teaching Java in two semesters, this could be the end) – Object-oriented programming – Core Java classes (Swing, exception, internationalization, multithreading, multimedia, I/O, networking, Java Collections Framework) 3
  • 4. Course Objectives, cont. 3 You will be able to – Develop programs using Forte – Write simple programs using primitive data types, control statements, methods, and arrays. – Create and use methods – Develop a GUI interface and Java applets – Write interesting projects – Establish a firm foundation on Java concepts 4
  • 5. Book Chapters 3 Part I: Fundamentals of Programming – Chapter 1 Introduction to Java – Chapter 2 Primitive Data Types and Operations – Chapter 3 Control Statements – Chapter 4 Methods – Chapter 5 Arrays 5
  • 6. Book Chapters, cont. 3 Part II: Object-Oriented Programming – Chapter 6 Objects and Classes – Chapter 7 Strings – Chapter 8 Class Inheritance and Interfaces – Chapter 9 Object-Oriented Software Development 6
  • 7. Book Chapters, cont. 3 Part III: GUI Programming – Chapter 10 Getting Started with GUI Programming – Chapter 11 Creating User Interfaces – Chapter 12 Applets and Advanced GUI 7
  • 8. Book Chapters, cont. 3 Part IV: Developing Comprehensive Projects – Chapter 13 Exception Handling – Chapter 14 Internationalization – Chapter 15 Multithreading – Chapter 16 Multimedia – Chapter 17 Input and Output – Chapter 18 Networking – Chapter 19 Java Data Structures 8
  • 9. Chapter 1 Introduction to Java and Forte 3 What Is Java? 3 Getting Started With Java Programming – Create, Compile and Running a Java Application 9
  • 10. What Is Java? 3 History 3 Characteristics of Java 10
  • 11. History 3 James Gosling and Sun Microsystems 3 Oak 3 Java, May 20, 1995, Sun World 3 HotJava – The first Java-enabled Web browser 3 JDK Evolutions 3 J2SE, J2ME, and J2EE (not mentioned in the book, but could discuss here optionally) 11
  • 12. Characteristics of Java 3 Java is simple 3 Java is object-oriented 3 Java is distributed 3 Java is interpreted 3 Java is robust 3 Java is secure 3 Java is architecture-neutral 3 Java is portable 3 Java’s performance 3 Java is multithreaded 3 Java is dynamic 12
  • 13. JDK Versions 3 JDK 1.02 (1995) 3 JDK 1.1 (1996) 3 Java 2 SDK v 1.2 (a.k.a JDK 1.2, 1998) 3 Java 2 SDK v 1.3 (a.k.a JDK 1.3, 2000) 3 Java 2 SDK v 1.4 (a.k.a JDK 1.4, 2002) 13
  • 14. JDK Editions 3 Java Standard Edition (J2SE) – J2SE can be used to develop client-side standalone applications or applets. 3 Java Enterprise Edition (J2EE) – J2EE can be used to develop server-side applications such as Java servlets and Java ServerPages. 3 Java Micro Edition (J2ME). – J2ME can be used to develop applications for mobile devices such as cell phones. This book uses J2SE to introduce Java programming. 14
  • 15. Java IDE Tools 3 Forte by Sun MicroSystems 3 Borland JBuilder 3 Microsoft Visual J++ 3 WebGain Café 3 IBM Visual Age for Java 15
  • 16. Getting Started with Java Programming 3A Simple Java Application 3 Compiling Programs 3 Executing Applications 16
  • 17. 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!"); } } Source Run NOTE: To run the program, install slide files on hard disk. 17
  • 18. Creating and Compiling Programs Create/Modify Source Code 3 On command line – javac file.java Source Code Compile Source Code i.e. javac Welcome.java If compilation errors Bytecode Run Byteode i.e. java Welcome Result If runtime errors or incorrect result 18
  • 19. Executing Applications 3 On command line – java classname Bytecode Java Java Java Interpreter Interpreter Interpreter ... on Windows on Linux on Sun Solaris 19
  • 21. Compiling and Running a Program Where are the files Welcome.java stored in the c:example directory? chapter1 Welcome.class Welcome.java~ chapter2 Java source files and class files for Chapter 2 . . . chapter19 Java source files and class files for Chapter 19 21
  • 22. Anatomy of a Java Program 3 Comments 3 Package 3 Reserved words 3 Modifiers 3 Statements 3 Blocks 3 Classes 3 Methods 3 The main method 22
  • 23. 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 /*, 23
  • 24. 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. 24
  • 25. 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 25
  • 26. 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. Modifiers are discussed in Chapter 6, "Objects and Classes." 26
  • 27. 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 27
  • 28. Blocks A pair of braces in a program forms a block that groups components of a program. public class Test { Class block public static void main(String[] args) { System.out.println("Welcome to Java!"); Method block } } 28
  • 29. 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 29
  • 30. 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 30
  • 31. 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) { 31
  • 32. Displaying Text in a Message Dialog Box you can use the showMessageDialog method in the JOptionPane class. JOptionPane is one of the many predefined classes in the Java system, which can be reused rather than “reinventing the wheel.” Source Run 32
  • 33. The showMessageDialog Method JOptionPane.showMessageDialog(null, "Welcome to Java!", "Example 1.2", JOptionPane.INFORMATION_MESSAGE)); 33
  • 34. 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. 34

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.