- Check java oracle version
- How to switch Java version
- Java version history
- JDK 14: New hot Features
- Smart way of Technology
- Worked in Database technology for fixed the issues faced in daily activities in Oracle, MS SQL Server, MySQL, MariaDB etc.
- Check Java version used in Oracle Database
- Check Java version used in Oracle Database
- Bash Command to Check if Oracle or OpenJDK Is Installed
- 1. Overview
- 2. Introduction to the Problem
- 3. Standard Output and Standard Error
- 4. Using the grep Command with the -q Option
- 5. Conclusion
Check java oracle version
You can find the Java installation path on Ubuntu using following command:
It will give path of Java installation directory, if you have multiple versions installed, then only the default Java version (set in your system) wll be displayed.
You can find the Java installation path on Ubuntu using following command:
It will give you Java installation path
How to switch Java version
You can have multiple installed versions of JDK on one machine. At any time, You can decide which Java version you want to make default version and should be used from command line automatically. The update-alternatives command is very helpful in switching between JDk versions, it will list all the installed Java versions. From that list, you can select which is the default version, you can want to keep.
sudo update-alternatives --config java
All available Java versions will be listed as shown below, with a sequence number. You can select any Java version using these sequence numbers. An Asterisk (*) mark shows that this Java version is currently being used as default version.
There are n choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode * 1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode 2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode 3 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 manual mode Press to keep current choice[*], or type selection number:
Java version history
The Java language has undergone several changes since JDK 1.0 also as numerous additions of classes and packages to the core library. The evolution of Java language has been governed by the JCP (Java Community Process), which uses JSRs (Java Specification Requests) to specify changes and propose changes, for additions to the Java.
In addition to the language semantics, lots of other changes have been made to the Class Libraries over the years, which has now grown from a couple of hundred classes to over three thousand. Entire new APIs, like Swing and Java2D, are introduced, and lots of of the first JDK 1.0 classes and methods are deprecated.
JDK 14: New hot Features
May 16, 2020
Smart way of Technology
Worked in Database technology for fixed the issues faced in daily activities in Oracle, MS SQL Server, MySQL, MariaDB etc.
Check Java version used in Oracle Database
Check Java version used in Oracle Database
Check the java JDK version present in Oracle Setup
Go to the Oracle Home directory then java & bin folder and run the following command to check.
E:\oracle\12.1.0\dbhome_1\jdk\bin>java -version
java version «1.6.0_75»
Java(TM) SE Runtime Environment (build 1.6.0_75-b13)
Java HotSpot(TM) 64-Bit Server VM (build 20.75-b01, mixed mode)
Check JDK Version from SQL
SQL> SELECT dbms_java.get_jdk_version JDK_Version FROM dual;
Check Oracle JAVA version from PLSQL code if you don’t have access to direct server
— Create the jave property function
create function get_java_property(prop in varchar2)
return varchar2 is
language java name ‘java.lang.System.getProperty(java.lang.String) return java.lang.String’;
/
— Select the query
select get_java_property(‘java.version’) from dual;
Error In express edition we did not have java installed. you get following error:
SQL> select get_java_property(‘java.version’) from dual;
select get_java_property(‘java.version’) from dual
*
ERROR at line 1:
ORA-29538: Java not installed
Check the Operating system Oracle
E:\>java -version
java version «10.0.1» 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
Following version Support the JVM present with Oracle Software
Released Database | Java Version |
---|---|
Oracle 18.1 | JVM support 1.8 version |
Oracle 12.2 | JVM support 1.8 version |
Oracle 12c | JVM Support 1.6 and 1.7 both version |
Oracle 11.2.0.4 | JVM supports JDK 1.6 |
Oracle 11g | JVM supports JRE 1.5 |
Oracle 10g | JVM supports JRE 1.4 |
Oracle 9i | JVM supports JRE 1.3 |
Bash Command to Check if Oracle or OpenJDK Is Installed
The Kubernetes ecosystem is huge and quite complex, so it’s easy to forget about costs when trying out all of the exciting tools.
To avoid overspending on your Kubernetes cluster, definitely have a look at the free K8s cost monitoring tool from the automation platform CAST AI. You can view your costs in real time, allocate them, calculate burn rates for projects, spot anomalies or spikes, and get insightful reports you can share with your team.
Connect your cluster and start monitoring your K8s costs right away:
1. Overview
OpenJDK and Oracle JDK are two widely used Java environments in the industry. Both of them are performant and stable. However, they have some differences.
Therefore, sometimes, we may want to quickly get the answer to the question: “Which JDK is running on this machine?”
In this tutorial, we’ll address how to check if the current Java environment is Oracle JDK or OpenJDK.
2. Introduction to the Problem
As we’ve known, the command “java -version” will print the detailed Java version information. So, for example, if we run it on a machine with Oracle JDK installed:
$ java -version java version "15.0.2" 2021-01-19 Java(TM) SE Runtime Environment (build 15.0.2+7-27) Java HotSpot(TM) 64-Bit Server VM (build 15.0.2+7-27, mixed mode, sharing)
The OpenJDK supports the same command, too:
$ java -version openjdk version "17.0.3" 2022-04-19 OpenJDK Runtime Environment (build 17.0.3+3) OpenJDK 64-Bit Server VM (build 17.0.3+3, mixed mode)
Of course, there are other JDK implementations. We can extend the solution to adapt to other JDK vendors. However, for simplicity, we’ll only check if the current JDK is OpenJDK in this tutorial.
Next, let’s see how to get the JDK provider information quickly in the Linux command line.
3. Standard Output and Standard Error
As soon as we see the two outputs of “java -version“, an idea may come up already: grep “OpenJDK” in the output of java -version.
The idea is straightforward. Let’s do a quick test with the OpenJDK:
$ java -version | grep -c 'OpenJDK' openjdk version "17.0.3" 2022-04-19 OpenJDK Runtime Environment (build 17.0.3+3) OpenJDK 64-Bit Server VM (build 17.0.3+3, mixed mode) 0
As we can see in the command above, we’ve passed the option -c (printing the count of matching lines only) to the grep command. However, the output contains the original “java -version” output.
Further, the “0” at the end of the output means we don’t find any line matching the pattern “OpenJDK”. This is obviously not true. Why is that happening?
This is because the command java -version writes the version information to the standard error (stderr) instead of the standard output (stdout). However, the following pipe (|) reads only the stdout of the java command and then feeds the grep command as the stdin.
Therefore, to make our idea work, we need to redirect the java command’s stderr to stdout:
$ java -version 2>&1 | grep -c 'OpenJDK' 2
This time, as the output above shows, we’ve got the expected result: 2.
Then, we can certainly write if statements to check if the output is greater than 0 to decide if the current JDK is OpenJDK.
However, let’s see a simpler approach to doing this check.
4. Using the grep Command with the -q Option
When we pass the -q option to the grep command, grep will output nothing. But, if the given pattern is not matched, the grep command exits with code 1. Otherwise, it returns with the exit code 0:
$ echo "Kotlin is amazing!" | grep -q 'Java' $ echo $? 1 $ echo "Java is amazing!" | grep -q 'Java' $ echo $? 0
We can make use of the exit code and conditionally concatenate multiple commands using the && and the || operators.
Let’s understand the operators through a quick example:
In the example above, CMD1 gets executed first. Only if it succeeds (exit code = 0 ) will CMD2 start. Otherwise, CMD3 will be executed.
Therefore, we can build a command to check whether the JDK provider is OpenJDK or not:
java -version 2>&1 | grep -q "OpenJDK" && echo "It is OpenJDK." || echo "It is NOT OpenJDK."
Now, let’s test our solution on different Java environments and see if it works as expected. First, let’s run it against an OpenJDK installation:
$ java -version openjdk version "17.0.3" 2022-04-19 OpenJDK Runtime Environment (build 17.0.3+3) OpenJDK 64-Bit Server VM (build 17.0.3+3, mixed mode) $ java -version 2>&1 | grep -q "OpenJDK" && echo "It is OpenJDK." || echo "It is NOT OpenJDK." It is OpenJDK.
As we can see, it detects OpenJDK correctly. Next, let’s test it with the Oracle JDK:
$ java -version java version "15.0.2" 2021-01-19 Java(TM) SE Runtime Environment (build 15.0.2+7-27) Java HotSpot(TM) 64-Bit Server VM (build 15.0.2+7-27, mixed mode, sharing) $ java -version 2>&1 | grep -q "OpenJDK" && echo "It is OpenJDK." || echo "It is not OpenJDK." It is not OpenJDK.
The output shows the command works for this case, too.
If we use this command often, typing the long command isn’t convenient. We can create an alias in the .bashrc file:
alias chkJDK='java -version 2>&1 | grep -q "OpenJDK" && echo "It is OpenJDK." || echo "It is not OpenJDK."'
In this way, when we want to check the provider of the current JDK, we can simply launch the chkJDK alias.
5. Conclusion
In this article, we’ve learned how to check if the current JDK is OpenJDK or Oracle JDK through examples.
We’ve addressed that combining grep -q and the && and || operators sometimes can solve this kind of problem simply.