Skip to main content

πŸ‘‹ Hello World in Java

Let’s write your first Java program β€” the famous "Hello, World!"


πŸ’‘ What Is It?​

β€œHello World” is the traditional first program in any language. It teaches:

  • How to write code
  • How to compile Java
  • How to run Java

β˜• Fun Fact​

The first β€œHello, World” in programming was written by Brian Kernighan in 1972 β€” even before Java was born!


πŸ§’ Explain Like I'm Five​

Think of Java like a letter you write, but your computer can’t read it directly. You need to translate (compile) it and then deliver (run) it. This Hello program is like your first β€œHi!” to the computer. 😊


πŸ—οΈ Code Example​

1. Create a file named HelloWorld.java​

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

2. Compile the code​

javac HelloWorld.java

If successful, a HelloWorld.class file will be created.

3. Run the compiled file​

java HelloWorld

βœ… You should see:

Hello, World!

πŸ” Breakdown of the Code​

Code PartWhat it Means
public class HelloWorldDeclares a class (every Java program is inside a class)
public static void main(String[] args)Entry point β€” the first thing Java runs
System.out.println(...)Prints to console

πŸ” Real-World Analogy​

Writing a Java program is like making a cake:

  • You write a recipe (Java code)
  • You compile it with a chef (compiler)
  • You serve the cake (run the output)

πŸ“ Try It Yourself​

πŸ§ͺ Exercise​

  1. Create a new file: HelloWorld.java
  2. Paste this code:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, Java Learner!");
}
}
  1. Compile and run:
javac HelloWorld.java
java HelloWorld

βœ… Output should be:

Hello, Java Learner!

Write your output here: ____________


πŸš€ What's Next?​

Now that you've made Java speak, it's time to learn about Java Syntax and how Java programs are structured.