-2

I just compiled a simple Java program in my Ubuntu Virtual Machine. It runned fine there. When I copied the same ".class" file to Windows (host machine) I got the message below:

"(...)has been compiled by a more recent version of the Java Runtime (class file version 58.0), this version of the Java Runtime only recognizes class file versions up to 52.0"

Is there any way to fix this by implementing changes only my Ubuntu environment?

nel_junior000
  • 45
  • 1
  • 1
  • 3

2 Answers2

2

Each version of the JDK has it's own class version.

A JDK can run files from a previous JDK but not from a future JDK.

58.0 is for JDK version 14.

52.0 is for JDK 8.

Either you can update the JDK on your windows machine

or

You can compile for a specific JDK using the -target command line option.

see

List of Java class file format major version numbers?

and

javac source and target options

BevynQ
  • 8,089
  • 4
  • 25
  • 37
0

Java on your windows is Java8. Java on Ubuntu is greater.

java --version

Gives you the numbers.

You can download a jdk and install it on Windows. Change the JAVA_HOME environment variable to use the new jdk.

Tokazio
  • 516
  • 2
  • 18
  • This doesn't answer the question. The OP specifically asked *"Is there any way to fix this by implementing changes **only my Ubuntu environment**?"* – Stephen C Feb 22 '21 at 03:44