0

I'm on Fedora 36 and installed java-latest-openjdk-devel (OJDK19) from Fedora repositories.

I wrote a simple print hello world and named it test_for_error as follows

public class test_for_error {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

then i tried to compile and run using javac & java commands

➤ javac test_for_error.java 

➤ java test_for_error
Error: LinkageError occurred while loading main class test_for_error
    java.lang.UnsupportedClassVersionError: test_for_error has been compiled by a more recent version of the Java Runtime (class file version 63.0), this version of the Java Runtime only recognizes class file versions up to 61.0

I expected to get the hello world as output, but facing the above error.

Where's the problem, and how should I solve it?

Naadiyaar
  • 45
  • 5
  • 1
    You probably have in your system `path` a java command which comes from another distribution then the `javac`. You can check the version of your `java` command with `java -version`. Or you can try to identify precisely what is the `path` of the `java` command and `javac` command. – Pierre Demeestere Nov 15 '22 at 19:56
  • 1
    Check output of `java -version` and `javac -version`. Looks like your JDK is more recent than the (also installed) JRE. `which java` and `which javac` may also provide valuable information. – Christoph Dahlen Nov 15 '22 at 20:01

1 Answers1

1

So as friends mentioned, I checked/compared javac(JDK) & java(JRE) versions and as you see my system was using an older JRE than which I installed and expected to be default

➤ javac -version
javac 19.0.1

➤ java -version
java 17.0.5

then i changed to my preferred version using this command:

sudo update-alternatives --config java

source: https://www.xmodulo.com/change-default-java-version-linux.html

so i tried again and:

➤ java test_for_error
Hello, World!
Naadiyaar
  • 45
  • 5