java.home specifies the folder path to the JDK, which should be like /usr/java/jdk16.
Despite manually pointing to the path, we can click it from GUI. Open Command Palette and choose Java: Configure Java Runtime. Below the option Java Tooling Runtime, the value of JDK for Language Server is equal to java.home.

If there's no optional path there, check if you've added java to PATH.
Reference: Installation of JDK on Linux Platforms. and Using Java runtime configuration wizard.
Answer from Molly Wang-MSFT on Stack Overflowjava.home specifies the folder path to the JDK, which should be like /usr/java/jdk16.
Despite manually pointing to the path, we can click it from GUI. Open Command Palette and choose Java: Configure Java Runtime. Below the option Java Tooling Runtime, the value of JDK for Language Server is equal to java.home.

If there's no optional path there, check if you've added java to PATH.
Reference: Installation of JDK on Linux Platforms. and Using Java runtime configuration wizard.
Install the required Java version.
Check what is under /usr/lib/jvm/
$ ls /usr/lib/jvm/
default-java java-1.17.0-openjdk-amd64 java-17-openjdk-amd64 openjdk-17
java-1.11.0-openjdk-amd64 java-11-openjdk-amd64 openjdk-11
Then check in VSCode this settings file:
/home/user/.vscode-server/data/Machine/settings.json
{
"editor.bracketPairColorization.enabled": true,
"java.jdt.ls.java.home": "/usr/lib/jvm/default-java",
"java.configuration.runtimes": [
]
}
Change to your JVM version:
{
"editor.bracketPairColorization.enabled": true,
"java.jdt.ls.java.home": "/usr/lib/jvm/java-1.17.0-openjdk-amd64",
"java.configuration.runtimes": [
]
}
Reload VSCode.
There are explicit details on the steps required for this in How do I configure the version of Java that the Apex Language Server uses?
By default, VS Code attempts to locate your local Java installation by looking for a
JAVA_HOMEorJDK_HOMEenvironment variable on your computer. If VS Code cannot find your Java installation, or if you want it to use a different installation, change thesalesforcedx-vscode-apex.java.homesetting.

Note that while the message specifies the JRE the prerequisites are currently for the JDK.
{
"salesforcedx-vscode-apex.java.home":
"/Program Files/Java/jdk1.8.0_121"
}
Upon restarting code.exe wanted network access past the firewall.
The output window for the Apex Language Server also showed messages indicating it was running now.

Not sure but you need java 8 specifically. Doesn't seem to work with Java 11.
I ran into the problem and found that the required version is mentioned in these issues and comments on GitHub.
https://github.com/forcedotcom/salesforcedx-vscode/issues/100
https://github.com/forcedotcom/salesforcedx-vscode/issues/930
java.configuration.runtimes in settings.json are ignored
java : runtime not compatible with 'javaSE-16' environment
I try to "Configure Java Runtime", but it's blank page
visual studio code - VSCode can't change Java Version in "Configure Java Runtime" - Stack Overflow
Videos
hey, i installed oracle java - 16 cuz my os (arch) came preinstalled openjdk and i could read the developer code (like implementation of Hashmap class), but now i get this error when ever i start vscode -
Invalid runtime for JavaSE-16: Runtime at '/usr/lib/jvm/java-16-jdk' is not compatible with the 'JavaSE-16' environment.
I'm quite new to java, so any help is appreciated.
Thanks
On Mac and VSCode Version: 1.86.2 I was unable to select an alternative JDK for my Java project. In particular I wanted to run my Java classes with a specific JDK.
I tried to add the JDK to the settings.json file ( with both a "java.jdt.ls.java.home" entry and a entry with "java.configuration.runtimes" but VSCode always run the wrong JDK. Even if setting proper JAVA_HOME before starting VSCode did not help.
Eventually I modified the launch.json file by adding a javaexec entry and then I could control what JDK to use! Below I pinpoint my JDK 21 installed using homebrew;
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "MyJavaClass",
"javaExec": "/usr/local/Cellar/openjdk/21.0.1/libexec/openjdk.jdk/Contents/Home/bin/java",
"request": "launch",
"mainClass": "se.myorg.MyJavaClass",
"projectName": "myproject"
}]
}
If you follow this link you should find some helpful information. VSC supports Java versions 1.5 and above
If I could give my two cents however, there are many IDEs that are much more intuitive and have built-in Java support where VSC does not. IDEs like IntelliJ or Eclipse are your best options for debugging, maven, library support, etc. (IntelliJ is my personal favourite).
I'm trying to learn how to code in Java, so I downloaded vs code for the first time today and the Java coding packet from the website, and when I tried to open a Java project it asked me to download a JDK. Also, I checked in the CMD and it says Java isn't recognised.
I tried downloading the Java pact several times already, the same problem happens.
PLS HELP
Change from
"java.home": "/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home"
to
"java.home": "/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home"
and keep the rest of the settings as is.
For future readers. If you are using the extension "Spring Boot Tools" you may get a similar error to this. I had my JAVA_HOME set to java 8 but required java 11 to use the Spring Boot Tools Language Server. It seems that Spring Boot Tools uses whatever your JAVA_HOME environment variable is or in the PATH environment variable, Spring Project Issue. To override your JAVA_HOME variable you'll need to modify the spring-boot.ls.java.home setting.
- Open Visual Studio Code
CRTL + ,to open the settings- Search
spring-boot.ls.java.home - Select 'Edit in settings.json'
- Your Java 11 installation →
"spring-boot.ls.java.home": "C:\\Program Files\\Java\\jdk-11.0.10" - Save and restart VS Code
Prereq: Have a Java 11 installation
Getting this error message when I am trying to set my default jdk. Not sure what the issue is.
** Invalid runtime for JavaSE-21: Runtime at 'C:\Program Files\Java\jdk-21' is not compatible with the 'JavaSE-21' environment. **
Heres my json settings for reference:
{
"workbench.colorTheme": "Tomorrow Night Blue",
"redhat.telemetry.enabled": true,
"java.configuration.runtimes": [
{
"name": "JavaSE-21",
"path":"C:\\Program Files\\Java\\jdk-21",
"default": true
},
],
"java.jdt.ls.java.home":"C:\\Program Files\\Java\\jdk-21",
}