您的位置:寻梦网首页编程乐园Java天地Core JavaJava Lecture Notes

Introduction

Content

Apply

Reflect

Extend

previous.gif
 (3087 bytes)
next.gif
 (2959 bytes)

 
 
Content Index
Content Page # 10

How does the interpreter decide which statement to execute next?

Consider the Java application BallWorld (version 1 from unit 2, with comments removed to make listing shorter):

import java.awt.*;

public class BallWorld extends Frame

{

  ////////// variables ///////////

  private Ball myBall;

  ///////////// methods //////////

  static public void main (String [] args)

    {

    BallWorld world = new BallWorld ();

    world.show ();

    }

    private BallWorld ()

    {

      setSize(600, 400);

      setTitle("Ball World");

      myBall = new Ball(100, 100, 50, 4, 5);

    }

    public void paint(Graphics g)

    {

      myBall.paint( g );

      pause( 2000 );

      System.exit(0);

    }

    private void pause(int numMilliseconds)

    {

      try{ Thread.sleep( numMilliseconds ); } catch
      (InterruptedException e){}

    }

} // class BallWorld

There are some important questions we need to know the answers to:
  • How does the Java run-time interpreter decide which statement to execute first?
  • After executing a statement, how does the interpreter decide which statement to execute next?
  • How does the interpreter know when to stop executing statements ?i.e. when does a program terminate ?
Also, most non-trivial Java programs are composed of 2 or more classes. Version 1 of the unit 2 BallWorld application consisted of 2 classes: BallWorld and Ball. So we have another question to answer:
  • How does the interpreter decide from which class to choose a statement to execute?
All of these questions relate to the control of statement execution by the Java run-time interpreter. The answer to some of these questions is determined by the design of the Java programming language, and the answer to others is that we can design programs to choose statements according to the rules we wish the program to follow.

Back to top

basicline.gif (169 bytes)

RITSEC - Global Campus
Copyright © 1999 RITSEC- Middlesex University. All rights reserved.
webmaster@globalcampus.com.eg