Hello Java Program

    To start writing a simple Java program, you have to install the JDK. Java works on the concept of classes and objects. First, we have to create a class that has 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) Run the program using (java first.java)

    How the compilation of code works?

    Using the javac tool, the java compiler will allow the code to be converted into byte code from the source 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 which specifies visibility and if defined as public then is visible to all.
    • static is a keyword for which there is no need to create an object to invoke the static method. The main method will be executed by the JVM so no object creation is required.
    • The void is the return type of the method 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 statement.

    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)


    In this article, we discussed a simple Java program for printing a single statement. Before compiling and running any Java program, it is essential to have JDK installed on your system and set the Java path. Also, it is important to remember that the class name and the file name where you save your program should be the same. Happy Coding!

    People are also reading: