Professional Documents
Culture Documents
Class
Object
Attribute (characteristic)
Behavior (responsibility)
State
Encapsulation
Inheritance
New classes can add some new details to the existing more
general class definition
Polymorphism
Composition
Compiler
Interpreter
Disadvantages of compilers/interpreters
Java compiler
Portability
Transparent
Application
Applet
Servlets
Performance
comments,
import statements, and
class declarations.
Ch
ap
ter
216
/*
Chapter 2 Sample Program: Displaying a Window
File: Ch2Sample2.java
*/
import javax.swing.*;
class Ch2Sample1 {
public static void main(String[ ] args) {
JFrame
myWindow.setSize(300, 200);
myWindow.setVisible(true);
}
myWindow;
/*
Chapter 2 Sample Program: Displaying a Window
File: Ch2Sample2.java
*/
import javax.swing.*;
class Ch2Sample1 {
public static void main(String[ ] args) {
JFrame
myWindow;
Comment
Ch
ap
ter
218
/*
This is a comment with
three lines of
Multiline Comment
text.
*/
// This is a comment
// This is another comment
/**
* This class provides basic clock functions. In addition
* to reading the current time and todays date, you can
* use this class for stopwatch functions.
*/
The McGraw-Hill Companies, Inc.
Permission required for
reproduction or display.
javadoc Comments
Ch
ap
ter
219
/*
Whenever you use a
java.lang package,
Otherwise you have
only shorthand for
avoid typing fully
into program */
Import
Statement
import javax.swing.*;
class Ch2Sample1 {
public static void main(String[ ] args) {
JFrame
myWindow;
Ch
ap
ter
220
Package Name
Name of the package that
contains the classes we
want to use.
Class Name
The name of the class we
want to import. Use asterisks
to import all classes.
<package name>
e.g.
More
Examples
dorm
import
import
import
<classname> ;
Resident;
javax.swing.JFrame;
java.util.*;
com.drcaffeine.simplegui.*;
Chapter 2
- 21
The McGraw-Hill
Companies, Inc. Permission
required for reproduction
or display.
/*
Chapter 2 Sample Program: Displaying a Window
Class
Declaration
File: Ch2Sample2.java
*/
import javax.swing.*;
class Ch2Sample1 {
public static void main(String[ ] args) {
JFrame
myWindow;
Ch
ap
ter
222
/*
Chapter 2 Sample Program: Displaying a Window
Method
Declaration
File: Ch2Sample2.java
*/
import javax.swing.*;
class Ch2Sample1 {
public static void main(String[ ] args) {
JFrame
myWindow;
Ch
ap
ter
223
Modifier
public
Modifier
static
Return Type
Method Name
void
main(
Parameter
String[ ] args
){
Method Body
JFrame myWindow;
myWindow = new JFrame( );
myWindow.setSize(300, 200);
Ch
ap
ter
224
/*
Chapter 2 Sample Program: Displaying a Window
Comment
File: Ch2Sample2.java
*/
Import
Statements
import javax.swing.*;
class Ch2Sample1
Class Name
Method Body
myWindow.setTitle(
My First Java Program);
myWindow.setVisible(true);
}
}
Ch
ap
ter
225
Class
Package
Object
Method
Argument
Statement
Variable
Data type
Name of the file must be the name of the class with .java
extension
Example: Calculate.java is a java source code file.
The McGraw-Hill
Companies, Inc. Permission
required for reproduction
or display.
Use the name of the class, not the name of the file
containing the class or its bytecode
Example: java Calculate (not java Calculate.class)