Java Environment Setup & Hello World
A comprehensive guide to setting up the Java Development Kit (JDK) and writing your very first Java program.
Overview of Java
Java is a high-level, class-based, object-oriented programming language designed to have as few implementation dependencies as possible. The mantra of Java is 'Write Once, Run Anywhere' (WORA).
Setting Up the Environment
To develop Java applications, you need the Java Development Kit (JDK). Follow these steps:
- Go to the official Oracle website or adoptium.net to download the JDK.
- Install the JDK on your system.
- Set the
JAVA_HOMEenvironment variable pointing to your JDK installation directory. - Add the JDK
bindirectory to your system'sPATHvariable.
Your First Java Program
Every Java application begins with a class name, and that class must match the filename.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}Understanding the Code
public: An access modifier meaning this class is accessible everywhere.class: Keyword used to declare a class.static: Means the method belongs to the class, not an instance.void: The return type; it returns nothing.main: The entry point of any Java program.String[] args: Command-line arguments passed as an array of Strings.