Upload
clarence-jennings
View
229
Download
2
Embed Size (px)
Citation preview
1
Part I : Chapter 01
Introduction to Java Programming
2
Objectives
• To learn about Java and its history.
• To create, compile, and run Java programs.
• To understand the Java runtime environment.
• To write a simple Java application.
3
History of Java
• Green Project• Developed by a team led by James
Gosling at Sun Microsystems.• 1991: Oak (use in embedded consumer electronic
application)
• 1995: Java (redesigned for developing Internet applications)
James Gosling and Dukehttp://java.sun.com/people/jag/
4
History of Java
• This is a snapshot taken at a barbecue that James Gosling threw for some of the folks associated with the Green Team. From left to right they are: Al Frazier, Joe Palrang, Mike Sheridan, Ed Frank, Don Jackson, Faye Baxter, Patrick Naughton, Chris Warth, James Gosling, Bob Weisblatt, David Lavallee, and Jon Payne. Missing in action: Cindy Long, Chuck Clanton, Sheueling Chang, and Craig Forrest.
• (http://java.sun.com/features/1998/05/birthday.html)
5
Java Version HistoryVersion Code-Name Release Date
JDK 1.1.4 Sparkler Sept 12, 1997
115JDK . . Pumpkin Dec 3, 1997
JDK 1.1.6 Abigail April 24, 1998
JDK 1.1.7 Brutus Sept 28, 1998
1 18 Chelsea April 8, 1999
J2SE 1.2 Playground Dec 4, 1998
2 121J SE . . (none) 30 199March ,9
J2SE 1.2.2 Cricket July 8, 1999
2 13J SE . Kestrel May 8 , 2 0 0 0
J2SE 1.3.1 Ladybird May 17, 2001
J2SE 1.4.0 Merlin Feb 13, 2002
2 141J SE . . Hopper Sept 16, 2002
J2SE 1.4.2 Mantis June 26, 2003
2 50 150J SE . ( . .)
Tiger Sept 29, 2004
Java SE 6.0 (1.6.0) Mustang December 11, 2006
Java SE 6 Update 14 - May 28, 2009
70 17Java SE . ( . .0)
Dolphin Plan to release in 2010
6
Characteristics of Java
• Java is simple.
• Java is Object-Oriented
• Java is Case-sensitive
• Java is Interpreted (Write-Once, Run-Anywhere)
• Java is Robust
• Java is Multithreaded
• Java can be manipulated in two ways: Application and Applet
7
Platform of Java Technologies
• Java, Micro Edition
(JMETM technology)
• Java, Standard Edition
(JSETM technology)
• Java, Enterprise Edition
(JEETM technology)
8
Platform of Java Technologies
http://java.sun.com/java2/whatis/index.html
9
Architecture of Java
Java Programming Language
Java class file
Java Virtual Machine (Java VM)
Java API
Computer System
Java platform
API = Application Programming Interface
10
Typical Java Development Environment
Javasource code
Java compiler(javac)
HTML page
Java Interpreter(java)
Appletvieweror
Browser
Application
Applet
.java .class
.html
11
Typical Java Development Environment
Disk
Primary Memory
JVM
Editor
Compiler
Class Loader
Bytecode Verifier
12
Style of Java Programming
• Java application– Run in text mode– Run in GUI mode
• Java applet<html>
<applet code=“myApplet.class” width=…
height=…>
</applet>
</html>
13
Anatomy of the Application Program
• Comments• Reserved Words• Modifiers• Statements• Blocks• Classes• Methods• The main method
14
Java Keywords
• abstract boolean break byte case• catch char class const continue• default do double else extend• false final finally float for• goto if implementation import instanceof• int interface long native new• null package private protected public• return short static super switch• synchronized this throw thows• transient true try voidvolatile• while
15
The First Java Application Example
// A first program in Java
public class Welcome
{
public static void main ( String args[] ) {
System.out.println(“Welcome to Java Programming”);
}
}
Begin class definition
Declaration of main methodArguments of main method
16
The First Java Application Example
• System.out is a standard output object to display text in text mode
• println is a method of System.out• To call a method, use . between a class /
object’s name and the method– System.out.println(“…”);– car.getLevel();
17
The First Java Application Example
• Save as a name of Welcome.java• compile Welcome.java
– javac Welcome.java– See the output
• run– java Welcome– See the output
18
Java Application Example II
// Printing multiple lines in a dialog box
import javax.swing.JOptionPane;
public class Welcome2 {public static void main (String args[] ) {
JOptionPane.showMessageDialog ( null, “Welcome\nto\nJava\
nProgramming!”);
System.exit(0); // terminate the program}
}
19
Java Application Example II
• import javax.swing.JOptionPane; to call a class named JOptionPane into the class.
• JOptionPane.showMessageDialog ( null, “Welcome\nto\nJava\nProgramming!”);
call a method named showMessageDialog of JOptionPane class.
• System.exit(0); is applied as the last command of the class to return resource to the system.
20
Java Application Example II
• Save the file as Welcome2.java• compile Welcome2.java
– javac Welcome2.java
– See the output• run
– java Welcome2– See the output
21
The First Applet
// The first applet in Java
import javax.swing.JApplet;import java.awt.Graphics;
public class WelcomeApplet extends JApplet {public void paint ( Graphics g ) {
g.drawString(“Welcome to Java Programming”, 25, 25);}
}
inheritance
22
The First Applet
• Save the file as WelcomeApplet.java• compile WelcomeApplet.java
– javac WelcomeApplet.java– See the result
• run– Create a html file to call the applet
<html><applet code=“WelcomeApplet.class” width=300 height=30></applet></html>
– Save the .html file. Name the file in any name such as welcome.html
– run by typing appletviewer welcome.html– Or call the .html in any browser program.
23
End of Chapter01
Introduction to Java