Java is a widely-used, object-oriented programming language known for its “write once, run anywhere” philosophy. Here’s how to write your first Java program:
Steps to Create “Hello, World!”
1. Prerequisites
- Install JDK: Download and install from Oracle or OpenJDK.
- Editor/IDE: Use tools like Visual Studio Code, IntelliJ IDEA, or Eclipse.
2. Write the Code
- Create a file named
HelloWorld.java
. - Add this code:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
3. Compile and Run
- Compile: Open a terminal and run:
javac HelloWorld.java
- Execute: Run the program:
java HelloWorld
Output:
Hello, World!
What’s Next?
Explore Java’s core features like variables, loops, and object-oriented programming. Happy coding!