Home / Java & Spring Boot / Setting Up Your Java Environment

Lesson 1 of 6

Setting Up Your Java Environment

Estimated time: 1.5–2 hours

What You Will Learn

  • Understand what Java is and why it matters in today's job market
  • Install the Java Development Kit (JDK) on your computer
  • Choose and set up a code editor for Java development
  • Write, compile, and run your first Java program
  • Understand basic Java syntax and how it differs from JavaScript

Part 1: What is Java?

Welcome to a brand-new chapter of your coding journey! If you have been following along with the earlier lessons in this course, you have already learned HTML, CSS, and JavaScript — the three core languages of the web. You have built web pages, styled them, and made them interactive. That is a huge accomplishment, and those skills will serve you well for your entire career.

Now we are going to learn a completely different programming language called Java. Before we go any further, let us address the single most common point of confusion for beginners:

Important: Java and JavaScript are completely different languages. Despite the similar names, they have almost nothing in common. They were created by different people, at different companies, for different purposes. The name similarity is a historical accident — when JavaScript was created in 1995, the marketing team thought naming it after the already-popular Java language would attract more developers. It is widely considered one of the most confusing naming decisions in the history of technology. Think of it this way: the relationship between Java and JavaScript is like the relationship between "car" and "carpet" — they share a few letters, but that is where the similarity ends.

So what is Java? Java is a general-purpose programming language that was created by James Gosling at Sun Microsystems in 1995. It was designed from the ground up to be reliable, portable, and powerful enough to run everything from tiny embedded devices to massive enterprise systems. Today, Java is one of the most widely used programming languages in the world, consistently ranking in the top three alongside Python and JavaScript.

Java is everywhere, and you interact with it more often than you probably realize. Here are just a few places Java powers the technology around you:

One of Java's most famous features is its platform independence, often described by the slogan "write once, run anywhere." Here is what that means: when you write a program in most languages, you compile it into instructions that only work on one specific type of computer. A program compiled for Windows will not run on a Mac, and vice versa. Java takes a different approach. When you compile a Java program, it does not get turned into instructions for a specific machine. Instead, it gets compiled into something called bytecode — a special intermediate format. That bytecode then runs on the Java Virtual Machine (JVM), which is a program that acts like a translator between your bytecode and whatever computer it is running on.

How Java Code Runs

The journey from Java code to a running program has three steps:

  1. You write Java source code in a .java file (human-readable text).
  2. The compiler (javac) translates your source code into bytecode, saved in a .class file.
  3. The JVM executes the bytecode on whatever operating system you are running — Windows, Mac, or Linux. The JVM handles all the platform-specific details for you.

This is why Java is platform-independent: the same bytecode runs on any machine that has a JVM installed.

So why are we learning Java in this course? There are several important reasons, and they are all connected to your goal of becoming employable as a developer.

First, the job market. Java is one of the most in-demand programming languages for employment. If you search for developer jobs on Indeed, LinkedIn, or Glassdoor right now — especially here in the Lansing, Michigan area — you will find that a significant number of positions ask for Java experience. State government agencies, insurance companies like Auto-Owners and Jackson National Life, health systems like Sparrow and McLaren, and tech companies throughout the Greater Lansing region all hire Java developers. Learning Java opens doors that JavaScript alone cannot.

Second, we are going to use Java to learn Spring Boot, which is a powerful framework for building web applications and APIs. Spring Boot is to Java what React or Express is to JavaScript — it is the tool that makes Java practical and productive for building modern web services. Companies love Spring Boot because it lets developers build robust, scalable backend systems quickly. We will dive into Spring Boot in the next lesson.

Third, learning Java will make you a stronger programmer overall. Java is what is called a statically typed language, which means you have to declare what type of data a variable holds (a number, a string, a boolean, and so on). Coming from JavaScript, where you can put anything in any variable without declaring its type, this might feel strict at first. But that strictness is actually a superpower — Java catches many mistakes at compile time, before your program even runs. This discipline will make you think more carefully about your code and catch bugs earlier.

Let us take a quick look at how Java compares to what you already know. In the earlier lessons, you learned about three languages that work together in the browser: HTML defines structure, CSS defines style, and JavaScript defines behavior. All three of those languages run in the browser (the client side). Java, on the other hand, typically runs on the server side — the computer that receives requests from browsers and sends back responses. When you visit a website, your browser (running HTML, CSS, and JavaScript) talks to a server (which might be running Java). You are about to learn both halves of that conversation, which makes you a much more complete developer.

Part 2: Installing the Java Development Kit (JDK)

Before you can write and run Java programs, you need to install the Java Development Kit, commonly called the JDK. The JDK is a free software package that contains everything you need to develop Java applications. It includes two critical tools:

JDK vs JRE: You might see references to the JRE (Java Runtime Environment) online. The JRE only lets you run Java programs — it does not include the compiler, so you cannot create programs with it. The JDK includes everything the JRE has, plus the compiler and other development tools. As a developer, you always want the JDK. The good news is that starting with Java 11, Oracle stopped distributing the JRE separately, so when you install the JDK, you get everything you need.

We are going to install JDK 21, which is a Long-Term Support (LTS) release. LTS versions are supported with security updates and bug fixes for many years, which makes them the best choice for learning and for professional work. JDK 21 was released in September 2023 and will be supported through at least September 2028.

Choose the tab below that matches your operating system and run the command in your terminal (Command Prompt or PowerShell on Windows, Terminal on Mac or Linux):

winget install Oracle.JDK.21 --accept-package-agreements --accept-source-agreements
brew install openjdk@21
sudo apt install openjdk-21-jdk
Windows users: The winget command comes built into Windows 10 (version 1809 and later) and Windows 11. If winget is not recognized, you can download it by installing "App Installer" from the Microsoft Store, or you can download the JDK directly from Oracle's website. Mac users: If you do not have Homebrew installed yet, visit brew.sh and follow the one-line install instruction first. Linux users: The apt command works on Debian-based distributions like Ubuntu and Linux Mint. If you use Fedora, use sudo dnf install java-21-openjdk-devel instead.

After the installation finishes, you need to verify that Java was installed correctly. Open a new terminal window (this is important — the old terminal might not recognize the new commands yet) and run these two commands:

java -version
javac -version

If everything is set up correctly, you should see output that includes the version number 21 (the exact minor version number may vary). For example, you might see something like java version "21.0.2" and javac 21.0.2. The specific minor version does not matter — what matters is that both commands work and show version 21.

If you see an error like "java" is not recognized as an internal or external command on Windows, or command not found: java on Mac or Linux, it means Java is either not installed or the system does not know where to find it. Here are some troubleshooting steps:

Do not move on to the next section until both java -version and javac -version work correctly. Having a working Java installation is the foundation for everything else in this lesson and the rest of the Java track.

Part 3: Choosing a Code Editor

Now that Java is installed, you need a good code editor to write your Java programs in. If you have been following this course from the beginning, you probably already have Visual Studio Code (VS Code) installed from the earlier web development lessons. The great news is that VS Code works wonderfully for Java development too — you just need to install one extension pack.

Open VS Code, click the Extensions icon in the left sidebar (it looks like four small squares), and search for "Extension Pack for Java" by Microsoft. Click Install. This single extension pack bundles together everything you need: Java language support, a debugger, test runner, project manager, and IntelliSense (smart code completion that suggests what to type as you write). Once it is installed, VS Code becomes a powerful Java development environment. You will see red underlines for errors, helpful auto-complete suggestions, and the ability to run Java programs directly from the editor.

Once the Extension Pack is installed, VS Code will look and feel different when you open a Java file. Here is what to expect:

What You Will See: The Extension Pack adds several features you will use constantly. The most important is the Run | Debug link that appears directly above every main method — clicking it compiles and runs your program in one step. You will also see red squiggly underlines beneath errors in real time, just like a spell-checker for your code. As you type, IntelliSense will pop up suggestions to auto-complete class names, method names, and variables. Finally, the Java Projects view appears in the Explorer sidebar, giving you a structured overview of your files and packages.
The Integrated Terminal: VS Code has a built-in terminal so you never have to leave the editor. Open it with Ctrl+` on Windows/Linux or Cmd+` on Mac (that is the backtick key, usually above Tab). You can also open it from the menu: Terminal > New Terminal. It appears at the bottom of the VS Code window and works exactly like your system terminal — you can run javac, java, and any other command right there. We will use this terminal throughout the Java lessons.

If you want to explore other options, the most popular alternative is IntelliJ IDEA Community Edition by JetBrains. IntelliJ is a full-featured Integrated Development Environment (IDE) built specifically for Java. It is incredibly powerful and is what many professional Java developers use at work. The Community Edition is completely free. You can download it from jetbrains.com/idea. IntelliJ is heavier than VS Code — it uses more memory and takes longer to start up — but it provides deeper Java-specific features right out of the box.

For this course, we recommend sticking with VS Code since you are already familiar with it. It keeps things simple and avoids the learning curve of a new tool. You can always switch to IntelliJ later as you become more comfortable with Java. The code you write will be exactly the same regardless of which editor you use.

Tip: Java development involves more files and more structure than the HTML, CSS, and JavaScript you have been writing. A good code editor is not optional — it is essential. Writing Java in a basic text editor like Notepad is technically possible but extremely painful. Your editor's features (error highlighting, auto-complete, easy file navigation) will save you enormous amounts of time and frustration. Make sure you have one set up before moving on.

Part 4: Your First Java Program — Hello World

Every programming language has a tradition: the first program you write should simply print the words "Hello, World!" to the screen. It is a small program, but it proves that your entire development environment is working correctly — you can write code, compile it, and run it. Let us do this in Java.

Open your code editor and create a new file called HelloWorld.java. This file name matters — in Java, the file name must match the class name inside it (we will explain what a class is in a moment). Type the following code exactly as shown:

Creating a file in VS Code: Press Ctrl+N (Windows/Linux) or Cmd+N (Mac) to create a new file, then Ctrl+S / Cmd+S to save it as HelloWorld.java. You can also right-click in the Explorer sidebar and choose New File. Once you save with the .java extension, the file icon will change to a Java icon — that is your confirmation that VS Code recognizes it as a Java file.
package org.codersfarm.learn;

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}
Look for Run | Debug: With the Extension Pack for Java installed, you should see a Run | Debug link appear directly above the public static void main line. Clicking Run will compile and execute your program automatically — no terminal commands needed. We will also show you the terminal commands below, because understanding javac and java is important. But for quick testing, the Run button is your friend.

That is your first Java program! If you are coming from JavaScript, your first reaction might be: "That is a lot of code just to print one line." And you are right — in JavaScript, you could accomplish the same thing with just console.log("Hello, World!");. Java requires more structure, and every piece of that structure has a purpose. Let us break it down line by line.

Line 1: package org.codersfarm.learn;

The very first line of every Java file is the package declaration. A package is like a folder that organizes your Java classes — similar to how you organize files into directories on your computer. The package name org.codersfarm.learn tells Java that this class belongs to that group. Every Java file you create should start with a package declaration. When you compile with javac -d ., Java automatically creates the matching folder structure (org/codersfarm/learn/) for you.

Line 3: public class HelloWorld {

In Java, all code must live inside a class. A class is like a container that groups related code together. For now, think of it as a required wrapper around your program. The word public means this class is accessible from anywhere (we will explore access levels later in the course). The word class is the keyword that tells Java you are defining a class. HelloWorld is the name you are giving this class — and it must exactly match your file name (without the .java extension). The opening curly brace { marks the beginning of the class body.

Line 4: public static void main(String[] args) {

This is the main method — the entry point of every Java program. When you run a Java program, the JVM looks for this exact method signature and starts executing from here. Let us break down each word:

Note: You do not need to memorize what every keyword in public static void main(String[] args) means right now. For the time being, just think of it as the magic incantation that tells Java "this is where my program starts." You will type it so many times that it will become second nature, and you will understand each piece more deeply as we progress through the course.

Line 5: System.out.println("Hello, World!");

This is the line that actually does something — it prints the text "Hello, World!" to the console. Let us break this down too:

If you are thinking "Java's System.out.println() is like JavaScript's console.log()," you are exactly right! They serve the same purpose — outputting text so you can see it. Java's version is just longer to type.

Lines 6 and 7: The Closing Braces

The closing braces } on lines 6 and 7 close the main method and the HelloWorld class, respectively. Every opening brace { must have a matching closing brace }. Keeping track of braces is important in Java — a missing brace is one of the most common causes of compiler errors for beginners.

Compiling and Running Your Program

Now let us compile and run your program. Open VS Code's integrated terminal with Ctrl+` (Windows/Linux) or Cmd+` (Mac), navigate to the folder where you saved HelloWorld.java, and run these two commands:

javac -d . HelloWorld.java
java org.codersfarm.learn.HelloWorld

The first command, javac -d . HelloWorld.java, runs the Java compiler. The -d . flag tells the compiler to create the proper folder structure for the package — it will automatically create an org/codersfarm/learn/ directory and place the compiled HelloWorld.class file inside it. If your code has no errors, it will do this silently. If there are errors, the compiler will print error messages telling you what went wrong and on which line. Read those messages carefully — they are usually very specific and helpful.

VS Code catches errors before you compile: Thanks to the Extension Pack, VS Code shows errors as red underlines in your code before you even run javac. Hover over any red underline to see a tooltip explaining the problem. You can also open the Problems panel with Ctrl+Shift+M (Windows/Linux) or Cmd+Shift+M (Mac) to see all errors in one list. Fix the red underlines before compiling and javac will usually succeed on the first try.

The second command, java org.codersfarm.learn.HelloWorld, runs the compiled bytecode on the JVM. Notice that you use javac (Java Compiler) to compile, but just java to run. You also need to use the fully qualified class name — the package name followed by the class name, separated by dots. If everything worked, you should see:

Hello, World!

Congratulations — you just wrote, compiled, and ran your first Java program! That might seem like a simple output, but a lot just happened under the hood: your source code was analyzed by the compiler, translated into bytecode, loaded onto the JVM, and executed. Every Java program you write for the rest of your career will follow this same compile-then-run process.

Let us compare the Hello World experience side by side to make the differences between Java and JavaScript crystal clear:

Step JavaScript Java
Write the code console.log("Hello, World!"); Requires a class and a main method wrapper
File name Anything (e.g., hello.js) Must match the class name (HelloWorld.java)
Compile step None (interpreted directly) javac -d . HelloWorld.java
Run the program node hello.js java org.codersfarm.learn.HelloWorld
Output method console.log() System.out.println()

Part 5: Java Basics — A Quick Tour

Now that you have your environment set up and have run your first program, let us take a quick tour of Java's basic syntax. Since you already know JavaScript, you have a huge head start — many of the concepts are the same, just with different syntax. The biggest difference you will notice is that Java requires you to declare the type of every variable.

Variables with Types

In JavaScript, you create variables with let or const and you can put any kind of value in them without telling JavaScript what type it is. JavaScript figures out the type on its own. Java works differently — you must explicitly declare the type of every variable when you create it. Here is how it looks:

package org.codersfarm.learn;

public class VariableExamples {
    public static void main(String[] args) {
        // Integer (whole number)
        int age = 25;

        // Decimal number
        double temperature = 72.5;

        // Text
        String name = "Maria";

        // True or false
        boolean isStudent = true;

        System.out.println("Name: " + name);
        System.out.println("Age: " + age);
        System.out.println("Temperature: " + temperature);
        System.out.println("Is student: " + isStudent);
    }
}

Let us look at each of those types:

Why Does Java Require Types?

When you tell Java that a variable is an int, Java knows exactly how much memory to allocate and exactly what operations are valid. If you try to put text into an int variable, the compiler catches the mistake immediately — before you even run the program. In JavaScript, that same mistake might only show up when a user does something unexpected, causing your running application to crash. Java's type system is like a spell-checker for your code: it flags problems early, before they reach your users. This is called static typing, and it is one of the main reasons Java is trusted for building critical systems like banking software and medical records.

Here is a side-by-side comparison of how you declare the same variables in both languages:

// JavaScript (dynamically typed)
// let age = 25;
// let temperature = 72.5;
// let name = "Maria";
// let isStudent = true;

// Java (statically typed)
int age = 25;
double temperature = 72.5;
String name = "Maria";
boolean isStudent = true;

In JavaScript, let handles everything regardless of the value type. In Java, you replace let with the specific type: int, double, String, or boolean. Once you declare a variable as a certain type, it can only hold values of that type. You cannot put a string into an int variable — the compiler will refuse to compile your code.

Basic Operations

The good news is that basic math operations in Java look exactly like JavaScript. Addition, subtraction, multiplication, division, and the remainder operator all use the same symbols:

package org.codersfarm.learn;

public class BasicMath {
    public static void main(String[] args) {
        int a = 20;
        int b = 7;

        System.out.println("Addition: " + (a + b));        // 27
        System.out.println("Subtraction: " + (a - b));     // 13
        System.out.println("Multiplication: " + (a * b));  // 140
        System.out.println("Division: " + (a / b));        // 2 (integer division!)
        System.out.println("Remainder: " + (a % b));       // 6

        // For decimal division, use double
        double x = 20.0;
        double y = 7.0;
        System.out.println("Decimal division: " + (x / y)); // 2.857142857142857
    }
}
Watch out for integer division! When you divide two int values in Java, the result is also an int — the decimal part gets thrown away. So 20 / 7 gives you 2, not 2.857. This is different from JavaScript, where all numbers are decimals by default. If you want decimal precision in Java, make sure at least one of the numbers is a double (like 20.0 / 7).

String Concatenation

Just like JavaScript, you can join strings together using the + operator. You have already seen this in the examples above when we combined strings with variables in System.out.println(). Java is smart enough to convert numbers and booleans to strings automatically when you concatenate them with the + operator:

package org.codersfarm.learn;

public class StringExamples {
    public static void main(String[] args) {
        String firstName = "Alex";
        String lastName = "Johnson";
        int age = 28;
        String city = "Lansing";

        // Concatenation with +
        String fullName = firstName + " " + lastName;
        System.out.println("Full name: " + fullName);

        // Mixing strings and numbers
        System.out.println(fullName + " is " + age + " years old.");
        System.out.println("They live in " + city + ", Michigan.");

        // Useful String methods
        System.out.println("Uppercase: " + fullName.toUpperCase());
        System.out.println("Lowercase: " + fullName.toLowerCase());
        System.out.println("Name length: " + fullName.length());
    }
}

Notice how similar the string methods are to JavaScript. Both languages have .toUpperCase(), .toLowerCase(), and .length() (though in JavaScript, .length is a property without parentheses, while in Java, .length() is a method with parentheses). If you already know these methods from JavaScript, you are in great shape — the concepts transfer directly.

Java vs JavaScript: A Quick Reference

Here is a summary table comparing the key syntax differences between the two languages. Keep this handy as you start writing Java — it will help you avoid the most common mistakes when switching between them:

Feature JavaScript Java
Variable declaration let x = 10; int x = 10;
Constant declaration const x = 10; final int x = 10;
String declaration let s = "hello"; or 'hello' String s = "hello"; (double quotes only)
Print to console console.log("hi"); System.out.println("hi");
Type system Dynamic (types checked at runtime) Static (types checked at compile time)
Semicolons Optional (auto-inserted) Required (compiler error without them)
Code structure Can write code anywhere All code must be inside a class
Program entry point Runs from top of file Runs from main method
Compilation Interpreted (no compile step) Compiled with javac -d ., then run with java
Integer division 7 / 2 = 3.5 7 / 2 = 3 (truncates decimal)

Do not feel like you need to memorize all of this right now. The differences will become natural as you practice writing Java code. The most important things to remember are: always declare your variable types, always end statements with semicolons, and always put your code inside a class with a main method.

Putting It All Together

Let us finish with a slightly larger program that uses everything we have covered. Study this code and see how all the pieces fit together. Try typing it into your editor, compiling it, and running it yourself:

package org.codersfarm.learn;

public class AboutMe {
    public static void main(String[] args) {
        // Personal information
        String name = "Your Name";
        int age = 25;
        String city = "Lansing";
        String state = "Michigan";
        boolean isLearningJava = true;

        // Print a greeting
        System.out.println("=== About Me ===");
        System.out.println("Name: " + name);
        System.out.println("Age: " + age);
        System.out.println("Location: " + city + ", " + state);
        System.out.println("Learning Java: " + isLearningJava);

        // Do some calculations
        int birthYear = 2025 - age;
        System.out.println("Approximate birth year: " + birthYear);

        int ageInMonths = age * 12;
        System.out.println("Age in months: " + ageInMonths);

        // String operations
        System.out.println("Name in uppercase: " + name.toUpperCase());
        System.out.println("Name length: " + name.length() + " characters");

        System.out.println("=================");
        System.out.println("Welcome to Coders Farm, " + name + "!");
    }
}

Save this file as AboutMe.java (remember — the file name must match the class name). Replace "Your Name" with your actual name, update your age, and then compile and run it:

Quick reminder: Create a new file with Ctrl+N / Cmd+N, save it as AboutMe.java, and you can click the Run link above main to run it instantly. Or use the terminal commands below.
javac -d . AboutMe.java
java org.codersfarm.learn.AboutMe

If everything compiles and runs without errors, and you see your personalized output in the terminal, you have successfully set up your Java environment and written real Java code. That is a major milestone. You now have all the tools you need to dive deeper into Java programming in the lessons ahead.

Knowledge Check

Let us make sure you have a solid understanding of the key concepts from this lesson. Give each question a try — you can review the lesson and try again as many times as you like.

1. What is the main difference between Java and JavaScript?

Correct! Java and JavaScript are completely different languages. They were created by different people, at different companies, for different purposes. The similar name was a marketing decision from 1995 and has confused beginners ever since. Java is a statically typed, compiled language often used for enterprise and Android development, while JavaScript is a dynamically typed, interpreted language originally designed for web browsers.

2. What command compiles a Java file named MyProgram.java?

That is right! The javac command (Java Compiler) is what compiles your .java source file into bytecode. It produces a .class file that the JVM can execute. After compiling, you run the program with java MyProgram (without the .java extension). Remember: javac to compile, java to run.

3. Why does Java require you to declare variable types (like int, String, boolean)?

Exactly! Java's static type system catches many errors at compile time — before your program ever runs. If you accidentally try to store text in a number variable or perform math on a string, the compiler will immediately tell you. This prevents bugs from reaching your users and is one of the main reasons Java is trusted for building critical systems like banking software, medical records, and government applications.

Lesson Summary

Outstanding work — you just completed a major setup lesson and took your first steps into Java programming! Here is everything you accomplished:

In the next lesson, we will introduce Spring Boot — the framework that makes Java practical and powerful for building modern web applications and APIs. You will see how everything you just learned connects to building real-world backend services. See you there!

Finished this lesson?

← Previous: Your Path to Employment Next: Intro to Spring Boot →