How Java "Hello, World!" Program Works?

  1. // Your First Program

    In Java, any line starting with // is a comment. Comments are intended for users reading the code to better understand the intent and functionality of the program. It is completely ignored by the Java compiler. Compiler is an application that translates Java program to Java bytecode that computer can execute

  2. class HelloWorld ...

    In Java, every application begins with a class definition. In the program, HelloWorld is the name of the class, and the class definition is:


    \begin{lstlisting}
class HelloWorld {
... .. ...
}
\end{lstlisting}

    For now, just remember that every Java application has a class definition, and the name of the class should match the filename in Java.

  3. public static void main(String[] args) ...

    This is the main method. Every application in Java must contain the main method. The Java compiler starts executing the code from the main method. For now, just remember that the mainfunction is the entry point of your Java application, and it's mandatory in a Java program. The signature of the main method in Java is:


    \begin{lstlisting}
public static void main(String[] args) {
... .. ...
}
\end{lstlisting}

  4. System.out.println("Hello, World!");

    The following code prints the string inside quotation marks Hello, World! to standard output (your screen). Notice, this statement is inside the main function, which is inside the class definition.