|
|
Structure of a Simple Java ProgramBasic code must be included in every Java program in order for it to work. Using the HelloWorldApp as an example, we can see what is involved in programming a basic Java program.
The class must have these 3 sections:
The "main( )" method - an entry point into our program must have these parts:
The "main" method is a key part of any program written in Java. When the Java interpreter executes a Java application, it starts by calling the class's main method . The main method then calls all the other method and executes lines of code required to run your application. If you try to run the Java interpreter on a class that does not have a main method , the interpreter refuses to run your program and displays an error message (except for Java applets, which have a different starting point). The application could also have made use of another method named print(). Code and execute the following application and compare the output. There is often more than one way to achieve a result in Java. How does the print() method differ from the println() method? Hint: you will need this for Assignment 2-1
|
| ||||