Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2007

Tip: Looking for answers? Try searching our database.

Java Version Functionality

Thread view: 
smcoe1@gmail.com - 01 Feb 2007 16:02 GMT
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
Andrew Thompson - 01 Feb 2007 16:14 GMT
On Feb 2, 3:02 am, smc...@gmail.com wrote:
> 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.
Juan Singh - 01 Feb 2007 16:22 GMT
> Hi, I am assuming I can't do this, but I figured I would ask.
>
[quoted text clipped - 7 lines]
>
> 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
Daniel Pitts - 01 Feb 2007 23:06 GMT
On Feb 1, 8:02 am, smc...@gmail.com wrote:
> Hi, I am assuming I can't do this, but I figured I would ask.
>
[quoted text clipped - 7 lines]
>
> 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.