How to set up Java with Visual Studio Code [Step-by-Step]

In this tutorial we will cover step by step instructions to set up Java with Visual Studio Code. Later we will also use VSC to write our first Hello World Java Program. But first let me give you a brief overview on Visual Studio Code.

 

Introduction to Visual Studio Code

Visual Studio Code is not just another evolved Notepad with syntax colorization and automatic indentation. Instead, it is a very powerful code-focused development environment expressly designed to make it easier to write web, mobile, and cloud applications using languages that are available to different development platforms and to support the application development life cycle with a built-in debugger and integrated support for the popular Git version control engine.

Visual Studio Code has been the first cross-platform development tool in the Microsoft Visual Studio family that runs on Windows, Linux, and macOS. It is free, open source (https://github.com/microsoft/vscode), and definitely a code-centric tool

 

Set up Java with Visual Studio Code

Step-1: Download VSC Coding Pack for Java

If you already have Visual Studio Code installed, then you can just go ahead and install the Extension Pack for Java

But since I do not have Visual Studio Code tool itself not installed, so I will go ahead and download the Coding Pack for Java. This Coding Pack includes Visual Studio Code, the Java Development Kit (JDK), and essential Java extensions.

The Coding Pack can be used as a clean installation, or to update or repair an existing development environment. This coding pack is available for Windows and macOS. However, for other operating systems, you will need to manually install a JDK, VS Code, and Java extensions.

 

Step-2: Install VSC Coding Pack for Java

Next double click on the JavaCodingPack software which you downloaded in the previous step to start the installer.

Set up Java with visual studio code

 

Step-3: Select Components to be installed with VSC

It will show the list of required components that include JDK and Visual Studio Code. If JDK is already installed, it will map the path of that JDK. However, if it is not installed then it will install both components.

List of components

 

Once you click on Install, the installation of all pre-requisite components will start.

Installing

 

Step-4: Launch Visual Studio Code

The wizard has finished the installation of all the components. Now, Click on Launch to start the Visual Studio Code.

Finish Installation and Launch

 

This is the landing page of Visual Studio Code. For the first time, it will ask you to select the theme. Depending on your choice, you can select dark or light theme.

Landing page
Now you are done with steps to set up java with Visual Studio Code editor.

 

Write and compile your first program using Visual Studio Code

Let us now learn step by step procedure to write and compile our first program on visual studio Code editor.

 

Step-1: Create Workspace

You can either create a folder for your Java program and open the folder with Visual Studio Code. You can also create a Java project using the Java: Create Java Project command.

Open folder

 

Next in Visual Studio Code, create a new file and save it with the name Demo.java.

How to set up Java with Visual Studio Code [Step-by-Step]

 

Step-2: Create your first Java Hello World program using VSC

We will go ahead and write two print statements with Hello World. Moreover, the Visual Studio Code also provides IntelliSense for code completion, and various refactor methods.

How to set up Java with Visual Studio Code [Step-by-Step]

 

Step-3: Compile and Execute your Java Program

Step 4 : Now to run your code, You can either run active file or open the New Terminal from Terminal Menu.

How to set up Java with Visual Studio Code [Step-by-Step]

Step 5 : Navigate to your Java file and folder using the commands cd. Then compile java file using the command javac Demo.java. If the file compiles successfully, it will not show any message and you can then go ahead with execution of file.

However, if the code has any errors, it will be listed on terminal after compilation. In order to execute the java file write "Java Demo" without giving file extension. This executes the file and displays the output.

How to set up Java with Visual Studio Code [Step-by-Step]

 

Summary

Here, We are done with step by step procedure to set up Java with Visual Studio Code Editor. This is the first step to learning the Java Programming. This editor is very helpful in compiling and running your code easily. In this tutorial, we covered step by step procedure to download and install the Visual code editor and set up java with visual studio code editor for windows OS. All in all, this tutorial, covers everything that you need to know in order to set up java with visual studio code on Windows OS.

 

References

Download Visual Studio Code Installer

 

Didn't find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can either use the comments section or contact me form.

Thank You for your support!!

Leave a Comment