Hello world Java program

Let’s create first Hello World Java program.

Create a java file ‘HelloWorld.java’ with the name ‘HelloWorld’ and extension as ‘.java’. Copy, paste and save below code inside HelloWorld.java file.

Java application file will always have .java as an extension in the file name.

// HelloWorld is the class name.
class HelloWorld {
   // Predefined function given by java  to print output.
  public static void main(String[] args) {
      // function to print Hello World !!!
      System.out.println("Hello World !!!");

Note: don’t worry about main method. We will be discussing this later in another chapter. Just remember, main method will be executing at first place.

Run javac HelloWorld.java command in the same directory where we created above HelloWrold.java file. This command will create Employee.class file.

Run java HelloWorld command to get output of java application.

Congratulations!!! we have created our first java application.

Note: For having latest output always run javac class_name.java before running java class_name command. After saving latest changes in java file and run java class_name command will not print or give latest output.

Imran Khan

Specialist Master (Architect) with a passion for cutting-edge technologies like AEM (Adobe Experience Manager) and a proven track record of delivering high-quality software solutions.

  • Languages: Java, Python
  • Frameworks: J2EE, Spring, Struts 2.0, Hibernate
  • Web Technologies: React, HTML, CSS
  • Analytics: Adobe Analytics
  • Tools & Technologies: IntelliJ, JIRA

🌐 LinkedIn

📝 Blogs

📧 Imran Khan