How To Setup Java for VSCode | Setting Up VSCode For Java Programming

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys in this video I'm going to show you how you can set up visual studio code for Java development on your windows 11 operating system 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 if you don't know how to install Java jdk on your Windows operating system then I will provide the link in the description of this video and you can watch that video and see how we can install Java jdk same goes for visual studio code so if you don't know how to install Visual Studio code just click the link in the description of this video and you will be good to go 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 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 our 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 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 this 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 complete my code faster and then let me just print hello volt here and it's that simple to create your first hello world Java 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 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 Visual Studio code has already compiled our code and ran our code and the output is printed here now let's say you forget 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 breakpoint 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 breakpoints so I can add multiple breakpoints 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 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 run 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 debugging from here and let me add some codes so let's say I just declared two number number one which will be equal to 5 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 uh 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 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 a 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 a 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 uh 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 get 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 post 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 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 framework so let's say I want to add the support for spring so I can just install the this extension and then develop 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: 16,440
Rating: undefined out of 5
Keywords: how to run Java code in visual studio code, how to run Java program in visual studio code terminal, visual studio code Java, Java extension for visual studio code, how to install pip in visual studio code, Java download, visual studio code download, Java interpreter vscode
Id: EfJMFzVU1sM
Channel Id: undefined
Length: 16min 41sec (1001 seconds)
Published: Sat Mar 18 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.