Monday - 1 - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

Monday - 1

Description:

import statements, and. class declarations. DoDEA Summer 2002. Java. Monday - 2 ... Program Component: Import Statement. Program MyFirstApplication ... – PowerPoint PPT presentation

Number of Views:17
Avg rating:3.0/5.0
Slides: 15
Provided by: cns28
Category:
Tags: monday | reimport

less

Transcript and Presenter's Notes

Title: Monday - 1


1
Java Program Components
  • A Java program is composed of
  • comments,
  • import statements, and
  • class declarations.

2
Template for Simple Java Applications
3
Program Component Comment
/ Program MyFirstApplication This program
displays a window on the screen. The window is
positioned at the center of the screen, and the
size of the window is almost as big as the
screen. / import javabook. class
MyFirstApplication public static void
main(String args) MainWindow
mainWindow mainWindow new MainWindow() mai
nWindow.setVisible( true )
4
Three Types of Comments
5
Program Component Import Statement
/ Program MyFirstApplication This program
displays a window on the screen. The window is
positioned at the center of the screen, and the
size of the window is almost as big as the
screen. / import javabook. class
MyFirstApplication public static void
main(String args) MainWindow
mainWindow mainWindow new MainWindow() mai
nWindow.setVisible( true )
6
Import Statement Syntax and Semantics
ltpackage namegt . ltclass namegt e.g.
javabook . InputBox
import javabook. import
java.awt.image.ColorModel
7
Program Component Class Declaration
/ Program MyFirstApplication This program
displays a window on the screen. The window is
positioned at the center of the screen, and the
size of the window is almost as big as the
screen. / import javabook. class
MyFirstApplication public static void
main(String args) MainWindow
mainWindow mainWindow new MainWindow() mai
nWindow.setVisible( true )
8
Program Component Method Declaration
/ Program MyFirstApplication This program
displays a window on the screen. The window is
positioned at the center of the screen, and the
size of the window is almost as big as the
screen. / import javabook. class
MyFirstApplication public static void
main(String args) MainWindow
mainWindow mainWindow new MainWindow() mai
nWindow.setVisible( true )
9
Your First Java Application
  • A program to display a window on the screen using
    the javabook package.
  • The size of the window is slightly smaller than
    the screen, and the window is positioned at the
    center of the screen.
  • A class in an application must have a main
    method where execution begins.

10
Your First Java Application
  • A program to display a window on the screen using
    the javabook package.
  • The size of the window is slightly smaller than
    the screen, and the window is positioned at the
    center of the screen.
  • The fundamental OOP concept illustrated by the
    program
  • An object-oriented program uses objects.
  • (e.g., mainWindow is the object)

11
Program MyFirstApplication
/ Program MyFirstApplication This program
displays a window on the screen. The window is
positioned at the center of the screen, and the
size of the window is almost as big as the
screen. / import javabook. class
MyFirstApplication public static void
main(String args) MainWindow
mainWindow mainWindow new MainWindow() mai
nWindow.setVisible( true )
12
Flow of the MyFirstApplication Program
mainWindow new MainWindow(Sample Java
Application)
mainWindow.setVisible( true )
MainWindow
State-of-Memory Diagram
13
Steps in Executing Java Applications
  • Step 1 Edit
  • Type in the program using an editor and save the
    program to a source file (className.java).
  • Step 2 Compile
  • Compile the source file to create the bytecode
    file (className.class).
  • Step 3 Run
  • Execute the compiled source file called bytecode
    file.
  • Well use and free IDE called jGrasp to perform
    steps 1-3.

14
The javabook Package
  • We used predefined classes from the javabook
    package. To download the package or get its
    detailed documentation, please visit Dr.
    Caffeine's web site at www.drcaffeine.com.
  • Advantages of using javabook
  • Gives you a taste of how real-world programs are
    developed.
  • Minimizes the impact of programming language
    syntax and semantics.
  • Allows you to write practical programs without
    learning too many details.
  • Serves as good example of how to design classes.
Write a Comment
User Comments (0)
About PowerShow.com