Interesting problem

Discussion in 'Java' started by jimlee2004@gmail.com, Nov 10, 2006.

  1. Guest

    I have a stupid but interesting question.

    Let's say I have 3 java files. a.java, b.java. c.java and a calls b and
    b calls c.
    If I compile and run them, they works fine.

    Assume I use java 1.2 to compile a.java
    and then use java 1.5 to compiel b.java
    and then use java 1.4 to compile c.java

    and then put a.class and b.class and c.class together,
    I was wondering if it still run?

    In other words, If I collect a bunch of class that compiled from
    differenet version of java.
    is there any issue to run it? Why or why not?

    Thanks,
    , Nov 10, 2006
    #1
    1. Advertising

  2. wrote:
    >
    > Let's say I have 3 java files. a.java, b.java. c.java and a calls b and
    > b calls c.
    > If I compile and run them, they works fine.
    >
    > Assume I use java 1.2 to compile a.java
    > and then use java 1.5 to compiel b.java
    > and then use java 1.4 to compile c.java


    1.5 defaults to compiling code that only runs on 1.5 or greater.
    Therefore the 1.2 compiler will not be able to read the b.class.

    Typically you would compile with the latest compiler and set -source,
    -target and -bootclasspath to the relevant target JRE.

    Tom Hawtin
    Thomas Hawtin, Nov 10, 2006
    #2
    1. Advertising

  3. Guest

    Thanks,

    what if I run on a 1.5 jre? It should be ok , right?
    In other words, if the jre is higher than any of the .class run, it
    should run.
    But not the otherway around ( that's what I want to confirm)

    Thomas Hawtin wrote:
    > wrote:
    > >
    > > Let's say I have 3 java files. a.java, b.java. c.java and a calls b and
    > > b calls c.
    > > If I compile and run them, they works fine.
    > >
    > > Assume I use java 1.2 to compile a.java
    > > and then use java 1.5 to compiel b.java
    > > and then use java 1.4 to compile c.java

    >
    > 1.5 defaults to compiling code that only runs on 1.5 or greater.
    > Therefore the 1.2 compiler will not be able to read the b.class.
    >
    > Typically you would compile with the latest compiler and set -source,
    > -target and -bootclasspath to the relevant target JRE.
    >
    > Tom Hawtin
    , Nov 10, 2006
    #3
  4. Daniel Pitts Guest

    wrote:
    > Thanks,
    >
    > what if I run on a 1.5 jre? It should be ok , right?
    > In other words, if the jre is higher than any of the .class run, it
    > should run.
    > But not the otherway around ( that's what I want to confirm)
    >
    > Thomas Hawtin wrote:
    > > wrote:
    > > >
    > > > Let's say I have 3 java files. a.java, b.java. c.java and a calls b and
    > > > b calls c.
    > > > If I compile and run them, they works fine.
    > > >
    > > > Assume I use java 1.2 to compile a.java
    > > > and then use java 1.5 to compiel b.java
    > > > and then use java 1.4 to compile c.java

    > >
    > > 1.5 defaults to compiling code that only runs on 1.5 or greater.
    > > Therefore the 1.2 compiler will not be able to read the b.class.
    > >
    > > Typically you would compile with the latest compiler and set -source,
    > > -target and -bootclasspath to the relevant target JRE.
    > >
    > > Tom Hawtin


    Kind of, you couldn't compile a.java, since the compiler needs to look
    at b.java.

    So, the short answer is, if you get it to compile, it should work. The
    longer answer is, you should try to be consistent in your codebase. If
    you need to use Java 1.5, then use it all the way around. Most java
    1.2/1.4 code (not all) will compile in 1.5 just fine. If you are
    having trouple with it, try to fix the J2 code to work with J5.
    Daniel Pitts, Nov 10, 2006
    #4
  5. Guest

    The reason I am asking this question is because I have the following
    scenario.

    Let's assume I delivered an application which contains a.class.b.class,
    c.class

    later on, I put some enhancement to c.java and want to delivery it to
    client.
    however, I can't redelivery a.class and b.class.

    can I simply give c.class to them and ask them to replace their old
    c.class?
    (Given the fact that I don't know exactly which jre version they are
    running?)
    , Nov 10, 2006
    #5
  6. Daniel Pitts Guest

    wrote:
    > The reason I am asking this question is because I have the following
    > scenario.
    >
    > Let's assume I delivered an application which contains a.class.b.class,
    > c.class
    >
    > later on, I put some enhancement to c.java and want to delivery it to
    > client.
    > however, I can't redelivery a.class and b.class.
    >
    > can I simply give c.class to them and ask them to replace their old
    > c.class?
    > (Given the fact that I don't know exactly which jre version they are
    > running?)


    You'd have to compile class c under the lowest common denominator.
    Meaning, if you possibly had clients with JRE1.2, then you'd have to
    write the class for 1.2.
    The alternative is to have the clients upgrade JRE's, and supply them
    with a fresh build, rather than a patch.
    It becomes complicated to keep track of "patches" if you do it file by
    file.

    "This client has a.class version 1, b.class version 32, and c.class
    version 14. c.class version 15 isn't compatible with a.class version
    1, but is with a.class version 3, but a.class isn't compatible with
    b.class version 32." etc... etc...

    Put everything in a single Jar file, then you can upgrade it all at
    once.
    Daniel Pitts, Nov 10, 2006
    #6
    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. Elliot M. Rodriguez

    An interesting problem

    Elliot M. Rodriguez, Oct 21, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    387
    Elliot M. Rodriguez
    Oct 21, 2003
  2. Bilbo
    Replies:
    3
    Views:
    420
    Bilbo
    Nov 20, 2003
  3. francois
    Replies:
    0
    Views:
    374
    francois
    Jan 9, 2004
  4. Rakesh Roberts

    A Very interesting cookie problem

    Rakesh Roberts, Apr 7, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    470
    Craig Deelsnyder
    Apr 7, 2004
  5. Xaonon
    Replies:
    1
    Views:
    372
    Matt Humphrey
    Dec 17, 2003
Loading...

Share This Page