Java Development Environment
To start programming in Java, you need two main components: the JDK (Java Development Kit) and an IDE (Integrated Development Environment). The JDK provides the compiler (javac), the runtime (java), and the standard libraries. An IDE helps you write, edit, and run code more efficiently.
Oracle releases a new JDK version every 6 months. LTS (Long-Term Support) versions such as Java 17 and Java 21 are the best choice for production projects because they receive security patch support for years. OpenJDK is also available for free as an open-source alternative to Oracle JDK.
Popular IDEs for Java include IntelliJ IDEA (most popular), Eclipse, and VS Code with the Java extension. IntelliJ IDEA Community Edition is free and already very adequate for learning. For dependency and build management, use Maven or Gradle.
Installation Steps:
- Download JDK 21 from Adoptium or Oracle
- Install IntelliJ IDEA Community Edition from JetBrains
- Set the
JAVA_HOMEenvironment variable to the JDK installation directory - Verify the installation with the
java -versionandjavac -versioncommands
Code Example
# Check the installed Java version
java -version
javac -version
# Compile and run a program
javac HelloWorld.java
java HelloWorld
Code Explanation
The java -version command displays the installed JVM version, including the build number and runtime environment. The javac -version command displays the Java compiler version. To run a Java program: first compile it with javac FileName.java, which produces a .class bytecode file, then run it with java FileName (without the extension). The JVM reads the bytecode and executes it.
Everyday Example
Imagine you just installed Java on a new laptop. The first thing you should do is verify that everything works correctly before you start coding:
# 1. Make sure JAVA_HOME is set
echo $JAVA_HOME
# 2. Check the version
java -version
# 3. Create a test file
echo 'public class Test { public static void main(String[] args) { System.out.println("Java is ready!"); } }' > Test.java
# 4. Compile and run
javac Test.java
java Test
# Output: Java is ready!
Summary
Setting up a Java development environment is the first crucial step. With JDK 21 and IntelliJ IDEA, you already have everything you need to start your Java programming journey. Always make sure to use an LTS version for production projects.