← Skill tree CS Skill Tree 0 CSCD210

Running Java in VS Code and IntelliJ

Textbook: BJP (Reges and Stepp)

Where you are: Week 0 review > Running Java in VS Code and IntelliJ

Try This First

First time seeing javac and java? Open for a 20-second refresher.

When you write Java source code, the compiler (<code>javac</code>) translates it into bytecode stored in a <code>.class</code> file. The Java Virtual Machine (<code>java</code>) then reads that bytecode and produces output. These are always two separate steps. See How a Java Program Compiles and Runs for the full picture.

You wrote Hello.java and want to see its output. Two paths exist: type javac Hello.java then java Hello in a terminal, or press a Run button in an editor. Decide what the Run button does that the two terminal commands do not.

Reveal

Nothing different in principle. The Run button runs javac then java for you. The editor hides the two steps, but it performs the same compile-then-run pipeline.

Before You Start

Check each box you can do from memory. A box you cannot check yet is not a problem; it points you to a quick refresher, not a grade.

Not sure? Take the 60-second self-check.

Try each from memory, then read the answer under it.

  1. What two commands compile and then run a Java program by hand? javac Hello.java to compile, then java Hello to run.
  2. True or false: a Run button in an editor replaces those commands with something new. False. The button runs the same javac then java for you and only hides the two steps.

What You Need To Walk In With

Walk into the next class able to state these:

You should be able to: open and run a simple program in either editor, and turn off AI completion.

How It Works

VS Code (CSCD 210)

VS Code with the Extension Pack for Java (from Microsoft) adds syntax highlighting, a Run button, and a terminal.

  1. Open the folder that holds your .java file with File then Open Folder.
  2. Press the Run triangle at the top right, or use the keyboard shortcut for Run.
  3. Output appears in the Terminal panel at the bottom.

The same two commands work by hand in any terminal:

javac Hello.java
java Hello

IntelliJ IDEA (CSCD 211)

IntelliJ manages a project rather than single files. On opening one you see four areas:

Area What it shows
Project view (left) The folder tree: src/ for source, build/ for compiled output.
Editor (center) The file you are editing, with live error highlighting.
Gradle tool window (right) Build tasks, when the project uses Gradle (CSCD 211 does).
Run toolbar (top right) The green arrow that runs the current run configuration.

The first time you open a class that has a main method, press the green arrow in the left margin next to main. IntelliJ creates a run configuration, and after that the top toolbar arrow runs the same class.

Turn off AI completion while learning

IntelliJ and many editors ship with inline AI suggestions that finish your code as you type. Turn this off while you are learning, so that every line is your own:

  1. Open Settings.
  2. Find the AI Assistant or inline completion setting.
  3. Switch it off, and confirm.

You can switch it back on later. While learning, typing each line yourself builds the recall you need for written exams.

A Common Mistake

A common belief is that the editor is the language, so a program that runs in IntelliJ might not run in VS Code. Both editors call the same javac and java. A program that compiles in one compiles in the other; the editor only changes the convenience around the same pipeline. (Source: BJP (Reges and Stepp), Ch 1.)

Go Deeper (optional)

For the curious: the reason CSCD 211 adds Gradle is that real projects have many files and outside libraries, and typing javac by hand stops scaling. Gradle records what to compile, what libraries to fetch, and how to run tests, so one command builds the whole project the same way on any machine.

Check Yourself

Close the notes and answer each one from memory, then reveal it. Pulling an idea back from memory is one of the strongest ways to make it stick.

Check your understanding

What does the Run button in VS Code or IntelliJ do?

Tier 1 · BJP (Reges and Stepp), Ch 1

A program compiles and runs in IntelliJ. Will it also compile in VS Code?

Tier 2 · BJP (Reges and Stepp), Ch 1

Why turn off AI code completion while learning CS1?

Tier 1 · BJP (Reges and Stepp), Ch 1