Java Program Structure

In this chapter, we will discuss high level java program structure, Compile and run a simple program. In java , Program can be defined using keyword "class". A Class starts and ends with curly braces. class < ProgramName > { // Start of the class/program .. .. } // end of the class. Within class we may have main() function/method , where actual execution starts when we run Java Program/Class. class < ProgramName > { public static void main(String[] args) { // Start of method statement 1; // statements ends with semicolon statement 2; .. .. statement n; } }

Compile and Run Sample Java Program

Here is the sample Hello World Program which will display the String to console. Click here for java source code. Save above program with name open command line prompt and compile it with javac command as shown below. Run the java program using Java command as shown below. After executing the MyFirstProgram, it will display following two lines from main() method.
    This is my first program

    Welcome to Java World