I used the alternatives --config command to select the more recent version of Java that matched my javac or java-devel.
[~]$ sudo alternatives --config java
There are 3 programs which provide 'java'.
Selection Command
-----------------------------------------------
*+ 1 java-17-openjdk.x86_64 (/usr/lib/jvm/java-17-openjdk-17.0.9.0.9-1.fc39.x86_64/bin/java)
2 java-latest-openjdk.x86_64 (/usr/lib/jvm/java-21-openjdk-21.0.1.0.12-1.rolling.fc39.x86_64/bin/java)
3 java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.21.0.9-1.fc39.x86_64/bin/java)
Enter to keep the current selection[+], or type selection number: 2
[~]$ cd javajar/javascripts
[javascripts]$ javac helloworld.java
[javascripts]$ ls
helloworld.class
helloworld.java
[javascripts]$ java helloworld.java
Hello World
Now works...
[javascripts]$ java helloworld
Hello World
[javascripts]$
1. Fedora 39: Linux 6.6.4-200.fc39.x86_64
2. javac version: javac 21.0.1, I vaguely recall downloading a new version while troubleshooting a Selenium issue. I think it was because I installed java-devel with this command:
sudo dnf install java-latest-openjdk-devel
3. java version:
openjdk 17.0.9 2023-10-17
OpenJDK Runtime Environment (Red_Hat-17.0.9.0.9-2) (build 17.0.9+9)
OpenJDK 64-Bit Server VM (Red_Hat-17.0.9.0.9-2) (build 17.0.9+9, mixed mode, sharing)
4. cat helloworld.java
public class helloworld {
public static void main(String[] args) {
System.out.println("Hello Worlld");
}
}
5. javac helloworld.java
6. ls
helloworld.java
helloworld.class
7. So, no helloworld file
8. java helloworld.java
Hello Worlld
9. Should there not also be a helloword file that was created with the javac command?
10. java helloworld
Error: LinkageError occurred while loading main class helloworld
java.lang.UnsupportedClassVersionError: helloworld has been compiled by a more recent version of the Java Runtime (class file version 65.0), this version of the Java Runtime only recognizes class file versions up to 61.0
11. So, I decided to recompile using the source and target options of javac.
12. javac -source 17 -target 17 helloworld.java
warning: [options] system modules path not set in conjunction with -source 17
1 warning
So, what's happening? I am compiling from the command line, not from an IDE. I don't want to mess with trying to upgrade the JDK or JRE to version 21. How do I get the javac command to compile with version 17? I tried to find out how to find the system modules path, but came up short.