• Post Reply Bookmark Topic Watch Topic
  • New Topic

JDK versions question  RSS feed

 
prasad agarwal
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Just out of curiosity, lets say you are working on a project where your J2EE app server is supporting Java EE6 and Java SE7 but you pick up one jar file compiled using say J2SE 1.4.2 and put it in classpath, what happens?

Is it going to encounter with errors because of old java version conflict or it will work fine in some mysterious way?
I very well know that it is never a good practice to do this kind of a thing but just curious since I was just testing (for the purpose of testing) and surprisingly it is working fine without any warnings or errors !

Thanks for your comments... I know it is never a good idea to do it this way but want to know how the app server and classloaders work in such a case... Also J2se 1.4.2 has a lot of deprecated code.
 
Campbell Ritchie
Marshal
Posts: 56522
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can usually execute code compiled with an older version of Java than you are using at present.
You can not usually execute code compiled with a newer version of Java than you are using at present, but there are options you can use to make the bytecode compatible with older versions.

So your Java1.4.2 jar file should execute normally on a Java7 or Java8 runtime. Java maintains backward compatibility.
 
Akaine Harga
Ranch Hand
Posts: 99
Java MyEclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It highly depends on what classes and methods of this library you will actually use on a runtime level. Chances it will function, chances not. Normally, JRE is backward compatible (old libs should run on later JRE versions).

Also, if the library in question is relatively small, you can always decompile and recompile it. Or even write your own library from the scratch by reverse engineering the original jar. On several occasions I had to use complex old libs that did magical stuff (COBOL adaptors, banking transactions assemblers, etc.) where adaptation/recompilation was the only way to solve the problem.
 
prasad agarwal
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks guys;
I never thought you can put some jar file which never used Generics and many more which were added since Java 5 and expect it to work.
I thought from Java 5 to Java 1.4.2 does not have backward compatibility?

Yes, reverse engineering the original jar is something new and interesting to me and I love the 'DJ Decompiler' ;)

Thanks again
 
Paul Clapham
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
prasad agarwal wrote:I thought from Java 5 to Java 1.4.2 does not have backward compatibility?


No, no, backward compatibility has always been an important feature for the Java engineers at Oracle (and Sun before them). People say that a much better implementation of generics would have been possible if they hadn't insisted on backwards compatibility, but they did and so we got the implementation we got.
 
prasad agarwal
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Awesome
It is good to hear that backward compatibility has always been an important feature in Java; I never knew that until now.
Thanks
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!