This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes UnsupportedClassVersionError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "UnsupportedClassVersionError" Watch "UnsupportedClassVersionError" New topic
Author

UnsupportedClassVersionError

shameem Shek
Greenhorn

Joined: Aug 27, 2007
Posts: 9
Hi this below code is compiling successfully but when I try to run I am getting the exception in thread main while running the program.
Please help me anyone thanks in advance..
class Octal
{
public static void main(String [] args)
{
int six = 06; // Equal to decimal 6
int seven = 07; // Equal to decimal 7
int eight = 010; // Equal to decimal 8
int nine = 011; // Equal to decimal 9
System.out.println("six= " +six);
System.out.println("seven = " + seven);
System.out.println("eight = " + eight);
System.out.println("nine = " + nine);
}
}

Exception in thread "main" java.lang.UnsupportedClassVersionError: Octal (Unsupp
orted major.minor version 49.0)

Please help me anyone as early as possible thank you.
Kedarnath Donthi
Greenhorn

Joined: Mar 12, 2006
Posts: 2
Generally UnsupportedClassVersionError is thrown when a Java program is compiled on lower version of Java and executed on a higher version.

Eg.: program is compiled using Java 1.4 and executed using Java 1.5.

Check the versions using the commands

javac -version
java -version


Both the commands should output the same version. If not update the classpath and path entries so that they point to the same Java directory.

One thing is that the entries in the path and classpath are order-sensitive, i.e., the first entry has the priority.

Eg.: There are two versions of Java in the system and both the entries are in path env variable as follows - C:\j2sdk1.4.0\bin;D:\oracle\java3\bin;
Then on using the java command the class is executed using Java version 1.4, because the first entry is of Java 1.4's.

This is the case for classpath too.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14278
    
  21

Originally posted by Kedarnath Donthi:
Generally UnsupportedClassVersionError is thrown when a Java program is compiled on lower version of Java and executed on a higher version.

Eg.: program is compiled using Java 1.4 and executed using Java 1.5.

No - it is exactly the other way around.

You will get this error when you compiled your code on a newer version of Java, and you are trying to run it on an older version.

Eg.: program is compiled using Java 5 and executed using Java 1.4.

The other way around (compiling on 1.4 and running on 5) works without problems.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Kedarnath Donthi
Greenhorn

Joined: Mar 12, 2006
Posts: 2
Yes Jesper. My opinion was same as yours, but the words, while writing, were wrong.

Thanks for the correction.
Kelvin Chenhao Lim
Ranch Hand

Joined: Oct 20, 2007
Posts: 513
Jesper is absolutely right. And if you want to get really technical, here are the precise rules for whether a class file version is compatible with a given JVM:

"The Java virtual machine implementation of Sun�s JDK release 1.0.2 supports class file format versions 45.0 through 45.3 inclusive. Sun�s JDK releases 1.1.X can support class file formats of versions in the range 45.0 through 45.65535 inclusive. For k >= 2 implementations of version 1.k of the Java 2 platform can support class file formats of versions in the range 45.0 through 44+k.0 inclusive."

where the class version numbers used so far are:

Java 1.0 --> version 45.3
Java 1.1 --> version 45.3
Java 1.2 --> version 46.0
Java 1.3 --> version 47.0
Java 1.4 --> version 48.0
Java 1.5 --> version 49.0
Java 1.6 --> version 50.0


SCJP 5.0
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: UnsupportedClassVersionError