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
- Open any text editor (Notepad, Notepad++, etc.)
- Write the below-shown codes or just download the HelloWorld.java file.
- Now open the command prompt/terminal.
- Navigate to the folder where you have created HelloWorld.java
- Now type javac HelloWorld.java to compile it.
- 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
- Every Java program must have main method.
- The class and file name both should be the same, Here it is HelloWorld.
- A Java class name should not match any reserved java keywords.
- It is always good practice to write a Java class name in capitalize format.
- A Java class name cannot start with a number.
- A Java class name cannot start with a special symbol other than ($ and _).
- Only two special symbols $ (dollar) and _ (underscore) are allowed in class name.
- It is always good practice to write formatted codes.