• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

UnsupportedClassVersionError

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Kedarnath Donthi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes Jesper. My opinion was same as yours, but the words, while writing, were wrong.

Thanks for the correction.
 
Ranch Hand
Posts: 513
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic