If you want Java in Visual Studio Code and you do not want to cry into your terminal this afternoon then this is the guide for you. We will walk through installing a JDK verifying the runtime is available installing the right extensions and getting a simple project to build run and debug. Keep calm and blame gradle later.
Pick a vendor such as Temurin or OpenJDK and run the platform installer like a normal person. After installation open a terminal and confirm the JVM is visible by running
java -version
If the command prints a Java version you are good to move on. If not check your installation steps and environment variables described below.
Download VS Code from the official site and install it for your operating system. Launch the editor and try not to be intimidated by the welcome screen. You will need the editor for the next step which is installing Java related extensions.
Open the Extensions view and search for the Java Extension Pack. Install the pack to get the language server code runner and debugger bundled together. Also consider adding these individual helpers if you want particular powers
Once installed the Java extension pack will configure many defaults so you can focus on programming rather than arguing with the IDE.
Tell VS Code where your JDK lives by setting the standard JAVA_HOME environment variable. On Unix like systems add a line to your shell profile that looks like this
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk
Then update your PATH so the JDK bin folder is found by terminals and tools. To do that prepend the path to the JDK bin folder then use a word for the separator and then the existing PATH variable when you run the export command. If you are on Windows use the System Properties environment variables UI to set JAVA_HOME and add the JDK bin folder to Path.
You can generate a project with the Java Project Explorer or create files by hand. For a minimal example make a HelloWorld class compile it and run it from the project folder with these commands
javac HelloWorld.java
java HelloWorld
VS Code also offers a handy run button in the editor gutter for quick execution. To debug place breakpoints in the source open the Run and Debug view and start a debug session. The extensions create sensible launch settings so stepping through code inspecting variables and evaluating expressions works out of the box.
The flow goes like this install a JDK install VS Code add the Java extension pack configure runtime variables create a project then build run and debug. Follow these steps and you will have a working Java setup in Visual Studio Code that is ready for small programs big projects and inevitable bugs.
Now go write something that compiles. If it does not compile come back here and read the troubleshooting section while making a strong cup of coffee.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.