Skip to content

Installing Java and VS Code

This page explains how to install and configure VS Code for Java in CS 159.

Definitions and Acronyms

Java
An object-oriented programming language
JDK
Java Development Kit (which you need to compile Java programs)
OpenJDK
A free and open-source implementation of a JDK
Eclipse Temurin
The OpenJDK distribution from the Adoptium working group
Adoptium
A community project supported by many companies with an interest in OpenJDK
VS Code
An open-source integrated development environment (that was created by Microsoft and supports many languages, including Java, C/C++, JavaScript, Python, and more)

Note

If you are on a CS lab machine, OpenJDK and VS Code are already installed. Skip to Step 3.

Install OpenJDK

Warning

We recommend you install Java 21 (which is the version that has long-term support), because that is the version installed in the computer labs and on Gradescope. If you install a later version, you might have unexpected errors.

Visit the Latest Releases page and use the drop-down boxes to select the following options:

  • Operating System
    • Select macOS or Windows, depending on your laptop.
    • Note: If you're running Linux, install the JDK this way:
      sudo apt install openjdk-21-jdk openjdk-21-source
  • Architecture
    • For Windows, select x64.
    • For macOS, select aarch64. (Or select x64 if you have a Mac from before 2021.)
  • Package Type
    • Select JDK (Java Development Kit).
  • Version
    • Select 21 - LTS (Long Term Support).

After downloading, run the installer. To verify the installation was successful, open a Terminal and type java -version.

Install VS Code

Visit code.visualstudio.com and click the Download button.

  • On Linux, install the deb or rpm package. Additional details are available here.
  • On macOS, drag the app to the Applications folder. Additional details are available here.
  • On Windows, run the installer and follow the steps. Additional details are available here.

If you are running VS Code for the first time, you should see the Welcome Page. If you have used VS Code in the past, you will likely see your previous files.

Figure 1: VS Code's Welcome Page
Welcome - Visual Studio Code

Install Extensions

Extensions add new features and languages to VS Code. Developers can publish extensions via the Marketplace.

  1. Click the Extensions icon in the Activity Bar (on the left).
    Extensions (Ctrl+Shift+X)
  2. Search for (by name) and install the following extensions:
  3. Uninstall the following unneeded extensions (that come with the Extension Pack):

In the end, you should have the following extensions installed:

Figure 2: List of Installed Extensions
VS Code extensions screenshot

The CS159 Folder

Download and open (extract) CS159.zip, which contains a CS159 folder. You will use this CS159 folder throughout the semester. Move the CS159 folder to where you store your other files for school.

Note

Ideally you should have a separate folder for each course you take. Do not store the CS159 folder in your Downloads. After you have moved the CS159 folder, delete the CS159.zip file in your Downloads.

Now open the CS159 folder in VS Code. You should see the following subfolders:

  • .vscode – settings and configuration files for CS 159
  • bin – binary files, which will be created automatically
  • lib – required libraries, such as JaCoCo and JUnit
  • src – source files, where all your programs will go

Important

Make sure you have the entire CS159 folder open in VS Code. Otherwise, none of the settings or libraries will be active. To open the CS159 folder, go to File → Open Folder.

Open src/demo/HelloWorld.java, and press F5 to run the program. VS Code will open a Terminal window. The terminal shows: (1) the command used to run the program, and (2) the program's output.

For each homework or lab, you will add a new subfolder under src. Eventually, you will have many .java files across many subfolders.

Going Further (optional)

The official tutorial by Microsoft is available here: Getting Started with Java in VS Code (see the 14 articles linked on the left of that page).

You don't need to read the official tutorial. As the semester progresses, you will learn what you need to know by experience.