Keeping up with the Java seasons

I'm a java developer. Its fun to code and life is too short to write boilerplate code. !
Search for a command to run...

I'm a java developer. Its fun to code and life is too short to write boilerplate code. !
No comments yet. Be the first to comment.
If you are looking for a quick and easy way to find the cheapest flight between 2 dates, you might want to try Bing chat, the new AI-powered chat mode of Microsoft Bing that can help you quickly get summarized answers and creative inspiration. (N.B T...

A breath of fresh air When creating an integration test you want the test to be as close as possible to the environment where you will eventually want to deploy right ?. One of the components I regularly need for an integration test is a database. ...

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.
To see available java versions to install enter the following :
sdk list java
A list of java candidates will then be displayed ..

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.
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
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.