Java first application

In Java, we start writing codes by creating a Java class. All the codes, logic and algorithms will be always inside a java class.

Hello World

A “Hello world!” program is usually a computer program that displays the message “Hello world!”. It is very simple in most of the programming languages. To write the Hello World program in Java follow the below-shown steps.

Steps

  1. Open any text editor (Notepad, Notepad++, etc.)
  2. Write the below-shown codes or just download the HelloWorld.java file.
  3. Now open the command prompt/terminal.
  4. Navigate to the folder where you have created HelloWorld.java
  5. Now type javac HelloWorld.java to compile it.
  6. If it is not showing any error you can run it by typing java HelloWorld

Program

public class HelloWorld {

    public static void main(String[] args) {

        System.out.println("Hello World");

    }
}

Output

Hello World

Now change the “Hello World” message to your name and run it again. (Repeat step 5 & 6)

Important points

  1. Every Java program must have main method.
  2. The class and file name both should be the same, Here it is HelloWorld.
  3. A Java class name should not match any reserved java keywords.
  4. It is always good practice to write a Java class name in capitalize format.
  5. A Java class name cannot start with a number.
  6. A Java class name cannot start with a special symbol other than ($ and _).
  7. Only two special symbols $ (dollar) and _ (underscore) are allowed in class name.
  8. It is always good practice to write formatted codes.