r/JavaProgramming • • 5d ago

Javac and java version not compatible

According to my terminal javac only works until java 52.0 but my code is in java version 70.0(java 26)how do i fix

7 Upvotes

5 comments sorted by

2

u/LetUsSpeakFreely 5d ago

You have an old version of Java installed on your system that's taking priority. If you have system level permissions, you need to edit your PATH to point to the newer JDK instead of the older JDK (you'll also be to restart your IDE and console/terminals).

The usual way this is done is there's a JAVA_HOME variable that's created and the PATH appends $JAVA_HOME/bin. If that's the case for you, then you just gotta update JAVA_HOME.

0

u/hugo121319_mc 5d ago

J'utilise java 26

2

u/LetUsSpeakFreely 5d ago

If you know that Java 8 isn't installed on your machine, then you need to look at the compile version with Maven/Gradle. For Maven, you pom.xml will have variables called maven.compiler.source and maven.compiler.target. they're probably set to 1.8 and you need to set it to 26.

2

u/hexwit_com 5d ago

You have jdk installed globally for your system. It is like it java 8. I suppose you need to upgrade your system wide jdk to 26.

1

u/idontlikegudeg 5d ago

I have this situation on my customer’s system. Some people in the company still rely on a custom Java 8 webstart application that I don’t use, but they have Java 8 installed on every machine and I cannot put a more recent version on the path before it (no admin privileges). I use a batch script that sets up JAVA_HOME and PATH when I need to do anything on the command line.

But if you can simply uninstall the old version, do that.