Providing a start point A Java application starts at the method called main() in the primary class (often called the main class). When method main() has finished, the program does not necessarily finish (there may be threads running). An application should call System.exit() to finish. The method main() is formally defined as follows: public static void main(String args[]) { // create the main window here }
The Java compiler will be quite fussy that the method is defined exactly like this. If you are creating a program with a graphical user interface the data passed in the argument args[] will not usually be of interest. This argument will contain the data specified by the user when running the program from a command prompt. As a GUI program will normally be run by clicking on something, there will not be a command line and args[] will be empty. The method main() is often defined in a class that does nothing else but provide this method. Conventionally this class has the same name as the program itself. For example: { public static void main(String args[]) { // create the main window here } } // class
Back to top 
RITSEC - Global Campus Copyright ?1999 RITSEC- Middlesex University. All rights reserved. webmaster@globalcampus.com.eg |