Fundaments of Java for Junior Devs 1.
- What is Java? Java is a high-level, object-oriented programming language. Its most famous feature is being platform-independent, thanks to the slogan: “Write Once, Run Anywhere” (WORA).
Key Components: JDK (Java Development Kit): The full “toolbox” you need to write and compile Java code.
JRE (Java Runtime Environment): The “engine” needed to run Java applications.
JVM (Java Virtual Machine): The component that actually executes the code on your specific operating system (Linux, Windows, etc.).
- Setup on Debian Since you are using Debian with XFCE, you can install the OpenJDK (the open-source version of Java) directly from your terminal:
Update your package list:
Bash
sudo apt update
Install the JDK (Version 17 or 21 is standard for DAM):
Bash
sudo apt install openjdk-17-jdk
Confirm installation:
Bash
java -version
- Basic Rules for Beginners Before writing your first line, remember these three golden rules:
Case Sensitivity: Main is NOT the same as main. Java is very strict about this.
File Naming: The filename must match the class name exactly.
Example: If your class is Hello, your file must be Hello.java.
The Semicolon: Almost every statement must end with a ;. If you forget it, the code won’t compile.
- Your First Program: “Hello World” Create a file named Hello.java and type the following code:
Java
public class Hello {
public static void main(String[] args) {
// This is a comment. It is not executed.
System.out.println("Hello, World!");
}
}
Breaking down the code: public class Hello: Defines a “blueprint” named Hello.
public static void main(String[] args): This is the Entry Point. Every Java program starts here.
System.out.println: The command to “print” text to the console. The ln stands for “line,” meaning it moves to the next line after printing.
- Compile and Run (The Workflow) Java uses a two-step process: Compiling (translating code to Bytecode) and Executing (running that Bytecode).
Compile the source code:
Bash
javac Hello.java
This creates a Hello.class file (the bytecode).
Run the program:
Bash
java Hello
Note: Do NOT add .java or .class when running it.
Pro-Tips for Students Braces { }: They define “blocks” of code. Everything inside the class braces belongs to the class; everything inside the main braces belongs to the program’s logic.
Indentation: Use the Tab key to indent your code. It doesn’t change how Java runs, but it makes your code readable for you and your teachers.
Would you like me to show you how to handle Variables (like storing numbers or names) next?