Where
does a Java application start?
A Java application is composed of 1
or more classes. When the Java run-time interpreter is instructed to begin
executing a Java application, it must be provided with a class that contains
a method called 'main'.
The first statement to be executed for a Java application is the first
statement inside this main class's method main.
A main
method is show in full in the abbreviated version of the BallWorld class
below:
//
BallWorld.java
import java.awt.*;
public class
BallWorld extends Frame
{
private
Ball myBall;
static
public void main (String [] args)
{
BallWorld
world = new BallWorld ();
world.show
();
}
private BallWorld
()
{ // implementation
of BallWorld constructor class }
public void
paint(Graphics g)
{ // implementation
of paint method }
private void
pause(int numMilliseconds)
{ // implementation
of pause method }
} // class
BallWorld
The first statement inside this class's
main
method will be the first statement of the application to be executed, i.e.:
BallWorld world
= new BallWorld ();
Although all classes that comprise an
application need to be compiled, we only tell the interpreter the name of the
main class. The class Ball does not contain the method main, it is used by
BallWorld. We can using Kawa run the BallWorld class.
Back
to top
RITSEC - Global Campus
Copyright © 1999 RITSEC- Middlesex
University. All rights reserved.
webmaster@globalcampus.com.eg
|