Java Hello World Program: What is It?

Overview

“Hello World!” is a basic program which display one liner of message Java Hello World!. This is the perfect program for beginners, it explain basic understanding of java concepts like syntax, structure and how to run the program.

Java Hello World

In this article, we’ll walk you through creating your very first Java program. Let’s dive in!

Step-by-Step Guide: Java Hello World Program

Step 1: Install Java Development Kit (JDK)

Before starting Java Hello World program, you need to install the Java Development Kit (JDK) in your system. JDK provides you Java Runtime Environment (JRE) and Java compiler which gives you features to compile and run the program.

  1. Go to the official website of Java and download JDK (https://www.oracle.com/in/java/technologies/downloads/).
  2. Select the Java version based on your system and follow the installation instructions.

Step 2: Set Up Your Development Environment

If you are using any text editor for Java code then it is recommended to use any IDE (Integrated Development Environment). IDE provides many features to easy run and debug the Java program. The popular java IDE are:

  • Eclipse
  • IntelliJ IDEA
  • NetBeans

Step 3: Write Your First Java Program

It is very easy to write Java Hello World! program, you need write a simple java class and define a special main() method. The main() method is responsible for starting you Java program.

The below Java Hello World! code:

public class HelloWorld {
  public static void main(String[] args) {
     System.out.println("Hello, World!");
   }
}

Code Explanation:

  1. public class HelloWorld: This is class declaration, HelloWorld is class name, where we have define the program.
  2. public static void main(String[] args): This is a special method which we know as  main() method. Java programs start the execution from main() method. String[] args is special arguments that accept the input from command line, but in this beginner guide are not using arguments.
  3. System.out.println("Hello, World!");: This is very important code. System.out.println() is special function which print the output. In out demo it will print the Hello, World!.

Step 4: Compile and Run Your Program

Once you write the Java program you need to compile and run it:

  1. Compile: To compile the Java program you need to write the below command in command prompt terminal:
javac HelloWorld.java

This command will convert your program to bytecode and generate the HelloWorld.class file.

  • Run:  To run the Java class you need to write the below command
java HelloWorld

If above both command works fine then see the below output on the screen:

Hello, World!

Step 5: Troubleshooting (If anything wrong)

If any error during running of program, then it is easy to troubleshoot and solve, the common error could be:

  • Class name mismatch: In java it is must to match the exact file name, if you put the class name as HelloWorld then file name must be HelloWorld.java.
  • Syntax errors: Java statement must be end with semicolon (;), else you get the compilation error.

Why Learn Java?

Java is a object-oriented programming (OOP) language hai, which makes a code as modular and reusable. This is very popular language, learning Java you can get lot of opportunity:

  • Android Development: Java used for Android apps development.
  • Web Development: Java used on web-development application.
  • Enterprise Applications: Java mostly used in Banking and finance industries.

Conclusion: Your first step on coding!

Congratulations! You have written your first Java program, now you know the basic Hello World!. Java is widely used programing language, now a days most of enterprise application use the Java.

The sample code available over the github.

Happy coding 😊

Leave a Comment

Your email address will not be published. Required fields are marked *

Index
Scroll to Top