Learn Java

 

The main() method

The main() method defines an entry point for execution

To run a Java program the JVM executes the main() method from a class that was previously specified

A main() method must have exactly the header lised below

public static void main(String[] args)

It is declared as public so it can be seen outside the class in which it is defined. It is static as no objects are created at this point. It is declared as having a return type as void because nothing is returned.

The main method() always has an argument defined as an array of Strings and is given the variable name "args".

This allows arguments to be passed to the main() method when the program is executed from the command prompt. These arguments are then stored in the array "args".

 

 

 

 

 

 

 

 

 

 

 

 

Previous Page Page 7 Next page

 

Page 1 2 3 4 5 6 7