Java Version Functionality

S

smcoe1

Hi, I am assuming I can't do this, but I figured I would ask.

I have to support a minimum java version. Is their any way of
detecting the version, and if the version is x or greater then some
specific task, otherwise skip the task.

If I can't do this (which is what I am assuming) is their a way I can
do a similar thing to #ifdef in C++ which will allow me to compile two
versions?

Thanks
 
A

Andrew Thompson

Hi, I am assuming I can't do this, but I figured I would ask.

Did your assumptions prompt you to search,
or did you just figure you'd skip that part?
I have to support a minimum java version. Is their any way of
detecting the version, and if the version is x or greater then some
specific task, otherwise skip the task.

Task? What task?
- start a web service?
- initiate a system back up?
- launch a GUI'd application?
- launch a command line application?

Note that 'ant' might be one way to achieve
what the desired goal, or perhaps web-start,
or maybe a combination of the both, or neither.
It depends on 'Task?' mentioned above.

Andrew T.
 
J

Juan Singh

Hi, I am assuming I can't do this, but I figured I would ask.

I have to support a minimum java version. Is their any way of
detecting the version, and if the version is x or greater then some
specific task, otherwise skip the task.

If I can't do this (which is what I am assuming) is their a way I can
do a similar thing to #ifdef in C++ which will allow me to compile two
versions?

Thanks


Use the following code to check the version of VM.

System.getProperty("java.specification.version");

Refer to http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html
for details.


Java does not have preprocessors like C/C++. If you use a class that is
in the newer version but not in the older, you will get
ClassNotFoundExceptions at run time. Therefore, you could do something
like this in the code.

String version = System.getProperty("java.specification.version");

if(version.equals("1.4"){
OldClass myObject = new OldClass();
}else if(version.equals("1.5")){
NewClass myObject = new NewClass();
}


Since classes are loaded on demand in Java, your code should never load
NewClass if you are using 1.4
 
D

Daniel Pitts

Hi, I am assuming I can't do this, but I figured I would ask.

I have to support a minimum java version. Is their any way of
detecting the version, and if the version is x or greater then some
specific task, otherwise skip the task.

If I can't do this (which is what I am assuming) is their a way I can
do a similar thing to #ifdef in C++ which will allow me to compile two
versions?

Thanks

Do you REALLY need to support java pre-beta release?

A more serious question though. Is there any way you can suggest
upgrading Java to a more recent version? Sun has made it easier than
ever to do this. I'm not sure, but I think webstart can even help
users upgrade as needed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top