Getting Started - PowerPoint PPT Presentation

1 / 34
About This Presentation
Title:

Getting Started

Description:

Inprise - Borland JBuilder. Oracle - JDeveloper. Metrowerks - CodeWarrior Professional ... The Anatomy of a Java Application. Defining a Class. The main Method ... – PowerPoint PPT presentation

Number of Views:53
Avg rating:3.0/5.0
Slides: 35
Provided by: csmKu
Category:

less

Transcript and Presenter's Notes

Title: Getting Started


1
Getting Started
  • Cognitive Systems Modeling Lab.

2
Contents
  • JDK 1.2 Installation
  • HelloWorldApp Application
  • HelloWordl Applet

3
JDK 1.2 Installation
  • JDK
  • Java Development Kit
  • Notepad
  • Microsoft - Visual J
  • SYMANTEC - Visual Café
  • Inprise - Borland JBuilder
  • Oracle - JDeveloper
  • Metrowerks - CodeWarrior Professional

4
JDK 1.2 Installation
5
JDK 1.2 Installation
6
JDK 1.2 Installation
7
JDK 1.2 Installation
8
JDK 1.2 Installation
9
JDK 1.2 Installation
10
JRE 1.2 Installation
11
JDK 1.2 Installation
12
JDK 1.2 Installation
13
Hello World Application
  • Create a Java Source File
  • Compile the Source File
  • Run the Application

14
Create a Java Source File
  • class HelloWorldApp
  • public static void main(String args)
  • System.out.println("Hello World!")
    //Display the string.

15
The Anatomy of a Java Application
  • Defining a Class
  • The main Method
  • Using Classes and Objects

16
Defining a Class
  • class HelloWorldApp . . . .
  • Class Cefinition
  • class name . . .

17
The main Method
  • public static void main(String args)
  • . . . .
  • Every Java application must contain a main method
  • public indicates that the main method can be
    called by any object
  • static indicates that the main method is a class
    method
  • void indicates that the main method doesn't
    return any value

18
Using Classes and Objects
  • System.out.println("Hello World!")
  • System.out is the full name of the out variable
    in the System class
  • an instance of the PrintStream class
  • a class provided with the Java development
    environment
  • When the System class is loaded into the
    application, it instantiates PrintStream and
    assigns the new PrintStream object to the out
    class variable
  • Now we have an instance of a class, we can call
    one of its instance methods

19
Create a Java Source File
  • Using a text editor, create a file named
    HelloWorldApp.java

20
Compile the Source File
  • UNIX javac HelloWorldApp.java
  • Win32 javac HelloWorldApp.java

21
Run the Application
  • UNIX java HelloWorldApp
  • Win32 java HelloWorldApp

22
Hello World Applet
  • Create a Java Source File
  • Compile the Source File
  • Create an HTML File that Includes the Applet
  • Run the Applet

23
Create a Java Source File
  • import java.applet.Applet
  • import java.awt.Graphics
  • public class HelloWorld extends Applet
  • public void paint(Graphics g)
  • g.drawString("Hello world!", 50, 25)

24
The Anatomy of a Java Applet
  • Importing Classes and Packages
  • Defining an Applet Subclass
  • Implementing Applet Methods
  • Running an Applet

25
Importing Classes and Packages
  • The first two lines of the following listing
    import two classes used in the applet
  • import java.applet.Applet
  • Import java.awt.Graphics
  • The java.applet package
  • classes that are essential to Java applets
  • The java.awt package
  • the most frequently used classes in the Abstract
    Window Toolkit (AWT), which provides the Java
    graphical user interface (GUI)

26
Importing Classes and Packages
  • public class HelloWorld extends
    java.applet.Applet public void
    paint(java.awt.Graphics g) g.drawString("Hello
    world!", 50, 25)

27
Defining an Applet Subclass
  • public class HelloWorld extends Applet .
  • extends indicates that HelloWorld is a subclass
    of the Applet class
  • Applet class
  • browser loads a page containing an applet, the
    browser sends a request to the applet, telling
    the applet to initialize itself and start
    executing

28
Implementing Applet Methods
  • implement the paint method
  • public void paint(Graphics g)
    g.drawString("Hello world!", 50, 25)
  • applets can implement two more methods

29
Running an Applet
  • ltAPPLETgt tag
  • browser should load the class whose compiled code
    HelloWorld.class
  • browser looks for this file in the same directory
    as the HTML document that contains the tag
  • browser creates an instance of the class
  • If you include an applet twice in one page, the
    browser loads the class file once and creates two
    instances of the class.
  • The WIDTH and HEIGHT attributes are like the same
    attributes in an ltIMGgt tag

30
Create a Java Source File
  • Create a file named HelloWorld.java

31
Compile the Source File
  • UNIX javac HelloWorld.java
  • Win32 javac HelloWorld.java

32
Create an HTML File that Includes the Applet
  • ltHTMLgt
  • ltHEADgt
  • ltTITLEgt A Simple Program lt/TITLEgt
  • lt/HEADgt
  • ltBODYgt
  • Here is the output of my program
  • ltAPPLET CODE"HelloWorld.class" WIDTH150
    HEIGHT25gt
  • lt/APPLETgt
  • lt/BODYgt
  • lt/HTMLgt

33
Create an HTML File that Includes the Applet
34
Run the Applet
Write a Comment
User Comments (0)
About PowerShow.com