Installing Java
This means downloading and setting up the JDK on your computer so you can write, compile, and run Java programs. Once installed, your computer understands commands like javac (to compile) and java (to run).
1. What does "Installing Java" mean?
This means downloading and setting up the JDK on your computer so you can write, compile, and run Java programs. Once installed, your computer understands commands like javac (to compile) and java (to run).
2. Why is it used?
Without installing the JDK, your computer has no way to understand or execute Java code. Installing it correctly, and setting up the required system path, is the very first practical step before writing any real program.
3. Real-Life Example
It's like buying a new smartphone. Before you can use apps on it, you first need to switch it on and complete the initial setup. Installing the JDK is that same "initial setup" step, done once, before you can start building anything in Java.
4. Syntax
1. Download the JDK from a trusted official source for your operating system.
2. Install it following the setup wizard.
3. Set the JAVA_HOME environment variable and add it to your system PATH.
4. Confirm installation using a terminal command.5. Example Program
java// After installing, test it by running this in your terminal: // java -version
Output:
java version "21.0.1" 2024-xx-xx6. Key Points to Remember
- You need the JDK, not just the JRE, if you plan to write code.
JAVA_HOMEandPATHmust be set correctly for terminal commands to work.- Use
java -versionandjavac -versionto confirm a successful installation.
Practice Problems
Try each question yourself first, then check the answer.
1. JRE or JDK
You want to WRITE and compile Java. Should you install the JRE or the JDK? Why?
Answer: The JDK — it includes the compiler (javac) and other development tools. The JRE can only run already-compiled programs.
2. Two settings to configure
Name the two things you typically configure after installing the JDK so terminal commands work.
Answer: Set JAVA_HOME to the JDK folder, and add Java's bin directory to the system PATH.
3. Two verification commands
Which two commands verify a successful installation, and what does each check?
Answer: java -version checks that the runtime works and prints its version. javac -version checks that the compiler is available (i.e. the JDK, not just a JRE).
4. Diagnose the failure
java -version gives "command not found" right after installing. What is the most likely cause?
Answer: The PATH (or JAVA_HOME) was not set correctly, so the terminal cannot locate the java executable.