Download and Install Java
To begin programming in Java, install the Java Development Kit (JDK): 1. Visit the official Oracle website: https://www.oracle.com/java/technologies/downloads/ 2. Download the latest JDK version for your operating system (Windows, macOS, or Linux) 3. Run the installer and follow the instructions 4. Set the JAVA_HOME environment variable to point to the JDK installation directory
Verify Installation
Open a command prompt or terminal and type: `java -version` This displays the installed Java version. Also check the compiler: `javac -version`
// Check Java runtime version
java -version
// Check Java compiler version
javac -version
java version "17.0.1" 2021-10-19 LTS Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39) Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode, sharing)
Your First Java Program
Create and run a simple 'Hello World' program: 1. Create a file named `HelloWorld.java` 2. Add the code below 3. Compile with `javac HelloWorld.java` 4. Run with `java HelloWorld`
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Hello, World!
Understanding the Structure
• `public class HelloWorld`: Defines a public class; filename must match the class name • `public static void main(String[] args)`: The main method, entry point of Java programs • `System.out.println()`: Prints text to the console • Curly braces `{}`: Group code blocks • Semicolon `;`: Ends a statement
Choosing an IDE
You can write Java in any text editor, but IDEs simplify development: - IntelliJ IDEA: Popular and powerful Java IDE - Eclipse: Free, widely used open-source IDE - NetBeans: Free IDE supported by Apache - VS Code: Lightweight editor with Java extensions
Expected Output
Hello, World!