Unit 0: Installation and Prerequisites
Installing Java JDK
Installing Java JDK (Java 17 LTS) for AP CS A
Introduction:
- What is the JDK?
- Java Development Kit.
- A software package that provides the necessary tools, executables, and binaries to develop, compile, and run Java applications.
- Why Do We Need JDK?
- Essential for compiling Java programs.
- Includes the Java Runtime Environment (JRE) to run Java applications.
- Provides additional tools for development, debugging, and monitoring.
- Includes the Java API documentation.
- What is Java 17 LTS?
- Java 17 is the latest long-term support (LTS) version of Java.
- It is the recommended version for AP CS A.
- It will be supported for several years.
- It is the most stable version of Java.
- It is the most widely used version of Java.
- It is the most compatible version of Java.
- It is the most secure version of Java.
Steps to Install Java 17 LTS JDK:
System Requirements Check
- Before starting the installation, ensure your computer meets the system requirements for the Java 17 JDK.
- The minimum requirements are:
- 2 GB RAM
- 2.5 GB disk space
- 1280x800 screen resolution
- Windows 8 or later, macOS 10.13 or later, Linux x64
Downloading
- Visit the official Oracle website or an alternative provider like AdoptOpenJDK.
- Navigate to the downloads section for Java 17 LTS.
- Download the appropriate JDK distribution for your operating system (Windows, MacOS, Linux).
- Choose the correct architecture (32-bit or 64-bit) for your system.
- Choose the correct package format (.exe, .dmg, .tar.gz, .rpm, etc.) for your system.
--
Installation
Using Windows
- Launch the downloaded executable file.
- Follow the installation prompts, choosing the installation directory if needed (default is often suitable).
- Optionally, set up the JAVA_HOME environment variable.
- Optionally, add the bin directory of your JDK installation to the PATH variable.
Using MacOS
Using the .pkg file
- Open the downloaded .dmg file.
- Drag the JDK icon to the Applications folder.
- Optionally, set up the JAVA_HOME environment variable.
- Optionally, add the bin directory of your JDK installation to the PATH variable.
Using Homebrew
- Open a terminal.
- Install Homebrew if not already installed by running the command /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)".
- Run the command brew install --cask adoptopenjdk/openjdk/adoptopenjdk17.
- Optionally, set up the JAVA_HOME environment variable.
- Optionally, add the bin directory of your JDK installation to the PATH variable.
Using Linux
- Depending on the distribution format (.tar.gz or .rpm), use the appropriate method to install:
- For .tar.gz: Extract the package and move it to the desired directory.
- For .rpm: Use a package manager like yum or dnf to install.
- Optionally, set up the JAVA_HOME environment variable by editing the .bashrc file.
- Optionally, add the bin directory of your JDK installation to the PATH variable by editing the .bashrc file.
Verifying the Installation
- Open a terminal or command prompt.
- Type java -version and press Enter.
- The output should display the version number, confirming Java 17 is installed.
- Similarly, you can check the Java compiler with javac -version.
Setting Environment Variables in Windows (optional but recommended)
Verify Java Installation
- Open Command Prompt.
- Type java -version and press Enter.
- If Java is installed, the version will be displayed. Otherwise, you need to download and install the JDK.
Locate the Java Installation Directory
- Commonly, the JDK is installed in C:\Program Files\Java\jdk_version where jdk_version represents the version of the JDK.
- Make a note of this path.
Set the JAVA_HOME Environment Variable
- Right-click on This PC or Computer on the desktop or in File Explorer, then select Properties.
- Click on Advanced system settings on the left.
- Navigate to the Advanced tab and select Environment Variables.
- In the Environment Variables window, click New under the "System variables" section.
- For the Variable name, input JAVA_HOME.
- For the Variable value, enter the path you noted in step 2. For instance: C:\Program Files\Java\jdk_version.
- Click OK.
Add Java to the System PATH
- In the Environment Variables window (from Step 3), locate the Path variable under "System variables", then click Edit.
- In the Edit Environment Variable window, click New and enter the path %JAVA_HOME%\bin.
- Click OK on all open windows to close them.
Verify the Configuration
Open a new Command Prompt (close it first if one was already open). Type echo %JAVA_HOME% and press Enter. This should display the path of your JDK installation. Run java -version again to confirm that the system can identify the Java executable.
Tips and Considerations:
JRE vs JDK
- The JDK includes the JRE. Therefore, when you install the JDK, you can both compile and run Java applications.
- Separate JRE installations are usually not necessary unless you have specific requirements.
Multiple Versions
- It's possible to have multiple versions of Java on a single machine. Use the update-alternatives command on Linux or adjust the PATH variable on Windows/Mac to switch between versions.
- It's also possible to have multiple JDK versions on a single machine. However, only one version can be the default. Use the update-alternatives command on Linux or adjust the PATH variable on Windows/Mac to switch between versions.
Using a Package Manager
- On some platforms (like Linux), you can use package managers (like apt for Debian/Ubuntu or yum for Red Hat/Fedora) to install Java. This can simplify updates and multiple version management.
Licensing and Distribution
Be aware of the licensing terms of the Oracle JDK. As of recent versions, Oracle introduced new subscription-based licensing for Oracle JDK, which might not be suitable for all use cases.
Consider using alternative distributions like AdoptOpenJDK, Amazon Corretto, or others that may offer more favorable licensing terms or additional features.
Be aware of licensing terms
Be aware of the licensing terms of the Oracle JDK. As of recent versions, Oracle introduced new subscription-based licensing for Oracle JDK, which might not be suitable for all use cases.
OpenJDK is open-source
OpenJDK is the open-source reference implementation of the Java SE Platform. It is free to use and distribute. Oracle JDK is a commercial implementation of the Java SE Platform. It is free to use for development and testing, but requires a paid subscription for production use. There are multiple alternative distributions of OpenJDK:
- AdoptOpenJDK
- Amazon Corretto
- Azul Zulu
- BellSoft Liberica
- SAP Machine
- Red Hat OpenJDK
Troubleshooting
- If you run into any issues during the installation, check the official documentation for troubleshooting tips.
- If you are still unable to resolve the issue, consider using an alternative distribution like AdoptOpenJDK or Amazon Corretto.
Conclusion:
Understanding how to properly install the JDK is essential for anyone looking to develop in Java. Java 17 LTS, being a long-term support version, will be a stable choice for several years. Once set up, students can begin compiling and running Java applications as part of their AP CS A coursework.