Running Java in VS Code and IntelliJ
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.
- What two commands compile and then run a Java program by hand?
javac Hello.javato compile, thenjava Helloto run. - True or false: a Run button in an editor replaces those commands with something new. False. The button runs the same
javacthenjavafor you and only hides the two steps.
What You Need To Walk In With
Walk into the next class able to state these:
- An editor does not replace the language. VS Code and IntelliJ both run the same
javacandjavaunderneath; either one produces the same.classand the same output. - VS Code (used in CSCD 210) is a light editor: open the folder, press Run, read the Terminal panel.
- IntelliJ (used in CSCD 211) manages a whole project:
src/holds source, the green Run arrow uses a run configuration, and CSCD 211 projects build with Gradle. - Turn off the editor’s AI code completion while learning, so that the code you write is your own.
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.
- Open the folder that holds your
.javafile with File then Open Folder. - Press the Run triangle at the top right, or use the keyboard shortcut for Run.
- 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:
- Open Settings.
- Find the AI Assistant or inline completion setting.
- 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?
A program compiles and runs in IntelliJ. Will it also compile in VS Code?
Why turn off AI code completion while learning CS1?