Hello Java Program

    To start writing a simple Java program, you must install the JDK. Java works on the concept of classes and objects. First, we must create a class with the main method to invoke object creation.

    Basic requirements

    • Install JDK.
    • Set the path of the jdk/bin directory.
    • Start writing the Java program using code editors like Notepad, Notepad++, etc.
    • Compile the program and then run it via command line commands.


    class Simple{  
        public static void main(String args[]){  
         System.out.println("Hello Java");  

    Save the above program as the first.java. Compile it using javac first.java , and run the program using java first.java .

    How Does the Compilation of Code Work?

    Java uses both a compiler and an interpreter . Using the javac command, the Java compiler will allow the code to be converted into byte code. The byte code will create the class file in the same directory where you saved the code.

    How the compilation of code works

    Parameters Used in the Example

    Below are the keywords that are mentioned in the first.java program -

    • The class keyword will allow you to declare a class in Java.
    • The public keyword is an access modifier that specifies visibility, and if defined as public, it is visible to all.
    • static is a keyword for which there is no need to create an object to invoke the static method. The JVM will execute the main method, so no object creation is required.
    • The void is the method's return type that will not return any value.
    • The main specifies the starting point of the program.
    • String[] args will be used for the command-line argument.
    • System.out.println() is used to print statements.

    Valid main statements

    static public void main(String[] args)
    public static final void main(String[] args)
    final public static void main(String[] args)
    final strictfp public static void main(String[] args)

    Invalid main statements

    public void main(String[] args)
    static void main(String[] args)
    public void static main(String[] args)
    abstract public static void main(String[] args)