• Post Reply Bookmark Topic Watch Topic
  • New Topic

A simple question - Help required!!  RSS feed

 
Sajee Joseph
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
I have a certain question which has been haunting me for quite some time.
We all are aware that Java comes up with a new version every now and then.
And in each new version, new API's are added, Code is optimized for performance & certain existing Bugs are fixed. Thus in general it is better to use a newer ( and probably more stable) version of Java than the Old one.
I have a couple of questions on this:
1. If i develop some code (say a servlet) using a new java version and later deploy the class files to a server ( running Tomcat or someother) which has an older version of Java installed (assuming that there are no new APIs used in my code). Which version of java will finally be used for my code execution? Obviously it should be the version installed on the server. In this case wouldnt my java servlet code still be performing bad since it is using the Old java version to execute though the class files are generated using the New java version.
2. If i develop some code (say a servlet) using an old java version and later deploy the class files to a server ( running Tomcat or someother) which has a new version of Java installed. Which version of java will finally be used for my code execution?
Please give these questions some careful thought and let me know the answers.
Thanks,
Sajee Joseph
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sajee Joseph:
1. If i develop some code (say a servlet) using a new java version and later deploy the class files to a server ( running Tomcat or someother) which has an older version of Java installed (assuming that there are no new APIs used in my code). Which version of java will finally be used for my code execution? Obviously it should be the version installed on the server. In this case wouldnt my java servlet code still be performing bad since it is using the Old java version to execute though the class files are generated using the New java version.

Yes, it will use the server's jvm to deal with that... You have to aware of the version specific issue, if ur j2ee version in development phase and that in deployment version... It's serious...

2. If i develop some code (say a servlet) using an old java version and later deploy the class files to a server ( running Tomcat or someother) which has a new version of Java installed. Which version of java will finally be used for my code execution?

I think I've answered to both questions... I feel that question No.2 is the same as question No.1...
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you compile against version X and deploy on version Y several things can happen:
1) your code runs fine
2) your code refuses to run
If X is older than Y it will usually be 1) (though not always, sometimes deprecated functions are removed causing trouble but this is so far rare (IMO rarer than it ought to be).
If otoh Y is older than X there's a good chance that your code won't run on the old JVM unless it was specifically compiled with backwards compatibility for that JVM in mind. This is because there is no guarantee that the internals of the compiled classfile will not change between versions, and you yourself might have used functionality not available on the old version.
Say your code runs, it will then run in a runtime environment of the version installed on the machine on which it is running, not the version it was compiled against.
That means it will suffer from all performance problems and bugs (except those in the javac compiler itself) of the deployment platform.
The moral of this story: when deploying against a different JVM from the one your workstation is running on always test on a machine that has the correct JVM version to make sure there are no sudden surprises (better yet, keep the machines on the same JVM version).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!