Java Installation - Tutorials and Examples
Java comes in different editions: JSE (Java Standard Edition), JEE (Java Enterprise Edition), JME (Java Micro Edition). Beginners should try to start java programming with JSE. For this, you need to download, install and configure the JSE development environment. To compile and run a java program we need to install JDK (Java Development Kit) which is the basic set of tools required to compile and run java programs. To download J2SE on your machine for development visit http:/www.java.sun.com/j2se.
Java is a popular and fast growing programming language in the world. Java now comes with the support for Cloud application development which makes it a better choice among the developers of enterprise and cloud applications. The first step in any application development is to download and install Java. After installation you should check and verify that Java has been installed correctly. If there is some issue with the Java installation you should debug and fix the issues.
Java is still one of the most popular and widely used programming languages in the world. Java can be used for building enterprise-scale applications, developing cloud applications or developing Android apps. Java is also used for developing embedded devices applications. The first crucial step is to install Java correctly on your system and then test it. In this guide we are going to walk you through the steps of Java installation and testing, later we will provide you the links to other tutorials pages in our website where you will learn Java in more detail.
Understanding Java Editions
Java is available in different editions and before installation, it’s very important to understand all these Java editions. Here are Java editions:
- Java SE (Standard Edition): The Java SE is used for desktop and server-side applications. This version is also used for development of cloud applications and microservices.
- Java EE (Enterprise Edition): The Java EE is built on top of Java SE and provides the tools for the development of web-based and enterprise applications.
- Java ME (Micro Edition): This edition of Java is used for embedded systems and mobile devices.
- OpenJDK vs Oracle JDK: There is open source Java under the OpenJDK brand. OpenJDK is open source; Oracle JDK provides long-term support and additional features but has licensing restrictions.
Prerequisites for Installing Java
Here are some of the pre-requisites of Installing Java/JDK on your computer/operating system:
- Administrator access to your system - You should have administrative access to your system or at least privileges to install software.
- Basic command-line knowledge - You should know the commandline tool of your operating system.
- An internet connection to download installers - To download the Java installer you should have Internet connection on your computer
- Sufficient Hardware Resources - Your computer should have enough RAM and Disk space to install Java software.
Installing Java on Windows
Here are the steps of installation on Java on various versions of Windows operating system. On all the versions of Windows operating system installation steps are the same and after learning on one version you can easily install it on another version of Windows.
Step 1: Download Java
In this step you have to download the JDK exe file for your Windows operating system.
- Visit theofficial Oracle Java page orOpenJDK
- Choose the appropriate version for your system (e.g., Java 21 LTS)
Step 2: Run the Installer
In this step you have to run the .exe file and follow the installer instruction for installation of Java.
- Double-click the .exe file
- Follow the on-screen instructions
Step 3: Set Up Environment Variables
Finally you should set up the environment variables correctly so that Java is available in the System path.
- Open System Properties → Environment Variables
- Under System Variables, add:
- JAVA_HOME = Path to JDK folder (e.g., C:\Program Files\Java\jdk-21)
- Change this based on your Java version and installation location
- Add %JAVA_HOME%\bin to the Path variable
- JAVA_HOME = Path to JDK folder (e.g., C:\Program Files\Java\jdk-21)
- Change this based on your Java version and installation location
Installing Java on MacOS
Next we will see how we can install it on MacOS
Using Homebrew (Recommended)
Java can be install using the homebrew. Run the following command in terminal:
brew install openjdk@21
Then link it using the following command:
sudo ln -sfn /opt/homebrew/opt/openjdk@21/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-21.jdk
Set environment variables:
Next we have to setup system environment variable:
export JAVA_HOME=/opt/homebrew/opt/openjdk@21 export PATH=$JAVA_HOME/bin:$PATH
Add the above lines to your .zshrc or .bash_profile.
This will completely setup Java on MacOS.
Installing Java on Linux
Now we will look into the steps of installing Java on various Linux OS.
Ubuntu/Debian-based Distros:
To install Java on Ubuntu use ap installer and run following command in the terminal:
sudo apt update
sudo apt install openjdk-21-jdk
The above command will install openjdk version 21 on your Ubuntu operating system.
Red Hat/CentOS/Fedora:
On redhat, CentOS and Fedora machines use following installation command:
sudo dnf install java-21-openjdk-devel
Check installation with:
java -version
The above command will show you the version of Java installed on your operating system.
Setting Up Environment Variables
You should correctly set up the JAVA_HOME and PATH variables correctly on your operating system as part of the Java configuration step.
Windows:
Set JAVA_HOME and update the Path variable.
macOS/Linux:
Add the following lines to your shell profile (~/.bashrc, ~/.zshrc, etc.):
export JAVA_HOME=/path/to/jdk
export PATH=$JAVA_HOME/bin:$PATH
0Then run:
source ~/.bashrc
Verifying Java Installation
To confirm that Java is installed correctly:
1java -version
Sample output:
java version "21.0.2" 2024-01-16 LTS
2Also check the compiler:
javac -version
The above command should display the version of the Java compiler.
3Read more at:
https://www.roseindia.net/java/beginners/installing_java.shtml
https://www.roseindia.net/java/learn-java-in-a-day/download-and-install-java.shtml
4Related Tutorials: