Working with Multiple Java Versions on Linux

Working with Multiple Java Versions on Linux
Working with Multiple Java Versions on Linux

Java is one of the earliest Object-Oriented programming languages, which was developed by James Gosling in the early 1990s.

The development team initiated the development of Java as there was a dire need for a language to manipulate the working of digital devices such as television sets, set-top boxes, etc. Furthermore, it was highly compatible with internet programming. Eventually, the Java technology was incorporated by Netscape.

The development team originally considered availing of C++ but the idea was dropped because of several limitations of the language, foremost C++ required a lot of supplementary memory in comparison to Java. James Gosling worked on C++ and tried to modify it, but before long he surrendered that for making another stage known as Green. This team referred to the project as “Green talk” and the codes written were saved as files with extension .gt. Gradually, “Greentalk” became popular as “OAK”.

Timeline of Java programming language

  • The Programming Language development project was initiated by James Gosling, Mike Sheridan, and Patrick Naughton in June 1991. This team consisting of a few Sun Engineers was known as The Green Team.
  • Initially, it was designed for concise, embedded systems in electronic appliances such as the set-top boxes or digital thermometers, at that time it was called “Greentalk” by James Gosling, and its file extension was .gt.
  • Later, it was known as Oak and the development process still continued under the name of the Green Project.
  • According to various thesis, the project was named Oak, after an oak tree that remained outside Gosling’s office. As it symbolises strength and solidarity; and is proudly recognised as the national tree of various countries like the United States of America, Germany, Roumania, France, etc. Later, in 1995 it had to be renamed as “Java” since Oak was already announced as the trademark of Oak Technologies.
  • The Green team assembled for deciding on a new name for their programming language. Various names were put forward by the Green Team members like “revolutionary”, “dynamic”, “DNA”, “Silk”, “jolt”, “Ruby”, etc.
  • Finally, post a lot of discussion and arguments Java name was finalised because of its uniqueness. The word originates from a kind of sort of espresso bean, called Java. Suddenly, Gosling got this idea while he was drinking coffee in his office.
  • There was a dilemma between “Java” and “Silk”. But, it was most-suited as the developers wanted a name that symbolises the essence of the technology: revolutionary, distinct, dynamic, lively, cool, fun to pronounce, and easy to spell.
  • It is currently a subsidiary of Oracle Corporation, although it was initially developed by James Gosling at Sun Microsystems and was released in the year 1995.

Java Version History

JDK 1.0 was released on January 23, 1996. Over the last two decades, multiple features have been added to Java. Currently, it is widely being employed in Windows applications, enterprise applications, mobile applications, e-cards, Web applications, etc. Every new version of it comes with a set of numerous new features and the current stable release of Java is Java SE 12.

  • JDK Alpha and Beta (1995)
  • JDK 1.0 (23rd Jan 1996)
  • JDK 1.1 (19th Feb 1997)
  • J2SE 1.2 (8th Dec 1998)
  • J2SE 1.3 (8th May 2000)
  • J2SE 1.4 (6th Feb 2002)
  • J2SE 5.0 (30th Sep 2004)
  • Java SE 6 (11th Dec 2006)
  • Java SE 7 (28th July 2011)
  •  Java SE 8 (18th Mar 2014)
  •  Java SE 9 (21st Sep 2017)
  •  Java SE 10 (20th Mar 2018)
  •  Java SE 11 (25th Sep 2018)
  •  Java SE 12 (19th Mar 2019)

The Java SE 12 comes with the following additional features:

  • Shenandoah: A Low-Pause-Time Garbage Collector
  • Micro benchmark Suite
  • Switch Expressions
  • Java Virtual Machine Constants API
  • One AArch64 Port, instead of two
  • Default CDS Archives

From the initial stage only, Java was driven by some of the non-negotiable key principles, such as, “Simple, Secured, High Performance, Portable, Platform-independent, Multithreaded, Robust, Architecturally Neutral, Interpreted, Object-Oriented, and Dynamic”, because of this with was recognised as one of the Ten Best Products of 1995 by the TIME MAGAZINE.

Nowadays, Java is being used in mobile devices, virtual-reality based games, e-business solutions, internet programming, and so on. Apart, from the notable change in augmentations of classes and packages to the standard library from JDK 1.0 till now, it has extended its classes from a few hundred to more than three thousand in J2SE 5.

Although, the updates are pre-announced and well documented, yet it becomes quite challenging for the user to work with different versions of it simultaneously, specifically on a Linux Machine. Read below, to get hands-on knowledge about working with multiple versions of it on Linux.

How to install and run multiple Java versions on Linux/Mac Operating System?

The traditional way is to install multiple it versions and configure different it versions manually. But, there are few limitations of this approach; you need to modify your environment variables, each time you have to switch your it version. To overcome this shortcoming, we have another convenient method, which is to use the SDKMAN.

SDKMAN stands for Software Development Kit Manager; it is used for managing parallel versions of multiple Software Development Kits on the commonly used Unix based operating systems. Using SDKMAN users can switch, install, remove, and list candidate versions of various SDKs including it. For example – JDK, Ant, Gradle, Scala, Dotty and so on.

The steps required for managing multiple it versions on your UNIX-based machine using SDKMAN are given below. This series of operations are applicable to the commonly used UNIX-based operating systems, such as macOS, any of the Linux-based operating systems including, Ubuntu, Debian, MINT, Manjaro, FreeBSD, Solaris, OpenSUSE and Cygwin.

There are Five major steps for setting up SDKMAN on your Linux system:

  • Install SDKMAN in the target system.
  • List the entire candidate JDKs using SDKMAN.
  • Install multiple candidate JDKs on the target system using SDKMAN.
  • Switching between candidate JDKs using SDKMAN.
  • Removing/Uninstalling JDK from the target system using SDKMAN.
Image Source: DZone

Step One: Install SDKMAN in the target system


Open a new terminal window on your Linux machine and enter the following command:
curl -s “https://get.sdkman.io” | bash

Now, for installing the SDKMAN, copy and paste the following command just below the previous command:

source “$HOME/.sdkman/bin/sdkman-init.sh”
Post-this SDKMAN will be successfully installed on the target machine.

For checking the version of SDKMAN installed, run the following command in the terminal window:

sdk version

 Step two : List the entire candidate JDKs using SDKMAN

Run the following command offered by SDKMAN for viewing all the available Java versions installed in your Linux machine:

sdk list java

After the successful execution, it will display all the installed JDKs from distinct vendors with their supported versions.

Image Source: towards data science

Step Three: Install multiple candidate JDKs on the target system using SDKMAN.
First
, install a specific JDK, for example, JDK 15 Liberica from BellSoft.

sdk install java 15.0.0-librca
Installing: java 15.0.0-librca
Done installing!
Do you want java 15.0.0-librca to be set as default? (Y/n):

If you want to verify the installed version, run the command given below:

java -version
openjdk version “15” 2020-09-15
OpenJDK Runtime Environment (build 15+36)
OpenJDK 64-Bit Server VM (build 15+36, mixed mode, sharing)

After this, you can install any another JDK, such as, JDK 8 Liberica from BellSoft by running the following commands:

sdk install java 8.0.265-librca
Installing: java 8.0.265-librca
Done installing!
Do you want java 15.0.0-librca to be set as default? (Y/n):

Every time you install a new version, you will be asked that you want to set it as the default version or not, respond with a “Y” to the terminal in case of a yes, otherwise “n”.

Step Four: Switching between candidate JDKs using SDKMAN

If you run the list command, all the JDKs with their vendor name and version names with be listed in a tabular form:

sdk list java

You can easily switch between the SDKs by running the SDKMAN commands given below:

sdk use java 8.0.265-librca
Using java version 8.0.265-librca in this shell.

For checking the specific installed version, run the following command:

jdk -version
openjdk version “1.8.0_265”
OpenJDK Runtime Environment (build 1.8.0_265-b01)
OpenJDK 64-Bit Server VM (build 25.265-b01, mixed mode)

Step Five: Removing/Uninstalling JDK from the target system using SDKMAN

For uninstalling a JDK use the following command with the version number and vendor name:

sdk uninstall java 15.0.0-librca

Uninstalling java 15.0.0-librca…

  1. Bottom of Form

In this article, we have very distinctly mentioned the LINUX based commands required for installing and managing Multiple Java version using SDKMAN. Although, when it comes to Node.js versions you need to use NVM for managing instead of SDKMAN, its user-interface is analogous to SDKMAN in terms of structure and readability.

The utility of SDKMAN is not limited to Java versions only, it can also be used for dealing with other JVM tools such as Spark, Kotlin, Ceylon, Ant, Spring Boot, Maven, Gradle, Groovy, Scala, Grails, SBT, Vert. x, and so on. If you frequently work with it and Java Virtual Machine, you must definitely install SDKMAN on your target machine. It is highly recommended for checking software versions for compatibility and upgrade efficiency. It also makes it quite easy to learn about the libraries associated with multiple Java and other JVM based SDK versions.

To explore more about Java, visit our blog section.

By Vanshika Singolia