HelloObject
,
and HelloTester
HelloObject anObject = new HelloObject();
HelloTester
, is used to
contain the static main()
method. No object needs
to be constructed from it.
The Java interpreter starts a program by looking
for a static main()
method.
Since it is static
the interpreter can run it
without first constructing an object.
It is convenient to have a separate class that
serves no other purpose than to contain the main()
method.
This testing class is used for no other reason than to start things running.
Usually its main()
constructs objects and calls their methods.
These objects do the real work of the program.
Name the file HelloTester.java
.
When you compile the file, the compiler outputs
two separate files of bytecodes:
C:/chap30>javac HelloTester.java compiling: HelloTester.java C:/chap30>dir 11/13/98 10:07p 257 HelloTester.java 11/13/98 10:40p 476 HelloObject.class 11/13/98 10:40p 373 HelloTester.class 3 File(s) 1,106 bytes
To run the program type:
java HelloTester
The Java interpreter finds the main()
method in
the HelloTester
class and starts it running.