Java Version Functionality

Discussion in 'Java' started by smcoe1@gmail.com, Feb 1, 2007.

  1. Guest

    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
     
    , Feb 1, 2007
    #1
    1. Advertising

  2. On Feb 2, 3:02 am, 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.
     
    Andrew Thompson, Feb 1, 2007
    #2
    1. Advertising

  3. Juan Singh Guest

    wrote:
    > 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
     
    Juan Singh, Feb 1, 2007
    #3
  4. Daniel Pitts Guest

    On Feb 1, 8:02 am, wrote:
    > 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.
     
    Daniel Pitts, Feb 1, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christian Schlichtherle
    Replies:
    8
    Views:
    484
    John Currier
    Jul 5, 2005
  2. Replies:
    1
    Views:
    895
  3. V Green
    Replies:
    0
    Views:
    923
    V Green
    Feb 5, 2008
  4. PA Bear [MS MVP]
    Replies:
    0
    Views:
    1,034
    PA Bear [MS MVP]
    Feb 5, 2008
  5. MowGreen [MVP]
    Replies:
    5
    Views:
    2,080
    PA Bear [MS MVP]
    Feb 9, 2008
Loading...

Share This Page