Print Hello World in Java Programming
Learn How To Print Hello World in Java Programming Language with 3 Different Methods. We have tried to cover up the basic program in Java Programming. Here, we have also Explained How the Program To Display Hello World works in Java.
Method 1: Declaring the Class containing Main Method as Public
Note: When the Class containing the Main Function is declared as Public in a Java Program, then the Class Name should be same as the Java File Name.
Also Read: Java Code To Check Even and Odd Numbers
Method 2: Not Declaring the Class containing Main Method as Public
Note: When Public Access Modifier is not used in the Class containing the Main Method in a Java Hello World Program, then the Class Name may be different to the Java File Name.
Method 3: Declaring Class without Main Method
Also Read: Java Program To Find Factorial of a Number
Steps To Execute Java Programs in Linux Ubuntu
- Create a Text File (using gEdit) named HelloWorld.java on Linux Ubuntu Desktop.
- Paste the above code into the Text file and Save it with a .java extension.
- Open Ubuntu Terminal by pressing Ctrl+Alt+T.
- Type: cd Desktop and Hit Enter.
- Type: javac HelloWorld.java and Hit Enter. This step helps in Compiling Java Programs.
- To Execute the program, use the command java HelloWorld.
- Now, you would be able to see the Output as Hello World on the Terminal.
How To Run Hello World in Java in Linux Ubuntu Video Tutorial
In case you get any Compilation Errors with this Code To Print Hello World in Java Programming or if you have any doubt about it, mention it in the Comment Section.