How To Run Java in Visual Studio Code on Windows 10
Java programming is very fun and interesting. The only thing you might get difficulty in is the installation part for running Java programs. So in this article let’s find out how you can run Java in visual studio code.
Video Tutorial: Run Java in Visual Studio Code
If you’re still finding it hard running Java in Visual Studio Code on your Windows 10 machine then you can refer to the below video for a complete guide.
Step 1: Download the latest version of JDK (Java Development Kit)
1) First things first you’ll need to download a jdk.exe and to download that you’ll have to click on the download link we’ve provided below. From there you’ll be redirected to the official JDK download page. Once you’re on that page click on the “JDK Download” button.
JDK Download Link: https://www.oracle.com/in/java/technologies/javase-downloads
2) After that, you’ll be redirected to the “Java SE Development Kit Downloads” page. Now scroll down and there you’ll see a “windows X64 Installer” row and next to that a download link is given. Click on that link to download the installer for windows 10.
3) A popup screen will appear here, check the license agreement box and click on the long green download button. Depending on your internet connection the JDK file will get downloaded accordingly.
4) Now go to the folder where the downloaded exe file is available, right-click on the file and run it as administrator. A small window will appear to click on yes and the installation will begin.
5) Once the installation gets finished a new installation wizard for Java will appear, here click next.
6) After that you’ll be asked to choose the installation folder, here we will go with the default installation folder so click on next.
7) A progress bar will appear showing the installation progress, once it gets completed “Java(TM) SE Development Kit successfully installed” will appear on the screen and after that click on the close button.
Congrats, by this time you’ve successfully installed JDK in your windows 10 machine.
Step 2: Verify Java Version
1) To check if JDK is installed properly or not, open up your command prompt by pressing the Windows button, type “cmd” and press enter.
2) In the command prompt type, “java –-version” and press enter to check the installed version of JDK.
3) After that type “javac –-version” and press enter to check the installed version of the java compiler.
Now pat yourself in the back cause you’ve successfully installed JDK in windows 10 all by yourself.
Step 3: Installing Java Extension Pack in Visual Studio Code
1) Now open VS Code in your windows 10 and click on the icon shown in the image below.
2) After that search for “Java Extension Pack” provided by Microsoft and click on the small green install button.
3) Now come to the home screen of the visual studio code and click on New File.
4) By this time you are ready to run your first Java program in visual studio code, we have provided below a small code snippet that you can run directly by copy-pasting in vs code IDE.
Class Subscribe{ Public static void main(String args[]){ System.out.println("Subscribe Now!"); } }
5) Press Alt+f, click on “save as” to save the above-copied snippet and name it as “Subscribe.java”.
The key thing to note here is that you should always name your Java program the same as that of the main class and always add a “.java” extension.
6) Click on the small play button just like shown in the image below to compile and run your Java program.