Fullstack > Tools > ☕ Java
Java
Java is a powerful, object-oriented programming language used for building cross-platform applications, including web, desktop, and mobile applications. This guide will help you install Java on your system.
Step 1: Download Java
- Go to the official Oracle Java Download page.
- Select the latest Java SE version and download the installer suitable for your operating system (Windows, macOS, or Linux).
Step 2: Install Java
On Windows:
- Run the downloaded
.exefile. - Follow the installation wizard and complete the setup.
- Once installed, verify the installation by running the following command in Command Prompt:
java -version
On macOS:
- Run the downloaded
.dmgfile and follow the installation instructions. - Verify installation using:
java -version
On Linux:
- Open the terminal and run:
sudo apt update sudo apt install default-jdk - Verify installation:
java -version
Step 3: Set Up JAVA_HOME Environment Variable
Setting up the JAVA_HOME variable is essential for Java-based applications.
On Windows:
- Open System Properties > Advanced > Environment Variables.
- Add a new system variable:
- Variable name: JAVA_HOME
- Variable value: Path to Java installation (e.g.,
C:\Program Files\Java\jdk-XX.X.X)
On macOS and Linux:
- Open the terminal and edit your profile file:
nano ~/.bashrc # or ~/.zshrc - Add the following line:
export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java)))) - Apply changes:
source ~/.bashrc
Step 4: Verify Installation
Run the following command to check if Java is correctly installed and configured:
java -version
Step 5: Run an Example Java Program
- Open a text editor and create a new file named
HelloWorld.java. - Copy and paste the following Java code:
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } } - Save the file and navigate to the directory where it is saved using the terminal or command prompt.
- Compile the program using:
javac HelloWorld.java - Run the compiled Java program:
java HelloWorld - You should see the output:
Hello, World!
Conclusion
You have successfully installed Java on your system! You can now start developing Java applications using an IDE like IntelliJ IDEA or Eclipse.