EMFAD Courses

Module 1: Java Foundations

The JVM and Java Ecosystem

Java runs a huge share of the world's business software: banking back ends, payment switches, Android apps, insurance systems and large e-commerce platforms. Before you write a single line, it helps to understand how Java code actually gets from your editor to a running program. That knowledge will save you hours when you hit your first "class not found" or "wrong version" error.

From source code to running program

Java is a compiled and then interpreted language. The journey has three stages:

  1. You write source code in a file ending in .java, for example Hello.java.
  2. The Java compiler, javac, turns that source into bytecode, saved in a file ending in .class. Bytecode is not machine code for your specific processor. It is a set of instructions for an imaginary computer.
  3. The Java Virtual Machine (JVM) reads the bytecode and runs it. Modern JVMs include a Just-In-Time (JIT) compiler that watches which parts of your program run often and compiles those parts into fast native machine code while the program runs.

This design is why Java became famous for the phrase "write once, run anywhere". The same .class file can run on Windows, macOS or Linux, as long as a JVM is installed there.

JDK, JRE and JVM: what you actually install

Three acronyms confuse almost every beginner, so let us settle them:

NameWhat it isWho needs it
JVMThe engine that executes bytecodeEveryone who runs Java programs
JREJava Runtime Environment: a JVM plus the standard class librariesHistorically, people who only run programs
JDKJava Development Kit: the JRE plus developer tools such as javac, jar and javadocYou, as a developer

As a developer, install a JDK. Several organisations publish free builds of the same open-source code base (OpenJDK), for example Eclipse Temurin, Amazon Corretto and Microsoft's build of OpenJDK. Any of them is fine for this course. Choose a Long-Term Support (LTS) version, because LTS releases receive updates for years and are what most employers run. Check the official OpenJDK or vendor website for the current LTS number before you download.

You will also want an editor. IntelliJ IDEA Community Edition, Visual Studio Code with the Java extensions, and Eclipse are all free and widely used.

Worked example: your first program by hand

Create a folder called java-course and inside it a file named Hello.java with this content:

public class Hello {
    public static void main(String[] args) {
        System.out.println("Habari, Java!");
    }
}

Open a terminal in that folder and run:

javac Hello.java
java Hello

The first command creates Hello.class. The second starts a JVM, loads the class called Hello and calls its main method, which prints the greeting. Notice that you pass the class name to java, not the file name with .class.

A few rules are already visible here. A public class must live in a file with exactly the same name, including capital letters. Every program starts at a method with the signature public static void main(String[] args). Statements end with semicolons, and code blocks are wrapped in curly braces.

Since Java 11 you can also run a single source file directly with java Hello.java, which compiles in memory. It is handy for quick experiments, but real projects use the two-step process or a build tool, which you will meet in the final module.

The wider ecosystem

Java is more than a language. The standard library gives you ready-made classes for text, dates, collections, files, networking and concurrency. Around it sits a large ecosystem: build tools (Maven, Gradle), testing libraries (JUnit), and frameworks such as Spring for web services. Other languages, such as Kotlin and Scala, also compile to JVM bytecode, which is why JVM knowledge transfers well.

Common mistakes to avoid

  • Installing only a runtime. If javac -version says "command not found", you installed a runtime without the JDK, or the JDK's bin folder is not on your PATH.
  • File and class name mismatch. public class Hello inside hello.java will not compile.
  • Running java Hello.class. Use the class name only.
  • Mixing versions. Bytecode compiled with a newer JDK will not run on an older JVM. Check both with java -version and javac -version.

Exercise

Install a current LTS JDK and a free editor of your choice. Run java -version and javac -version and confirm they report the same major version. Then create Hello.java from the lesson, change the message to include your own name and city, compile it with javac and run it with java. Finally, look inside your folder and note which new file the compiler created.

Key points

  • The compiler (javac) turns .java source into .class bytecode, and the JVM runs that bytecode.
  • Developers install a JDK; it contains the runtime plus tools like javac.
  • Choose a Long-Term Support version and confirm java and javac report the same version.
  • A public class must be saved in a file with exactly the same name.

Enjoyed this lesson?

The full course has 15 lessons with exercises, a quiz after every module, a final project and a certificate of completion. About 6 hours, USD 39, lifetime access.

Course details