-1

I want to see the list of all jdk versions available in my system. However, when I type in java and javac version to the cmd line, it gives me only jdk 20 version. How can I do an implementation to see other jdk versions as well in the list?

C:\Users\USER>java --version
java 20 2023-03-21
Java(TM) SE Runtime Environment (build 20+36-2344)
Java HotSpot(TM) 64-Bit Server VM (build 20+36-2344, mixed mode, sharing)

C:\Users\USER>javac --version
javac 20

C:\Users\USER>

I just typed java --version and javac --version commands to see jdk versions exist in my computer. Due to my assignment, I need jdk8 version. How can solve the problem in order to see the version I need?

6
  • Use the full path to your java installation, so something like C:\Program Files\jdk8\bin\java --version or whatever the correct path is where you installed java 8 Commented Oct 20, 2023 at 6:35
  • 1
    Due to my assignment, I need jdk8 version Set your JAVA_HOME to point to Jdk 8. Commented Oct 20, 2023 at 6:36
  • Not only the JAVA_HOME but also the PATH. Commented Oct 20, 2023 at 6:40
  • 1
    @PradeepSimha that doesn't help if you're running java from the command line. It will still run what's in the PATH Commented Oct 20, 2023 at 6:40
  • 2
    This is standard Operation System problem, more precisely from the used Command Line program. Usually (most versions) the system search the executables, if not using absolute path, in the directories given in the PATH environment variable. The first found executable will be executed. java --version or javac --version does not show all existing installations, it only shows the version being executed. (JAVA_HOME is not used by Java itself, some external tools use it instead of relying on the PATH) Commented Oct 20, 2023 at 6:51

1 Answer 1

2

You're going to have big headaches if you try to handle multiple java versions manually. The best option is to delegate this to a third party tool, quite some already exists to overcome the issue. The best one and recommended by several frameworks (https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#getting-started.installing.cli.sdkman) is sdkman:

https://sdkman.io/

Follow windows installation: https://sdkman.io/install#:~:text=Windows%20installation

Then do:

sdk list java

You will see something like:

================================================================================
 Vendor        | Use | Version      | Dist    | Status     | Identifier
--------------------------------------------------------------------------------
 Corretto      |     | 21           | amzn    |            | 21-amzn             
               |     | 21.0.1       | amzn    |            | 21.0.1-amzn         
               |     | 20.0.2       | amzn    |            | 20.0.2-amzn         
               |     | 20.0.1       | amzn    |            | 20.0.1-amzn         
               |     | 17.0.9       | amzn    |            | 17.0.9-amzn         
               |     | 17.0.8       | amzn    |            | 17.0.8-amzn         
               | >>> | 17.0.7       | amzn    | installed  | 17.0.7-amzn         
               |     | 11.0.21      | amzn    |            | 11.0.21-amzn        
               |     | 11.0.20      | amzn    |            | 11.0.20-amzn        
               |     | 11.0.19      | amzn    |            | 11.0.19-amzn        
               |     | 11.0.18      | amzn    | local only | 11.0.18-amzn        
               |     | 8.0.392      | amzn    |            | 8.0.392-amzn        
               |     | 8.0.382      | amzn    |            | 8.0.382-amzn        
               |     | 8.0.372      | amzn    | installed  | 8.0.372-amzn        

Install what you need with:

sdk install java 20.0.2-amzn

Then switch among versions with:

sdk use java 20.0.2-amzn
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.