Determining which versions of java a program will run on?

A

Andrew Thompson

Is there a way to find this out?

Please repeat subject line in the body of the message.

What app.? Yours or someone elses?

For your own, you might try compiling the code
using the -bootclasspath option, and pointing it
to the rt.jar of the earlier version.
 
T

travel2light

Please repeat subject line in the body of the message.

No problem.
What app.? Yours or someone elses?

For your own, you might try compiling the code
using the -bootclasspath option, and pointing it
to the rt.jar of the earlier version.

This is my application. Actually I think I explained it incorrectly. I
only want to find out what versions of java the compiled code will run
on. I am using 1.6.0_03-b05. I don't intend to recompile it for
different versions.

Michael
 
A

Andrew Thompson

...
...I
only want to find out what versions of java the compiled code will run
on. I am using 1.6.0_03-b05. I don't intend to recompile it for
different versions.

You don't need to. Any code that is compiled
to run on Java 1.4 (for example) will also run
just fine in Java 1.5 and 1.6 (etcetera).

The -bootclasspath option is useful because
it ensures the bytecodes are *really* compatible
with the target minimum version, as opposed to
simply having the bytecodes written in the form
expected for 1.4. That is what Jeff was referring
to when he mentioned the class file format.

So, it works like this, you compile code
using the 1.6 SDK, but specify the -bootclasspath
option and point that towards a 1.4 rt.jar
(as well, specify the -source and -target,
but the -bootclasspath is the one most people
miss).

The binary will be compatible with 1.4+.

Using -bootclasspath is also a good 'acid test'
for whether the code is truly compatible with
the target minimum version.
 
A

Arne Vajhøj

travel2light said:
Is there a way to find this out? Thanks for any advice.

javap -verbose -classpath . yourpackage.YourClass

will display major and minor version number.

Version X will run on versions >X but not on version <X.

Basically JDK version 1.n.x uses major version 44+n.

Arne
 
K

Kenneth P. Turvey

On Sat, 08 Mar 2008 18:10:28 -0800, Andrew Thompson wrote:

[Snip]
So, it works like this, you compile code
using the 1.6 SDK, but specify the -bootclasspath
option and point that towards a 1.4 rt.jar
(as well, specify the -source and -target,
but the -bootclasspath is the one most people
miss).

I'm not the original poster, but I have a related question. You always
see the -source and -target options used together and set to the same java
version. Is this required these days. What I would like to do is to
create a 1.4 class file from 1.6 sources using a 1.4 rt.jar. So I could
use modern java language features, but restrict myself to the older
libraries and produce a class file that can be read by older versions of
the JRE?

Am I asking too much here?

Thanks.
 
A

Andrew Thompson

On Mar 10, 10:41 am, "Kenneth P. Turvey" <kt-
(e-mail address removed)> wrote:
...
I'm not the original poster, but I have a related question.  You always
see the -source and -target options used together and set to the same java
version.  

You might. I don't.

-source never has any meaning below '1.3',
whereas the -target might specify '1.1'.
..Is this required these days.  What I would like to do is to
create a 1.4 class file from 1.6 sources using a 1.4 rt.jar.  So I could
use modern java language features, but restrict myself to the older
libraries and produce a class file that can be read by older versions of
the JRE?  

I am not entirely sure what you are asking,
but note that generics (for e.g.) cannot be
used in any code intended to run on 1.4.
 
K

Kenneth P. Turvey

I am not entirely sure what you are asking,
but note that generics (for e.g.) cannot be
used in any code intended to run on 1.4.

Well, that would be one feature I would like. Would this give the modern
looping constructs (a favorite of mine)? What about assertions?

Thanks?
 
A

Andrew Thompson

Well, that would be one feature I would like.  Would this give the modern
looping constructs (a favorite of mine)?  What about assertions?  

I do not believe so, though the spec. gurus
might be in a better position to advise.

(shrugs) I usually 'specify the options and let
the compiler decide'. Further, since I only too
regularly need to design for binaries that will
run on 1.4 or (shock/horror) 1.1, my enthusiasm
for the 'new language constructs' has been somewhat
lacking.

I understand 'Thanks' and 'Thanks!', but what
does 'Thanks?' mean?

Bear with me - I took the English level in school
that was designed for people who's parents were
cousins (more interested in math and any flavor
of science or tech.).
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top