How To Install Java For Visual Studio Code: Easy Guide For Beginners

Learn to write, build & debug Java code with Visual Studio Code

DuAa AwAn
6 min readDec 10, 2023

Using Visual Studio Code for Java development is like having the best tools in an art studio, but instead of paints, you’re using code to create your masterpiece on the screen!

It is sleek, dynamic, and builds lightning-fast.

A newer release is available so let’s begin by updating the Visual Studio Code. If you have already updated you can skip this step and go straight to getting started with Java.

The download link from Visual Studio Code’s official website is here.

You can choose whichever installation according to your operating system. I will be installing it for Windows.

If you get the above message in your browser that means your download has begun.

It will be automatically updated. Like below.

1. Getting Started With Java:

Java development using VS Code is pretty dope. To get started all you need to do is to find the extensions tab which will be on the right sidebar.

It will have a small 4 cubes joined together sort of icon or you can use the shortcut key Ctrl + Shift + X.

Once your extensions tab is opened you can see all kinds of plugins. On the top of it will be a search bar.

Type Java in it to locate all Java-related extensions or plugins.

As you can see above the first plugin on the list is Extension Pack for Java is what we need to get started with Java development in VS Code.

Selecting it will open up the details view on the right side of the VS Code window. Here you will find a little blue button with a dropdown arrow to install Java Development tools.

This will install Intelli Code, Language Support for Java, Debugger, Maven, TestRunner, and Project Manager for Java.

Installation has begun.

Once its installation is complete the Welcome window will appear like below.

2. Setting Up Workspace:

To start you need to open your workspace which will be a folder of your choice. So we selected the Open Folder link and created a new folder named Sample Java Project.

Now by clicking Select Folder Button we have selected our workspace folder.

It will open the Do you trust the authors of this folder dialog. By selecting the check box and the button Yes, I trust the Authors button which enables all features.

Sample Java Project will be opened in the explorer.

3. New Java File

Hover over the project name it will show these icons with a plus sign to create a new file or folder.

We will create a new Java file by typing the file name hello.java and pressing enter.

The final result will look like this.

It will automatically create the hello class inside the hello.java file.

Now start typing main inside the hello class and select the main option from the menu which will write code for the application start function.

public class hello {
public static void main(String[] args) {

}
}

You can use Ctrl + S to save the file content.

Let’s print Hello World on the command prompt by typing system and it will open suggestions select System.out.println();

And add the text that you wish to display on screen like below:

public class hello {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

Step 4. Build, Run Program:

It’s time to build our program. You can see this play icon at the top corner of our window.

You can run your program by clicking this run button. This will open this firewall dialog. Here you can allow access and the program will display “Hello World” in the bottom Terminal.

Once you allow it, the terminal will start displaying the directory java.exe path with -cp command, and your sample project bin.

Hello World will be printed in front of your project directory.

Step 5. Debug Code:

By clicking on the column before the code line number you will be able to put a breakpoint on that line number.

The breakpoint means that once your code starts running it will come to that line number and pause until you make it resume code code execution.

These red dots are the breakpoints.

To debug code instead of running you will have to select the debug option after selecting the play drop-down arrow.

The moment the debugger starts and hits line number 5 where we have put our first break point it will pause code execution here and let us examine our code flow.

To go to the next line of execution press F5.

By placing the mouse on our previous line sum variable we can see the value assigned to the sum after calculation.

Press F5 again to get out of the debugger and finish the program execution. Which will output the result in the terminal.

That is how easy it is to write, build, run, and debug Java code in Visual Studio Code. The best part is that it is lightning-fast and has a very small learning curve.

Anyone can learn it in no time.

If you like the article follow me here on Medium to get more content like this and make your programming journey delightful.

--

--

DuAa AwAn

Software Engineer | Android | Tech Writer. Join me in exploring the endless possibilities of app development!