Oop
Oop
Oop
Java Programming
Course Objectives
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)
2
Course Objectives, cont.
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
3
Book Chapters
Part I: Fundamentals of Programming
4
Book Chapters, cont.
Part II: Object-Oriented Programming
5
Introduction to Java and Forte
What Is Java?
Getting Started With Java Programming
– Create, Compile and Running a Java
Application
6
What Is Java?
History
Characteristics of Java
7
History
James Gosling and Sun Microsystems
Oak
9
JDK Versions
JDK 1.02 (1995)
JDK 1.1 (1996)
Java 2 SDK v 1.2 (a.k.a JDK 1.2, 1998)
Java 2 SDK v 1.3 (a.k.a JDK 1.3, 2000)
Java 2 SDK v 1.4 (a.k.a JDK 1.4, 2002)
10
JDK Editions
Java Standard Edition (J2SE)
– J2SE can be used to develop client-side standalone
applications or applets.
Java Enterprise Edition (J2EE)
– J2EE can be used to develop server-side applications
such as Java servlets and Java ServerPages.
Java Micro Edition (J2ME).
– J2ME can be used to develop applications for mobile
devices such as cell phones.
12
Getting Started with Java
Programming
A Simple Java Application
Compiling Programs
Executing Applications
13
A Simple Application
Example 1.1
//This application program prints Welcome
//to Java!
package chapter1;
Source Run
NOTE: To run the program,
install slide files on hard
disk. 14
Creating and Compiling Programs
Create/Modify Source Code
On command line
– javac file.java
Source Code
If compilation errors
Bytecode
Run Byteode
i.e. java Welcome
Result
15
Executing Applications
On command line
– java classname
Bytecode
16
Example
javac Welcome.java
java Welcome
output:...
17
Compiling and Running a Program
Where are the files
Welcome.java
stored in the
c:\example directory?
chapter1 Welcome.class
Welcome.java~
.
.
.
chapter19 Java source files and class files for Chapter 19
18
Anatomy of a Java Program
Comments
Package
Reserved words
Modifiers
Statements
Blocks
Classes
Methods
The main method
19
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 /*,
20
Package
25
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 26
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
27
main Method
The main method provides the
control of program flow. The
Java interpreter executes the
application by invoking the main
method.
30
The exit Method
Use Exit to terminate the program and stop
all threads.