Versions are for applications. But in java there is major and minor versions for class files.
When JVM loads a class it gets it's major version. If this version is more than the JVM's max supported version then it wil not load the class.
JVM only loads the class if it's major version lies in the limit of the versions supported by the JVM.
The first four bytes of a class file are CAFEBABE, it is called magic number. Next four bytes are major and minor versions. Run the following code and see the output:
import java.io.InputStream;
public static void main(String argv[]) throws Exception{
InputStream stream = ClassLoader.getSystemResourceAsStream("java/lang/String.class");
byte[] bytes = new byte[4];
stream.read(bytes);
System.out.println("The first four bytes are:");
print(bytes);
stream.read(bytes);
System.out.println("\nNext four bytes are:");
print(bytes);
stream.close();
}
private static void print(byte[] bytes){
for(int i=0;i<bytes.length;i++){
System.out.print(getChar((bytes>>4) & 0xF));
System.out.print(getChar(bytes&0xF));
System.out.print(" ");
}
}
private static char getChar(int b){
if(b>15 || b<0){
return 'x';
}
if(b>=0 && b<=9){
return (char)('0'+b);
}
return (char)('A'+ (b-10));
}
The next four bytes are 00 00 00 30, so here 0030 is the major version. Now let your JVM supports upto 0020 then it will not load this class.
May this help.
Regards,