Simple Java Program

A class to display a simple message: 

Simple Java Program
Simple Java Program

class MyProgram
    {
              public static void main(String[] args)
                   {
                              System.out.println("―First Java program.");
                    }
   }

File name : MyProgram.java
Compilation : javac MyProgram.java
Execution:java MyProgram


  • public the visibility. This can be public, private, protected or (if you omit a value) default.

  • static a special [optional] keyword that indicates that this method can be called without creating an instance of this class. Without it, you have to instantiate this class and call this method from the resulting object.

  • void the return type of this method, indicating that this method doesn't return anything. 

  • Methods must have a return type.main( ... )is the name of this method. Methods have to be named. The parentheses indicate that this is a method.

  • String[] args is a single parameter for the method.String[]is the type of the parameter, indicating an array of Strings.argsis the name of the parameter. Parameters must be named.