Print Hello World in Java

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.

Output

Print Hello World in Java without Main Class

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.


Tushar Soni

I am Tushar Soni, Co - Founder of CodingAlpha. I am a computer science student from India and passionate about Web Development and Programming. Connect with me on Facebook | LinkedIn | Google Plus

4 thoughts on “Print Hello World in Java

  • December 30, 2015 at 11:25 pm
    Permalink

    Thanks for Explanation.

    Reply
    • July 31, 2016 at 9:52 pm
      Permalink

      We hope you could execute this Hello World Java Program perfectly!

      Reply
  • December 31, 2015 at 1:21 pm
    Permalink

    Excellent Explanation of the variations.

    Reply

Join The Discussion