How to Run JAVA in Visual Studio Code on Windows 11

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so for developing java on visual studio code you need two things first thing is java jdk which should be installed on your windows 11 operating system and the other thing is visual studio code editor so for that first of all open your favorite browser and search for java jdk download and the first link which will appear here will be from oracle.com forward slash java forward slash technologies forward slash download so just click on this link i'm going to provide this link in the description of this video also so you can directly come to this website and here you just need to scroll down at the time of making this video java 17 is the latest version which is available for download so when you scroll down you will see the option to download the linux binaries or the mac os binaries or the windows binaries right so we are going to select windows from here and then we are going to select the exe option here so just select the link which is in front of the installer option here so click on this link here so just wait for the download to complete and once this exe file is downloaded i'm going to click on this exe file and let me minimize my browser so first of all you will see this kind of window which says do you want to allow this app to make changes on your device i trust this app so i will click on yes and now i can see the java jdk installer has been started on my windows 11 operating system so here you just need to click on the next button and this will be the default location where java will be installed on your windows 11 operating system just remember this location so by default it's installed in c then program files then it's going to create a java directory in program files folder and then there will be a jdk 17 folder or the name of the folder will be the version of jdk you are installing right so if you want to change this path just click on change and then change the destination otherwise if you don't have the good reason to change this location just leave it as default and then click on next which is going to start the installation of java on your windows 11 operating system so at this point you just need to wait for this process to complete and in few seconds you can see the java jdk has been installed on my windows 11 operating system so i'm going to close this window that means java is installed on my windows 11 operating system but still i have to do few things first of all i'm going to just go to the location where java is installed so just open your folder explorer and then go to the c directory and then i'm going to go to the program files where java folder is created and then in my case jdk 17.0.1 is created in your case this folder name version can be different so just go to this folder right now in order to set the environment variable for java what you need to do you can just click on the search icon once again and then just type edit and here which is going to show you this result which is edit environment variable for your account and it's going to open this kind of window you can also open this edit environment variable using control panel so you can search for control panel and then just view by category here and then click on system and security then click on system and then once the system window opens you can click on advanced system settings and then click on environment variables which is also going to show you the same window right so you can choose any method to open this environment variable window and once this is open you need to click on the path environment variable under system variables and then click on edit and here you need to add the path to your jdk folder binaries so go to the folder where we have installed java until a jdk folder and then click on bin folder so we need to go inside the bin folder inside this jdk folder and then copy the path right so until bin and then copy this path from here go to the environment variable window once again and then you can double click here or you can click on new which is go also going to show you this option and then just paste this path until bin and then press enter which is going to add this path to your environment variables click on ok so your java environment variable is set now some application also needs the java home environment variable on your windows operating system to run them so let me show you how you can set the java home environment variable also so you can go at the top under user variable section and then click on new here and then the variable name you need to provide here is java underscore home everything is capital just write whatever i have written here everything in capital and the variable value will be the folder which we have opened which is jdk folder so don't go inside the bin folder in this case just copy the path until jdk folder you don't need to go inside the bin folder in this case okay and then just paste this path under variable values okay so you can see there is no bin folder added here only the path until the jdk folder click on ok and then click on ok and then click on ok which is going to set the environment variable for java on your windows 11 operating system now once you have installed java and set the environment variables you can use java on command line so you can just open the command prompt by typing cmd once again and then i can type java space hyphen version here and it's going to show me the version of java so you can see java version 17.0.1 is installed on my windows 11 operating system now if you want to compile a java file you can use the java c command so you can just write java c space hyphen version here and then press enter and you can see the java c version is also same so as i said you can use java c to compile a java file on your window so after installing visual studio code and java jdk on your windows 11 operating system there is one more thing which you will require in order to develop java programs on visual studio code and that is the java support for your visual studio code so for that you can open your favorite browser once again and then search for visual studio code java and you will see the first link which will appear here which will be from code.visualstudio.com so i'm going to click on this link and i'm going to put this link in the description of this video also so the most important step here is when you scroll down you need to install this package which is called install the coding pack for java on windows so in order to fast track the process of java development on visual studio code visual studio code team has itself created this pack for java which you can install on your windows operating system or on your mac operating system and this will help you to develop java programs on your windows 11 operating system so now i'm going to click on this uh button which says install coding pack for java which is also going to download this exe file you can also read this description which says to help you set up we recommend you to use the coding pack for java which is the bundle of vs code the java development kit so now this exe file is downloaded for the java pack so i'm going to click on this exe file and let me minimize my browser and now you can see this install coding pack for java setup has been started so first step is to accept the license terms and conditions click on next here and then just verify everything you can see i have already installed java development kit 17 on my windows operating system and i already have the installation of visual studio code so this pack is going to detect if you have already have the java jdk installation and visual studio code installation so in the next step you just need to click on the install button which is going to start the installation of this coding pack for java so once this coding pack is installed you can see this message which says completing the setup just leave this checkbox as checked and then click on finish which is going to launch visual studio code on your windows operating system so now a visual studio code has been started with the java support you might be able to uh just check all the java related extensions here when you click on the extension icon here you will be able to see so when you click on extension pack for java it's already installed debugger for java it's also installed maven for java it's also installed so all the extensions which you will require to develop java programs on your visual studio code editor you will see the list of all the extensions here so now we are ready to develop some java code right so let me start from the very beginning so let's say you want to create your first java program in visual studio code so what i'm going to do here is i'm going to just to open the command prompt i will just write cmd and here i'm going to create a new directory so first of all let's say i want to create this project folder on the desktop so i will just cd to the desktop directory and here i can create a folder using the command mkdir you can right click on the desktop and create the folder also i'm going to name my folder as a sample and then press enter and you will see the sample project has been created so let me go inside that folder so just type cd sample here and then press enter and now you are inside the sample directory right here you can write code space dot and then press enter which is going to open this sample folder in visual studio code directly right if you don't want to use the command line just do it everything using this gui and then go inside the project folder right now it's empty you can right click here and then click on show more options and then click on open with code which is also going to open the same folder in your visual studio code so let's say i want to create a very simple hello world java program here i can create a java file using this icon or using file and then new file or i can simply right click here and then click on new file here so i'm going to name my file as hello dot java and once i do that i will just press enter and once you create this file you can see visual studio code is going to automatically detect the file extension and you will be able to see this language here you can also see projects are imported into workspace so let me just create a very simple hello class in this hello.java file so i'm going to just type class here and you can see visual studio code is going to detect that you are trying to create a class in this hello.java file and when you just select the second option here you can see visual studio code has automatically created this hello class for me now in order to create a main method inside this hello class i can just type main here and once again visual studio code is going to show you intellisense and show you all these options and it has detected that i want to create the main method inside this class and i'm going to just select the first option here which is going to create the main method inside this hello class from me automatically so how simple this is right now let's say i want to just type hello world i can just write system dot out dot print line and at every step you will be able to see this intellisense so i will be able to uh complete my code faster and then let me just uh print hello world here and it's that simple to create your first hello world java uh program right now how you can run your java programs so you for that you have few options here the obvious one is this one which is this run button and it's going to run your java program the second option is to just right click on your java file and when you scroll down and you will be able to see this run java option and the bug java option so you can use these two options to run and debug your java program or you will see this option here on the top of your main method run or debug so you can also use uh one of these options to run your program or debug your program you also have this run option here and it's going to allow you to start debugging and all the other options related to debugging are available here also so let's run our program so i'm going to just click on this run button which is going to compile our java program and for the first time it's going to show me this warning i'm going to just click on allow access and you can see uh visual studio code has already compiled our code and ran our code and the output is printed here now let's say you forgot to type the semicolon here visual studio code is going to show you this red error and it's also going to show you what can be this error so it's you see it's a syntax error and we need to insert the semicolon at the last right so it's going to help you to detect the errors in your java code also now let's say you have written the wrong code which will not compile but then also you want to just compile it then you will see this error here in the problems tab and you will see the details of the error here right so the exact line number on which the error is coming and when you click on this error it's going to just redirect you to the particular line from which the error is coming so this is how you can detect the errors and fix them also let's try to debug our code so you can click on this debug option here or you can click on this debug icon here on the left hand side and then you can click on run and debug option so i'm going to click on run and debug which is going to start the java debugger and because i haven't added any break point my debugger has ran successfully and it has printed hello world let's say i will just add a break point here all my break points i will be able to see here under break points so i can add multiple break points uh in my code using these red dots and i can keep the track of all the breakpoints under this breakpoints section i can disable all the breakpoint at once using this toggle uh active breakpoint button which is going to deactivate all the breakpoints if i want to remove all the breakpoints then i can just click on this icon which is going to remove all the breakpoints right let's say i have just added the breakpoint here and then ran the debugger once again this time you can see the execution of my code has been stopped on the breakpoint and i will be able to see the argument values here and then i have all these options so i can continue using this button i can step over to the next line i can step into a method or i can step out from a method i can also restart my debugger stop my debugger and this option is for hot code replace option right so i have all these options here so now let me just stop this uh debugging from here and let me add some codes so let's say i just declared two number num1 which will be equal to five let's say and then i'm going to declare a second variable which is called num2 and the value of it is 10 let's say right and i'm going to create a third variable which will be called let's say sum here and it will be the sum of num1 plus num 2 right so you will be able to see at each and every point visual studio code is going to show us hint and intellisense to complete our code faster and now i want to just print the value of sum here right and now i have uh more debugging possibilities and let me just start the debugger once again i have added three break points here and here you can see that i will be able to keep the track of all the local variables here i can also watch for some variables here for example i want to watch for a variable called sum i can just add that but the program execution is still not there so right now cannot evaluate because of the compilation error right so let's step over to the next line you can see the value 5 is assigned to variable num1 step over once again now num2 has 10 and then step over once again now we have the sum which is equal to 15 and this variable we were watching right so it was in our watch list so now it shows the value right so you can see the global and local variable lists here you can watch for some variables and you have the track of all these breakpoints here right so this is how you can debug your java code on your visual studio code also have the possibility so let me just stop this debugger so you also have the possibility to create a launch.json file and here you can provide the configuration related to debugging on this launch.json file so you can click on this create a launch dot json file so just click on this launch.json file which is going to create this launch.json file and you can see all the configuration related to the java debugging and when you click on the explorer option you will be able to see this dot vs code folder is created and under that you have this launch dot json file so this is good when you are just creating your program and then just pushing it to some github repository and then somebody else will be able to take your launch configuration and he will be able to use it for debugging your java program right you also have this github versioning for your source code so when you have git installed visual studio code is going to track all the changes which you make on your project in your java files and it will allow you to commit or push your code or pull some repository from github or any other repository right you can also search for some code using the search option and if these extensions are not enough you can search more java related extensions by just typing java and then you will be able to find more java related extensions here so you can install them and use them for developing different java frameworks so let's say i want to add the support for spring so i can just install the this extension and then develops spring based app in my visual studio code editor so this is how you can set up and use java in your visual studio code editor i hope you've enjoyed this video and i will see you in the next video
Info
Channel: ProgrammingKnowledge2
Views: 26,232
Rating: undefined out of 5
Keywords: Java Development, Visual Studio Code, Windows, vsCode, Java Development Basics, Java, Set Up Java, Visual Studio, Java (Programming Language), Java (Software), Java Development Kit (Software), Introduction, Linux, Ubuntu (Operating System), Eclipse IDE, Eclipse (Software), OS X, Mac, Mac OS X, Download and Install, How to, wiki, how to articles, Eclipse, Eclipse on Mac, How to install Eclipse on Mac, Learn Java, Java Tutorial, Java Tutorial course, First Java Project, Windows 11
Id: Rp1UZsPuO04
Channel Id: undefined
Length: 23min 7sec (1387 seconds)
Published: Wed Mar 09 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.