Java Installation and Setup

Java Installation and Setup

โš™๏ธ Java Installation and Setup

๐Ÿ“Œ Overview

Before writing and executing Java programs, Java must be properly installed on the system. A correct setup ensures that programs compile and run smoothly without unnecessary configuration issues.

This guide explains:

  • The easiest way to install Java
  • How to verify the installation
  • How to create and run the first Java program step by step
  • When environment variables are required
  • Common mistakes beginners usually make

๐Ÿง  Understanding What Needs to Be Installed

๐Ÿ“ฆ Java Development Kit (JDK)

To develop Java programs, the Java Development Kit (JDK) is required.

The JDK includes:

  • Java Compiler (javac)
  • Java Runtime Environment (JRE)
  • Java Virtual Machine (JVM)
  • Core Java libraries and tools

๐Ÿ‘‰ Installing the JDK is sufficient for both writing and running Java programs.


๐ŸŒ Recommended Way to Install Java (Simple and Beginner-Friendly)

โœ… Using Adoptium (Temurin JDK)

The easiest and most reliable way to install Java is by using Adoptium (Temurin JDK).

Benefits:

  • Free and open-source
  • Long-Term Support (LTS) versions
  • Automatically configured on most systems
  • No immediate need to set environment variables

๐Ÿ“ฅ Downloading and Installing the JDK
  1. Download the latest LTS version of Temurin JDK
  2. Select the correct operating system and 64-bit architecture
  3. Run the installer
  4. Accept the license agreement
  5. Keep default settings and complete installation

โœ… Verifying Java Installation

๐Ÿ” Checking Java Version

After installation, open Command Prompt and run:

java -version

If a Java version number is displayed, Java is installed successfully.


๐Ÿ” Checking Java Compiler

Now check the compiler:

javac -version

If a version number appears, the JDK is working correctly.

๐Ÿ‘‰ At this point, Java is ready to be used.


๐Ÿ“ Creating a Folder for Java Programs (Important for Beginners)

๐Ÿ“Œ Why This Step Is Important

Beginners often face confusion because Java files are saved in random locations. To avoid this, it is recommended to use a fixed folder for Java programs.


๐Ÿ“‚ Creating the Folder
  1. Open This PC
  2. Go to Local Disk (C:)
  3. Create a new folder named:
java

The folder path will be:

C:\java

๐Ÿ‘‰ All Java programs will be saved inside this folder.


๐Ÿ“ Writing the First Java Program Using Notepad

โœ๏ธ Creating the Program File
  1. Open Notepad
  2. Type the following program:
class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Java is successfully installed!");
    }
}

๐Ÿ’พ Saving the File Correctly
  1. Click File โ†’ Save As
  2. Navigate to:
C:\java
  1. File name:
HelloWorld.java
  1. Save as type:
All Files
  1. Encoding:
UTF-8

๐Ÿ‘‰ The file must be saved with .java extension.


๐Ÿ’ป Compiling and Running the Program from Command Prompt

๐Ÿ“ Opening Command Prompt in the Correct Folder
  1. Open Command Prompt
  2. Type:
cd C:\java
  1. Press Enter

Now the command prompt is pointing to the folder where the Java file is stored.


โ–ถ๏ธ Compiling the Program

Run:

javac HelloWorld.java

If no error appears, compilation is successful.


โ–ถ๏ธ Running the Program

Run:

java HelloWorld

Expected output:

Java is successfully installed!

๐ŸŽ‰ This confirms that Java is installed and working correctly.


โš ๏ธ When Are Environment Variables Required?

๐Ÿ“Œ Important Clarification

For modern JDK installers (such as Adoptium), manual environment variable configuration is usually not required.

Environment variables are needed only if:

  • java or javac command is not recognized
  • Java was installed using a ZIP file
  • Multiple Java versions are installed
  • System PATH was not updated automatically

๐Ÿ”ง Understanding Environment Variables (If Needed)

๐Ÿ› ๏ธ JAVA_HOME

JAVA_HOME should point to the JDK installation directory.

Example:

C:\Program Files\Eclipse Adoptium\jdk-21

โž• PATH Variable

Add the JDK bin directory to PATH:

C:\Program Files\Eclipse Adoptium\jdk-21\bin

After setting this, reopen Command Prompt and recheck:

java -version
javac -version

โŒ Common Mistakes Beginners Usually Make

๐Ÿšซ Saving File with .txt Extension

Example:

HelloWorld.java.txt

โœ” Always select All Files while saving


๐Ÿšซ File Name and Class Name Mismatch

Class name and file name must match exactly.


๐Ÿšซ Running Commands from the Wrong Folder

If the command prompt is not in C:\java, compilation will fail.

โœ” Always use:

cd C:\java

๐Ÿšซ Installing Only JRE

JRE cannot compile programs.

โœ” Always install JDK


๐Ÿ Conclusion

๐Ÿ“ Final Summary

Java installation is straightforward when using modern JDK distributions such as Adoptium. After installation, creating a dedicated folder, writing programs using a simple editor, and running them from the command line helps beginners understand Javaโ€™s workflow clearly.

Environment variables should be configured only when required, keeping the initial learning process simple and focused.

A correct setup ensures a strong foundation for learning Java programming effectively.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *