Recommended Prerequisites
Consider completing these modules before starting this one:
Understanding command line basics is essential for compiling and running Java programs using javac and java commands.
VS Code with Java extensions provides a powerful development environment for Java programming.
Having experience with another programming language like Python can help you understand Java concepts more easily.
☕ Getting Started with Java
Java is a widely-used programming language required for many computer science courses. This guide will help you install the Java Development Kit (JDK) and set up your environment for Java development.
🔍 Installation Options
Choose the installation method that works best for your operating system:
📦 Method 1: Official Installer
- Visit the Oracle website: https://www.oracle.com/java/technologies/javase-downloads.html
- Download the latest Java SE JDK for your operating system
- Run the installer, following the on-screen instructions
🍺 Method 2: Using Homebrew (Mac)
If you have Homebrew installed on your Mac, you can use it to install OpenJDK:
brew install openjdk
✅ Verifying Installation
After installation, verify that Java is correctly installed by checking the version:
java -version
⚙️ Setting Up Environment Variables
After installation, you may need to set up environment variables:
💻 Windows Environment Setup
- Right-click on This PC or My Computer and select Properties
- Click on Advanced system settings
- Click on Environment Variables
- Under System Variables, find and select Path, then click Edit
- Add the path to the JDK bin directory (e.g.,
C:\Program Files\Java\jdk-xx.x.x\bin
) - Click OK to save changes
🍏 Mac/Linux Environment Setup
Add the following to your .bash_profile
, .zshrc
, or equivalent:
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$JAVA_HOME/bin:$PATH
▶️ Compiling and Running Java Programs
To compile a Java program:
To run a compiled Java program:
javac YourProgram.java
java YourProgram
💻 Your First Java Program
Create a file named HelloWorld.java
with the following content:
Compile and run the program with:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
javac HelloWorld.java
java HelloWorld
📚 Additional Resources
- Oracle Java Documentation: https://docs.oracle.com/en/java/
- Java Tutorials: https://docs.oracle.com/javase/tutorial/
- Codecademy Java Course: https://www.codecademy.com/learn/learn-java
- University of Helsinki's Java MOOC: https://java-programming.mooc.fi/