Java check jar java version

Java check jar java 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.

Читайте также:  Css increase all font sizes

Read more about the article JDK 14: New hot Features

JDK 14: New hot Features

Read more about the article How to do technical Audit for a software development project

May 16, 2020

Источник

How to check the java compiler version from a java class file?

This tutorial provides a great way to find Java compiler version for a class file generated. It is one of the common problem among Java developers to know the exact version in which the JAR file is created. If you receive a JAR file, can you find what is the target compiler version for that JAR file to be deployed?. If developer not aware of the details, it is difficult for them to test the compatibility issues. If the run the code with different version, runtime exception will be thrown. Before start reading this article, If you want to understand the basics of Java compiler and JVM architecture, please go through the articles Java Compiler API, JVM, JRE and JDK difference and JVM.

java.lang.UnsupportedClassVersionError: test class : Unsupported major.minor version 51.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(Unknown Source)

Without knowing the Java version in which the JAR is created is difficult for the developers. There is no way to check the version in the JAR file itself. We can check the version details only using the class files inside the JAR file. Unzip the JAR and take out any one class file to be verified.

  • JDK 1.0 — major version 45 and minor version 3
  • DK 1.1 — major version 45 and minor version 3
  • JDK 1.2 — major version 46 and minor version 0
  • JDK 1.3 — major version 47 and minor version 0
  • JDK 1.4 — major version 48 and minor version 0
  • JDK 1.5 — major version 49 and minor version 0
  • JDK 1.6 — major version 50 and minor version 0
  • JDK 1.7 — major version 51 and minor version 0

These version could be different for each implementation of the compiler. The above details are specific to Oracle/Sun JDK. JDK has javap command to find the version details.

You will find the following details displayed on the screen.

javap

javapThere is simple program which can get you the Java version details. Run the below program by passing the class file name as the arguments, this would return you the major version details.

package com; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; public class GetVersion < public static void main(String[] args) throws IOException < System.out.println(getVersionDetails(args[0])); >public static String getVersionDetails(String filename) throws IOException < String version = ""; DataInputStream stream = new DataInputStream(new FileInputStream(filename)); int magicBytes = stream.readInt(); if (magicBytes != 0xcafebabe) < System.out.println(filename + " is not a valid java file!"); >else < int minorVersion = stream.readUnsignedShort(); int majorVersion = stream.readUnsignedShort(); version = majorVersion + "." + minorVersion; >stream.close(); return version; > >

javap command returns the complete details of the bytecode. In that there is major version and minor version which is for identifying the Java version details. I hope this tutorial have provided nice tip on finding the version details for the Java class. If you have any more tips, please contact us, we will publish it in our website.

Reference Books:

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Источник

How to Determine Java Version

This article was co-authored by Yaffet Meshesha. Yaffet Meshesha is a Computer Specialist and the Founder of Techy, a full-service computer pickup, repair, and delivery service. With over eight years of experience, Yaffet specializes in computer repairs and technical support. Techy has been featured on TechCrunch and Time.

This article has been viewed 392,663 times.

Multiple copies of Java can be installed on a single computer, and, if you have more than one browser, every one of them could be using a different version or none at all. You can determine your Java version by verifying it on the Java website, or you could check using the Windows command prompt, Mac terminal, or Linux terminal.

Verifying Online

Image titled Determine Java

Open a new window in your web navigate to Java’s website. Oracle, the makers of Java, have provided an easy page that will check your Java installation and report the exact version you’re running. This can be done from any operating system.

Image titled Determine Java

Image titled Determine Java

Image titled Determine Java

After a few seconds, check the results! This will include the Version number as well as the Update number. The version number is most important if you’re checking for compatibility with other programs.

Windows

Image titled Run window empty.png

Image titled Run window with cmd.png

Image titled Windows cmd blank.png

Wait for a black window with white text to appear on your screen. This is called a «console window.»

Image titled Windows cmd java version command small.png

Image titled Windows cmd java version command output small.png

    You can tell what version of Java you have by looking at the number after the «1.» in the first line of the console output. In this example, the user has Java 8 installed.

Image titled Windows cmd java version command output version highlighted.png

Image titled Determine Java

Mac OSX

Image titled Determine Java

Image titled Determine Java

Image titled Determine Java

With Utilities open, open the Terminal and type in «java -version», then retrieve the current java version.

Linux

Image titled Determine Java

  • This should return something like Java(TM) 2 Runtime Environment, Standard Edition (build 1.6) If it returns
    -bash: java: command not found
    This means that either it is not installed or you haven’t set up your paths properly

Image titled Determine Java

  • With Firefox 3 go to Tools Add-ons button and go to the Plug-ins tab.
  • With Firefox 2 or 3: In Firefox versions 2 and 3, enter in the address bar: about:plugins. If Java is installed there will be multiple Java entries.
  • With Internet Explorer 7 or 8 go to Tools select Internet Options in the General tab click on the Browsing History Settings button and select the View Objects button right click on an ActiveX control and get its properties. Each ActiveX control has a «code base» and for each of the Java entries it will display the version number.

Expert Q&A

You Might Also Like

Add JARs to Project Build Paths in Eclipse (Java)

Set Java Home

How to Set JAVA_HOME for JDK & JRE: A Step-by-Step Guide

Check Your Java Version in the Windows Command Line

Use Easy Windows CMD Commands to Check Your Java Version

Do Division in Java

How to Do Division in Java (Integer and Floating Point)

Compile & Run Java Program Using Command Prompt

Compile and Run Java Program by Notepad

How to Compile and Run Java Programs Using Notepad++

Источник

Как проверить версию Java

Проверьте версию Java, Проверьте версию java терминал mac, Как проверить версию java в программе, Класс версии Java 10, Сборка версии Java, Как проверить версию java, java-версия, пример java-версии.

Иногда нам нужно проверить версию Java во время выполнения программы Java. Мы могли бы разрабатывать наш проект на локальной машине, но развертывать его на удаленном сервере, поэтому нам нужно проверить версию java, чтобы убедиться, что наша программа будет работать нормально.

Как проверить версию Java?

Мы можем легко проверить версию java с помощью командной строки. Мы можем использовать любую из следующих команд для печати версии java.

$java -version $java --version

java -версия выведет версию в поток ошибок и завершит работу.

java —version выведет свою версию в поток вывода и завершит работу.

Обратите внимание, что каталог JDK или JRE bin должен находиться в переменной PATH, иначе вы получите сообщение об ошибке, так как команда java не найдена .

У меня на MacBook установлены Java 8 , Java 9 и Java 10, поэтому давайте посмотрим, каков результат выполнения команды проверки версии java.

Вывод Java Версии 10

$ 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) $

Обратите внимание , что версия имеет форму $FEATURE.$INTERIM.$UPDATE.$PATCH , поэтому из приведенных выше выходных данных мы можем сделать вывод, что функция равна 10, Промежуточная-0, Обновление равно 1, а исправление равно 0.

Во второй строке то, что вы видите после+, называется номером сборки. Таким образом, сборка составляет 10. Обратите внимание, что это соглашение об именовании появилось в самой Java 10. Так что в старых версиях Java все будет немного по-другому.

Вывод Java Версии 9

$ java -version java version "9" Java(TM) SE Runtime Environment (build 9+181) Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode) $

Вывод Java Версии 8

$ cd /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/bin/ $ ./java -version java version "1.8.0_131" Java(TM) SE Runtime Environment (build 1.8.0_131-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode) $

Вывод Java версии 11

$ java -version openjdk version "11.0.1" 2018-10-16 OpenJDK Runtime Environment 18.9 (build 11.0.1+13) OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode) $

Можем ли мы проверить версию java программно?

Что делать, если мы хотим убедиться, что наш код работает на совместимой версии java, и, возможно, выйти из приложения, если это не так. Мы также можем проверить версию java в программе. Ниже приведены фрагменты кода, в которых показано, как программно проверить версию java.

Код проверки версии Java для Java 10

Version version = java.lang.Runtime.version(); System.out.println("Java Version = "+version); System.out.println("Java Version Feature Element = "+version.feature()); System.out.println("Java Version Interim Element = "+version.interim()); System.out.println("Java Patch Element Version = "+version.patch()); System.out.println("Java Update Element Version = "+version.update()); System.out.println("Java Version Build = "+version.build().get()); System.out.println("Java Pre-Release Info = "+version.pre().orElse("NA"));
Java Version = 10.0.1+10 Java Version Feature Element = 10 Java Version Interim Element = 0 Java Patch Element Version = 0 Java Update Element Version = 1 Java Version Build = 10 Java Pre-Release Info = NA

Обратите внимание, что вывод программы совпадает с выводом команды java-версия .

Код проверки версии Java для Java 9

Version version = java.lang.Runtime.version(); System.out.println("Java Version = "+version); System.out.println("Java Major Version = "+version.major()); System.out.println("Java Minor Version = "+version.minor()); System.out.println("Java Security Version = "+version.security()); System.out.println("Java Version Build = "+version.build().get()); System.out.println("Java Version Pre-Release Info = "+version.pre().orElse("NA"));

Версия класс был впервые представлен в Java 9, в версии java 10 основные, второстепенные и свойства безопасности были устаревшими. Если мы выполним приведенный выше фрагмент кода для Java 9, мы получим следующий вывод:

$ java JavaVersion Java Version = 9+181 Java Major Version = 9 Java Minor Version = 0 Java Security Version = 0 Java Version Build = 181 Java Version Pre-Release Info = NA

Версия Java Проверьте код для версий Java 8 или ниже

Для Java 8 или ниже мы можем использовать свойства системы, чтобы получить подробную информацию о версии Java.

System.out.println(System.getProperty("java.version")); System.out.println(System.getProperty("java.specification.version"));

Источник

Оцените статью