Java Program Case Study on Public Static Void Main


A case study on public static void main (250 words)

Case study:

The program structure of a simple java program is given below with different steps

  • Step-1: Click start+run and then type notepad in run dialog box and click OK. It displays Notepad.
  • Step-2: In run dialogbox type cmd and click OK. It displays command prompt.
  • Step-3: Type the following program in the Notepad and save the program as “” in a
current working directory.
class example
public static void main(String args[])
}Code language: PHP (php)
  • Step-4 (Compilation): To compile the program type the following in the current working directory and then click enter.
    • c:\xxxx >javac
  • Step-5 (Execution): To run the program type the following in the current working directory and then click enter.
    • c:\xxxx>java example


  • Generally, the file name and class name should be the same. If it is not the same then the java file can be compiled but it cannot be executed. That is when execution gives the following error
    • Exception in thread “main” java. lang.NoClassDefFoundError: ex
  • In the “public static void main(String args[])” statement
    • public is an access specifier. If a class is visible to all classes then the public is used
    • main() must be declared as public since it must be called by outside of its class.
    • The keyword static allows main() to be called without creating an object of the class.
    • The keyword void represents that main( ) does not return a value.
    • The main method contains one parameter String args[].
    • We can send some input values (arguments) at run time to the String args[] of the main method . These arguments are called command-line arguments. These command-line arguments are passed at the command prompt.
  • In System.out.println(“Welcome”); statement
    • System is a predefined class that provides access to the system.
    • out is the output stream.
    • println() method display the output in different lines. If we use print() method it display the output in the same line

Leave a Comment