Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 1

Java Development Environment Setup

This lesson is built with resources from youtube.com, blog.hakanserce.com and 1 more site.

Welcome to the course! I'm excited to guide you on your journey to becoming a senior backend and platform engineer. Given your extensive experience with the MERN stack, we'll be able to move quickly, focusing on mapping your existing knowledge to the Java and Spring Boot ecosystem.

This first lesson is all about setting up your workshop. Before we can build our production-grade blog platform, we need to install and understand the fundamental tools of the trade in the Java world.

Today, we will:

  • Demystify the Java ecosystem (JDK, JRE, and JVM) and compare it to the Node.js environment you know well.
  • Set up a professional Java development environment using a version manager, a build tool, and an IDE.
  • Compile and run your first Java application from the command line, observing the process from source code to execution.

By the end of this lesson, you'll have a fully functional Java development setup, ready for us to build upon in the next session.

1. The Java Platform: JDK, JRE, and JVM

In the JavaScript world, you have the Node.js runtime, which executes your server-side code. The Java ecosystem has a similar, but more structured, set of components.

  • JVM (Java Virtual Machine): This is the core component. Think of it as the equivalent of the Node.js runtime (which uses the V8 engine). The JVM's job is to execute compiled Java code. Its "write once, run anywhere" philosophy means that any code compiled for the JVM can run on any device that has a JVM, regardless of the underlying operating system.

  • JRE (Java Runtime Environment): This is a package that contains everything needed to run a Java application. It includes the JVM and core Java libraries. You would install the JRE on a server if you only needed to run pre-compiled Java applications.

  • JDK (Java Development Kit): This is what we, as developers, need. The JDK contains the JRE (including the JVM) plus development tools. The most important tool is javac, the Java compiler.

This diagram provides a great overview of how these components relate and the compilation process.

Java Virtual Machine (JVM) Architecture Explained
The JDK contains the JRE, which in turn contains the JVM. Your `.java` source files are compiled by `javac` (part of the JDK) into `.class` files (bytecode), which are then executed by the JVM.

MERN-to-Java Mapping: Compilation

Your TypeScript code is transpiled by tsc into JavaScript, which is then executed by Node.js. Java follows a similar but distinct path:

  1. You write code in a .java file.
  2. The javac compiler compiles it into bytecode, which is stored in a .class file. This bytecode is a platform-independent set of instructions.
  3. The JVM reads, interprets, and executes this bytecode. Modern JVMs use a Just-In-Time (JIT) compiler to convert frequently executed bytecode into native machine code at runtime for performance.

This image helps visualize the difference between compilation and the interpretation/JIT model common in JavaScript.

Compilation vs. Interpretation vs. JIT Compilation
Java uses a compilation model to create portable bytecode, which is then executed by the JVM, often with JIT compilation for performance. This contrasts with JavaScript's typically interpreted or JIT-compiled nature directly from source.

2. Installing the JDK with SDKMAN!

In your Node.js projects, you likely use nvm to manage different Node versions. The Java world has an equivalent that's even more powerful: SDKMAN!. It allows you to manage different versions of not just Java (from various vendors like Oracle, OpenJDK, Amazon), but also other JVM tools like Maven, Gradle, and even Spring Boot itself.

Using a version manager is a critical professional practice. To understand why, take a few minutes to read the following blog post. It perfectly frames the problem that tools like SDKMAN! solve.

Installing Java in 2025, and Version Managers

This article, 'Installing Java in 2025, and Version Managers', explains why managing Java versions manually is complex and why version managers are the modern, professional standard. It will resonate with your experience using tools like nvm.

Read the sections 'The Modern Reality', 'What Are Our Options?', 'The Benefits', and 'Popular Version Managers in the Wild'. Focus on how the challenges described mirror those in other ecosystems and why SDKMAN! is the preferred tool for the JVM.

Now, let's install the JDK. We'll use the video below as a guide. We'll install SDKMAN! and then use it to install Java. We will be using Java 17, as it's the current Long-Term Support (LTS) version and the standard for modern Spring Boot applications.

Install multiple Versions of Java with SDKMAN | Also works with Maven Gradle Spring Boot Kotlin etc

This video, 'Install multiple Versions of Java with SDKMAN', provides a clear, step-by-step walkthrough of installing and using SDKMAN! to manage Java versions. We will follow its guidance to set up our JDK.

Follow the video's instructions to install SDKMAN! and then a Java version. Specifically, watch the segments on installation (0:24-1:23), verifying the installation (1:23-1:32), and installing and switching Java versions (2:51-4:48).

Your Task: Install the JDK

  1. Install SDKMAN!: Open your terminal and run the installation command from the SDKMAN! website or the video.

    curl -s "https://get.sdkman.io" | bash
    

    Follow the on-screen instructions, which will likely involve sourcing a new script in your .bashrc or .zshrc file. Open a new terminal or run source "$HOME/.sdkman/bin/sdkman-init.sh" for the changes to take effect.

  2. Verify Installation:

    sdk version
    

    You should see the SDKMAN! version number printed.

  3. List Available Java Versions:

    sdk list java
    

    You will see a long list of Java versions from different vendors. Look for an identifier for Temurin (Eclipse Temurin), a popular, community-supported OpenJDK distribution.

  4. Install and Set Java 17 as Default:

    
    
    
    # The exact identifier might change, find one that looks like '17.x.x-tem'
    sdk install java 17.0.11-tem 
    

    SDKMAN will ask if you want to make this the default version. Say yes (Y).

  5. Verify Java Installation:

    java --version
    

    You should see output indicating you are running OpenJDK version 17.


3. Maven: Your New Build Tool & Dependency Manager

In the MERN stack, npm (or yarn) is your go-to for managing dependencies via package.json and running scripts. In the Java ecosystem, Maven is one of the most established tools for this.

  • pom.xml is your package.json: Maven uses a pom.xml (Project Object Model) file to define project information, dependencies, and the build process.
  • Convention over Configuration: Unlike the flexibility of a Node.js project structure, Maven projects follow a standard directory layout. This is a key principle: by adhering to the convention, you write less configuration.
    • src/main/java: Your application source code.
    • src/test/java: Your test code.
  • The Maven Wrapper (mvnw): Just like you might commit a yarn.lock file, Spring Boot projects include a "Maven Wrapper." This is a small script that automatically downloads the correct Maven version for the project. It ensures that everyone on the team, and your CI/CD server, uses the exact same build tool without needing to install Maven globally. For this reason, we will not install Maven globally. We will let our Spring Boot project (in the next lesson) set up the wrapper for us.

This crash course will give you a fantastic overview of Maven's core concepts.

Maven Tutorial - Crash Course

The 'Maven Tutorial - Crash Course' is an excellent, concise introduction to Maven. It covers everything from what Maven is to the structure of a pom.xml and the main build commands.

Watch the following sections to get a solid grasp of Maven's role: What is Maven? (0:03-0:34) The pom.xml file: (5:50-9:44) Pay close attention to groupId, artifactId, version, and the dependencies block. This is the direct analog to package.json. Dependency Scopes: (9:44-10:38) Understand the difference between compile and test scopes. Core Maven Commands: (14:28-19:18) Focus on clean, compile, test, and package. This is your npm run build equivalent. Convention over Configuration: (20:56-22:30) This explains the standard project layout.


4. Your IDE: IntelliJ IDEA

While you can use VS Code for Java, the vast majority of professional Java developers use IntelliJ IDEA. Its deep integration with Maven, Spring, and its powerful debugging and refactoring tools make it the best choice for our "debugging-first" approach.

Your Task: Download and install the free IntelliJ IDEA Community Edition from the JetBrains website.


5. Hands-On: A Classic "Hello, World!"

Let's put all the pieces together and build a simple Java application from scratch using the command line. This exercise will solidify your understanding of the basic Java/Maven workflow before we let Spring Boot automate it for us.

  1. Create Project Structure:
    Open your terminal and create the standard Maven directory structure. We'll use com.blogplatform as our group/package name.

    mkdir blog-platform-java-intro
    cd blog-platform-java-intro
    mkdir -p src/main/java/com/blogplatform
    

    The -p flag creates parent directories as needed.

  2. Create the pom.xml:
    Create a file named pom.xml in the blog-platform-java-intro root directory. This is the simplest possible POM for a Java 17 project.

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.blogplatform</groupId>
        <artifactId>java-intro</artifactId>
        <version>1.0-SNAPSHOT</version>
    
        <properties>
            <maven.compiler.source>17</maven.compiler.source>
            <maven.compiler.target>17</maven.compiler.target>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
    
    </project>
    
    • <groupId>, <artifactId>, <version>: These three are the "coordinates" that uniquely identify your project. It's like the name and version in package.json.
    • <properties>: Here we're telling Maven that our source code is written in Java 17 and we want to compile it for a Java 17 target.
  3. Create the Java Source File:
    Inside src/main/java/com/blogplatform, create a file named Main.java.

    package com.blogplatform;
    
    public class Main {
        public static void main(String[] args) {
            System.out.println("Hello, Backend Engineer!");
        }
    }
    
    • public class Main: Defines a class named Main. In Java, all code lives inside classes.
    • public static void main(String[] args): This is the special method signature that the JVM looks for as the entry point of an application. It's conceptually similar to the top-level execution of a node index.js script.
    • System.out.println(...): The Java equivalent of console.log().
  4. Compile and Run:
    Now, from the project's root directory (blog-platform-java-intro), run the Maven compile command. Since we don't have a Maven wrapper yet, we'll use the globally available mvn command for now.

    
    
    
    # Install maven globally just for this one time, we will remove it later
    sdk install maven
    
    
    
    
    # Compile the source code
    mvn compile
    

    You'll see Maven download some plugins and then report a BUILD SUCCESS. Look inside your project directory. You'll now see a target folder. This is where Maven places all build artifacts. Inside target/classes/com/blogplatform, you'll find Main.class—your compiled bytecode!

    Now, let's run it.

    
    
    
    # Run the compiled code
    java -cp target/classes com.blogplatform.Main
    
    • -cp target/classes: This sets the "classpath," telling the java executable where to find our compiled .class files.
    • com.blogplatform.Main: This is the fully qualified name of the class that contains our main method.

    You should see Hello, Backend Engineer! printed to your console.

  5. Import into IntelliJ:
    Finally, open IntelliJ IDEA. Choose "Open" and select the blog-platform-java-intro directory. IntelliJ will automatically recognize it as a Maven project, index the files, and set everything up. You can then open Main.java and click the green play button next to the main method to run your application directly from the IDE.


Conclusion

Congratulations! You've successfully set up a complete Java development environment from scratch. You've installed a JDK using a version manager, learned the fundamentals of Maven, and compiled and ran your first Java application.

Key Takeaways:

  • The JDK is for development, containing the compiler (javac) and the runtime (JRE + JVM).
  • SDKMAN! is the professional's tool for managing Java and other SDK versions, much like nvm for Node.js.
  • Maven is the standard build and dependency management tool, using pom.xml (like package.json) and a conventional project structure.
  • The Java build process is explicit: *.java files are compiled into *.class (bytecode) files, which are then executed by the JVM.

In our next lesson, we'll leave this manual setup behind and use Spring Initializr to generate a complete Spring Boot project. You'll see how the framework builds upon these fundamentals to give us a powerful, production-ready starting point with just a few clicks.