I want to try the new features
New versions of java are released almost as quickly as the seasons change these days. If your like me you might be working for clients who use different versions. For me my office uses java 17, my client uses Java 8 of all things and at my previous client they used Java 11.
So its important I can switch between versions easily. Do a search on how to switch java versions and you will come across various options available . Theres homebrew, chocolatey, scoop and my favourite SDKMAN.
SDKMAN will allow you to
Install multiple java versions
Set a default java version
Set a default java version for a project(directory)
If your using linux or a mac user sdkman can be installed in the command line with ..
$ curl -s "https://get.sdkman.io" | bash
If your on windows try executing the same command in a WSL shell.
List Java versions
To see available java versions to install enter the following :
sdk list java
A list of java candidates will then be displayed ..
Install a version
Identify the text of the identifier of the version to install :
sdk install java 19-amzn
The sdk will be downloaded and you will be prompted if you want this version to be the default.
You can the install other versions using the same method.
Set the default version
The default java version (eg java 19) can be set by issuing the following command...
sdk default java 19-amzn
To change to another installed version (eg java 11) execute the command...
sdk use java 11.0.16-amzn
Setting a java version for a project/directory
Being able to set the java versions in a directory /project really is cool. First edit the file $HOME/.sdkman/etc/config and set the variable sdkman_auto_env to true. eg...
Now go to the directory where you want to set the java version and type
sdk env init. A file will then be created with the name .sdkmanrc. In this file there will now be a line with a key value pair for java. eg
java=8.0.342-amzn. To the right of the java = you set the java version you want for this directory
The next time you visit this directory the java version will be set to this version. If you exit the directory the java version reverts to your normal default java version.