JAVA Tutorial



HELLO WORLD IN JAVA


👋 Hello World in Java

The "Hello World" program is the simplest program that can be written in Java to demonstrate the basic structure of a Java program. It helps you understand the syntax and how to display output to the console.

🔸 Steps to Write a Hello World Program in Java

  1. Create a class: Every Java program must be inside a class. The class name should match the file name.
  2. Define the main method: This is the entry point of the program. The code execution begins from here.
  3. Use System.out.println(): This is the function used to print output to the console.

🔸 Code Example

Below is the simple "Hello World" program written in Java:

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

In this program:

  • public class HelloWorld: This defines a class named HelloWorld. The file name should also be HelloWorld.java.
  • public static void main(String[] args): This is the main method where the program execution starts.
  • System.out.println("Hello, World!");: This line prints the message "Hello, World!" to the console.

🔸 How to Run the Program

  1. Open your terminal or command prompt.
  2. Navigate to the directory where your HelloWorld.java file is saved.
  3. Compile the Java program using the command: javac HelloWorld.java.
  4. Run the compiled program with the command: java HelloWorld.

After running the program, you should see the following output:

Hello, World!
  

🔸 Key Points to Remember

  • Java is case-sensitive, so the class name must match the filename.
  • The main() method must be declared as public static void main(String[] args).
  • The System.out.println() method is used to print output to the console.
💡 Tip: The class name in Java should always start with an uppercase letter, following the Java naming convention.

🌟 Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review