Java Hello World

  • Post author:
Download PDF

Java Hello World

Start Java Hello World program that displays the message “Welcome to Java by zitoc!” on the console screen. Open java IDE and start a new project. Below code of Java copy and paste your Java IDE and compile it for demonstration.

public class WelcomeToZitoc
  public static void main(String[] args)
    // Display message Welcome to Java by zitoc! to the console
    System.out.println("Welcome to Java by zitoc!");

Output:   Welcome to Java by zitoc!

Line Numbers:   Line number shows the reference of the code line which is not part of the program so do not write line number in your code.

Class name:   Line 1 defines a class. Each Java program must have at least one class. Each class has one single name. By convention, class names start in Java with an uppercase letter. In this example, the class name is WelcomeToZitoc which start line 01 and end at line 06.

Main method:   Line 2 defines the main method. Every class has main method. Every program is executed from the main method. A method has some statements which perform some specific task. The main method in this program contains the System.out.println statement. This statement prints a message “Welcome to Java by zitoc!” to the console screen (line 4). The system is another class and out is the object of system class and println is the function/method of system class. Method println used to show the string on the console screen.

Statement terminator (;):   Every statement ends with a semicolon (;) in Java programming, known as the statement terminator


Reserved word:   Reserved word, keyword word, and built-in keyword are the same in Java programming. These keywords have a specific meaning to the compiler and these keywords cannot be used for any other purposes in the program. For example, when the compilers see the word class, compilers understand that the word after class is the name for the class. Other reserved words in this program are public, static, void, and main.

Comment:   Comments are not programming statements and compiler not read them. Comments help the programmer to understand and communicate the program. In Java, comments are preceded by two slashes (//) called a line comment, or enclosed between /* and */ called a block comment. Below are some examples of comments:

// This is line comment

/* This is block comment line 1

This is block comment line 2

This is block comment line 3 */

Block:   Everything which enclosed the pair of braces ({,}) called a block of the statement. In Java, every block starts with an opening brace ({) and terminates with a closing brace (}). Every class has a class block that contains the data and methods of the class and each method has a method block that contains the statements in the method. Blocks can be nested, mean one block can have another block inside the block.


Java programming is case sensitive. It would be wrong, for example, to replace main in the program with Main or replace static with Static or static.