Forums Register Login

Detect JRE Version

+Pie Number of slices to send: Send
Ok, this is more of a curiosity question. But it may be interesting.
I was wondering if there is any way to detect the JRE version running on a PC using JAVA.
Here is the reason:
Suppose you could write an application and you used some API from 1.4 but the user is running 1.3 and they don't want to upgrade. Could you then say something like:
if (using JRE1.4)
{
//Perform 1.4 Specific API Code
}else
{
//Perform 1.3 Specific API Code
}
I hope this makes sense.
Thanks.
+Pie Number of slices to send: Send
You could try using:

However be careful when you use classes from 1.4 & the target JRE is not 1.4. The problem is that some JRE's may implement eager loading of classes, i.e when your class is loaded, the JVM might try to resolve all symbolic references and load those classes as well up front. So you may end up getting ClassDefNotFoundErrors, even though you are detecting & avoiding the usage of 1.4 classes.
You can work-around this issue by using Reflection and avoiding any symbolic references to 1.4 classes in your code.
[ November 07, 2002: Message edited by: Junaid Bhatra ]
+Pie Number of slices to send: Send
Be ware, though, that (I'm pretty darn sure) there is no standard or requirement of the JLS or JVMS as to the actual String returned when requesting a System property. Hopefully the returned String would always contain 1.4 or 1.3 and you could just search the whole String for such a substring - but again, there is no official standard or guarantee as to the contents of the String.
+Pie Number of slices to send: Send
If to rephrase this problem, then does it sound like:
whether earlier version JRE/JVM can run Java application compiled with later JDK, i.e. with the use of the classes from later JDK?
It was what I tried to clear for me in various topics.
Let me guess...
"Write once, run anywhere" ("WORA") combined with practical impossibility to configure (remote) clients, and the general-sense security considerations logically dictate that Java application should be independent on JVM/JRE version.
In other words, JVM should be capable to load "later versions" classes from application (class or .jar).
The application, obviously, should be filled during compilation with content of developer's classes, and contain everything to be loaded by thin JVM/JRE, independently of which JDK version is installed locally, sorry remotely from developer, except dynamic references.
This my,is obvious to me, logic.
But does it correspond to reality?
?Certainly, I followed advise of Cindy and looked to extreme of my patience thru JVM spec, but I did not understand from where JVM/JRE do resolve references, especially on standard packages.
From client's JDK, from client's JRE, from jars, as it should have been?
It seems to me, it is not specified exactly (Well, by pure logic of "WORA", everything should be really included to compiled file).
Does JRE installation contain all JAVA's standard API classes?
?Then if JVM/JRE loads only what is needed, it is better/smaller than always bundle (excessive volumes) of/with JRE to clients.
[ November 22, 2002: Message edited by: G Vanin ]
It's hard to fight evil. The little things, like a nice sandwich, really helps. Right tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1475 times.
Similar Threads
Launch Exception encountered in Java Web Start
java.lang.IllegalAccessError
where should I?
assert
Unsupported major.minor version 50.0
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 07:46:06.