Introduction to Java
Java is one of the most widely used programming languages in the world, created in 1995 by Sun Microsystems (now Oracle). Its "Write Once, Run Anywhere" philosophy has made it the preferred choice for enterprise applications, Android, and distributed systems.
What You'll Learn
- History and philosophy of Java
- Difference between JVM, JRE and JDK
- Development environment setup
- Structure of a Java program
- Naming conventions
History of Java
Java was born in 1991 as an internal Sun Microsystems project called "Oak", led by James Gosling. The goal was to create a language for embedded devices, but with the explosion of the web, Java found its niche in applets and server-side applications.
Key Milestones
- 1995: First public release (Java 1.0)
- 2004: Java 5 introduces generics, annotations, enums
- 2014: Java 8 brings lambda expressions and Stream API
- 2017: Oracle adopts six-month release cycle
- 2021: Java 17 LTS (Long Term Support)
- 2023: Java 21 LTS with virtual threads
JVM, JRE and JDK
Understanding the difference between these three components is fundamental for every Java developer.
JVM (Java Virtual Machine)
The JVM is the heart of the Java ecosystem. It's a virtual machine that executes Java bytecode, making programs platform-independent.
Source Code (.java)
|
v
Compiler (javac)
|
v
Bytecode (.class)
|
v
JVM (execution)
JRE (Java Runtime Environment)
The JRE includes the JVM plus the standard libraries needed to run Java applications. It's sufficient for end users who only need to run Java programs.
JDK (Java Development Kit)
The JDK includes the JRE plus development tools: compiler (javac), debugger, documentation and various utilities. It's necessary to develop Java applications.
+------------------------------------------+
| JDK |
| +------------------------------------+ |
| | JRE | |
| | +------------------------------+ | |
| | | JVM | | |
| | +------------------------------+ | |
| | + Standard Libraries | | |
| +------------------------------------+ |
| + Compiler (javac) |
| + Debugger |
| + Tools (jar, javadoc, etc.) |
+------------------------------------------+
Development Environment Setup
1. JDK Installation
To develop in Java, I recommend installing an LTS (Long Term Support) distribution like Java 21.
# Update repositories
sudo apt update
# Install OpenJDK 21
sudo apt install openjdk-21-jdk
# Verify installation
java --version
javac --version
# Install OpenJDK 21
brew install openjdk@21
# Add to PATH
echo 'export PATH="/opt/homebrew/opt/openjdk@21/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
# Verify
java --version
# Download from: https://adoptium.net/
# Or use winget:
winget install EclipseAdoptium.Temurin.21.JDK
# Verify (PowerShell)
java --version
2. IDE Configuration
IntelliJ IDEA is the most widely used IDE for professional Java development. The Community version is free and sufficient for this course.
Recommended IDEs
- IntelliJ IDEA: Most complete, great for enterprise projects
- VS Code: Lightweight, with Java extensions (Extension Pack for Java)
- Eclipse: Historic, still used in enterprise environments
Structure of a Java Program
The First Program
Every Java program starts with a class containing the main method.
/**
* My first Java program.
* This is a Javadoc comment.
*/
public class HelloWorld {
/**
* Application entry point.
* @param args command line arguments
*/
public static void main(String[] args) {
// This is a single line comment
System.out.println("Hello, World!");
/*
* This is a
* multi-line comment
*/
}
}
Structure Analysis
public class HelloWorld // Class declaration
{ // Class MUST have same name as file
public // Access modifier (visible everywhere)
static // Class method (no instance required)
void // Return type (no value)
main // Method name (entry point)
(String[] args) // Parameters (string array)
System.out.println() // Print to console with newline
}
Compilation and Execution
# Compile source file
javac HelloWorld.java
# HelloWorld.class is generated (bytecode)
# Run the program
java HelloWorld
# Output: Hello, World!
Naming Conventions
Java has well-defined naming conventions that make code readable and professional.
// CLASSES: PascalCase (uppercase initial for each word)
public class UniversityStudent { }
public class OrderManager { }
// METHODS and VARIABLES: camelCase (lowercase initial)
public void calculateAverage() { }
private String fullName;
int studentCount;
// CONSTANTS: UPPER_SNAKE_CASE
public static final int MAX_STUDENTS = 30;
public static final String SCHOOL_CODE = "SC001";
// PACKAGES: all lowercase, reversed domain
package com.school.management.students;
package edu.university.grades;
Best Practices for Names
Rules to Follow
- Descriptive:
calculateGradeAverage()instead ofcalc() - Avoid abbreviations:
studentinstead ofstd - Verbs for methods:
getGrade(),setName(),isPassed() - Nouns for classes:
Student,Course,Grade - Plural for collections:
List<Student> students
Types of Comments
// 1. Single line comment
int grade = 8; // Student's grade
// 2. Multi-line comment
/*
* This block of code calculates
* the average of a student's grades
* considering all semesters.
*/
// 3. Javadoc comment (for documentation)
/**
* Calculates the arithmetic average of grades.
*
* @param grades array of grades to average
* @return the calculated average
* @throws IllegalArgumentException if array is empty
*/
public double calculateAverage(int[] grades) {
// implementation
}
Complete Example: School Registry
package edu.school.registry;
/**
* Main class of the School Registry.
* Demonstrates the basic structure of a Java program.
*
* @author Federico Calo
* @version 1.0
*/
public class SchoolRegistry {
// Class constants
public static final String SCHOOL_NAME = "Einstein Science High School";
public static final int SCHOOL_YEAR = 2025;
/**
* Application entry point.
*
* @param args command line arguments (not used)
*/
public static void main(String[] args) {
// Print header
System.out.println("================================");
System.out.println(" " + SCHOOL_NAME);
System.out.println(" School Year: " + SCHOOL_YEAR);
System.out.println("================================");
// Sample data
String studentName = "John Smith";
String className = "3A";
int[] mathGrades = {7, 8, 6, 9, 8};
// Calculate average
double average = calculateAverage(mathGrades);
// Print result
System.out.println("\nStudent: " + studentName);
System.out.println("Class: " + className);
System.out.println("Math Average: " + average);
System.out.println("Result: " + (average >= 6 ? "Passed" : "Failed"));
}
/**
* Calculates the arithmetic average of a grade array.
*
* @param grades array containing the grades
* @return the arithmetic average of grades
*/
public static double calculateAverage(int[] grades) {
if (grades == null || grades.length == 0) {
return 0.0;
}
int sum = 0;
for (int grade : grades) {
sum += grade;
}
return (double) sum / grades.length;
}
}
================================
Einstein Science High School
School Year: 2025
================================
Student: John Smith
Class: 3A
Math Average: 7.6
Result: Passed
Conclusion
In this first article we covered the basics of Java: its history, the JVM/JRE/JDK architecture, how to set up the development environment, and the structure of a Java program.
In the next article we'll dive into primitive data types and flow control: variables, operators, conditions and loops.
Key Takeaways
- JDK: Required for development (includes compiler)
- JRE: Required to run (includes JVM + libraries)
- JVM: Executes bytecode, ensures portability
- main: Entry point of every Java application
- Naming: PascalCase for classes, camelCase for methods/variables
- Javadoc: Documents code professionally







