Getting started with Java is straightforward if you follow a structured approach. In this guide, you will learn how to install Java, configure your system, and run your first Java program successfully.
What You Need Before Starting
To begin with Java development, you need:
- JDK (Java Development Kit)
- A code editor (Notepad, VS Code, or IntelliJ IDEA)
- Basic knowledge of using the command prompt or terminal
Step 1: Download and Install JDK
Steps:
- Visit the official website (Oracle JDK or OpenJDK)
- Download the latest stable version (Java 17 or above recommended)
- Install it like any standard software
Step 2: Set Environment Variables (Windows)
This step ensures Java commands work globally in your system.
Steps:
- Open System Environment Variables
- Create a new variable:
-
Variable Name:
JAVA_HOME -
Variable Value:
C:\Program Files\Java\jdk-17
-
Edit the
Pathvariable and add:
%JAVA_HOME%\bin
Step 3: Verify Installation
Open Command Prompt and run:
java -version
javac -version
If installed correctly, version details will be displayed.
Step 4: Choose a Code Editor
You can use:
- Notepad (for beginners)
- VS Code (lightweight and popular)
- IntelliJ IDEA (advanced development)
For beginners, it is recommended to start with simple tools and focus on core concepts.
Step 5: Write Your First Java Program
Create a file named:
HelloWorld.java
Write the following code:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}
Step 6: Compile the Program
Open Command Prompt in the file location and run:
javac HelloWorld.java
This generates a file:
HelloWorld.class
Step 7: Run the Program
java HelloWorld
Output:
Hello, Java!
Understanding the Program
-
class HelloWorlddefines a class -
main()is the entry point of execution -
System.out.println()prints output
Every Java program starts execution from the main() method.
🔹 Common Errors & Fixes
❌ Error: javac is not recognized
👉 Fix: Check environment variables (JAVA_HOME & Path)
❌ Error: Class name mismatch
👉 File name must match class name
✔ HelloWorld.java → class HelloWorld
❌ Error: Could not find or load main class
👉 Run command without .class
✔ java HelloWorld (NOT java HelloWorld.class)
Best Practices for Beginners
-
Always save files with
.javaextension - Java is case-sensitive
- Follow proper naming conventions
- Practice using the command line before switching to IDEs
What to Learn Next
After your first program, focus on:
- Variables and Data Types
- Operators
- Control Statements (if, loops)
- Object-Oriented Programming
Conclusion
Setting up Java and running your first program is the foundation of your programming journey. Once this is complete, you are ready to move forward into real development.
Every experienced Java developer started with a simple program like this.
Comments
Post a Comment