← Java

Java · 01 / 18

Install Java and run the first program

Compile a Java file and run the resulting program.

  • Small
  • Basics
  • 15 min

Prerequisites: No prior knowledge required.

Java is a programming language. A JDK contains tools for compiling and running Java code. We use Java 21, matching PDF Batch Studio. You initially need neither Spring Boot nor a database. We create one file containing a greeting, then examine the difference between source text and a compiled program.

Example files

01Check the JDK

Install a complete JDK 21. In a terminal, check java --version and javac --version. javac is the compiler. If only java is available, you may have installed just a runtime or configured the wrong PATH.

02Write Main.java

The public class is Main, so the file is Main.java. The main method is the entry point. String[] args accepts optional startup arguments. System.out.println outputs text followed by a newline. We will learn the keywords gradually.

Main.java · javaOpen file
public class Main {
  public static void main(String[] args) {
    System.out.println("Hello, AppFabrik!");
  }
}

Run / check

javac Main.java
java Main

03Compile and run

javac Main.java creates Main.class. java Main runs this class without specifying a file extension. Recompile after changing the source. Java 21 can also run a single source file directly with java Main.java.

Expected result

Hello, AppFabrik!

Your exercise

Add a second output and run first without recompiling, then after recompiling.

Show the solution and explanation

java Main uses the existing .class file. javac updates it. After recompilation the program displays both lines. This explains why saved source and executed code can represent different versions.

Project context and sources

The example is simplified for learning. The linked source version shows its use in the project and the checks applied there.