Setup Java & First Program


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:

  1. Visit the official website (Oracle JDK or OpenJDK)
  2. Download the latest stable version (Java 17 or above recommended)
  3. Install it like any standard software
📌 Ashok IT also offers a Full Stack Java training program with structured placement assistance to guide you from learning to earning.

Step 2: Set Environment Variables (Windows)

This step ensures Java commands work globally in your system.

Steps:

  1. Open System Environment Variables
  2. Create a new variable:
  • Variable Name: JAVA_HOME
  • Variable Value:

    C:\Program Files\Java\jdk-17
  1. Edit the Path variable 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 HelloWorld defines 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.javaclass 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 .java extension
  • Java is case-sensitive
  • Follow proper naming conventions
  • Practice using the command line before switching to IDEs

💼 Looking to become job-ready? Ashok IT’s Full Stack Java course comes with hands-on training and a proven placement assistance program to help you get hired faster.

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