Interesting problem

J

jimlee2004

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,
 
T

Thomas Hawtin

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
 
J

jimlee2004

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)
 
D

Daniel Pitts

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)

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.
 
J

jimlee2004

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?)
 
D

Daniel Pitts

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.
 

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

Similar Threads


Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top