java 1.5 on 1.4.2

O

oracle

Just need to verify something.

You can not use a java 1.5 war file on a machine with java 1.4.2 loaded
on it.

Is this not right???

Thanks
 
G

Gerbrand van Dieijen

oracle schreef:
Just need to verify something.

You can not use a java 1.5 war file on a machine with java 1.4.2 loaded
on it.

That depends, you can compile Java 1.5 source code to a 1.4 class file.
Then it will run fine on a java 1.4.2 JVM, even with the use of
generics, and other java 1.5 extensions.
 
R

Ross Bamford

oracle schreef:

That depends, you can compile Java 1.5 source code to a 1.4 class file.
Then it will run fine on a java 1.4.2 JVM, even with the use of
generics, and other java 1.5 extensions.

Hmm, I'd like a copy of your JVM... You can specify to javac the Source
Code and Target JVM versions you require. Specifying a lower Target
requires also that you set a lower Source.

So you can compile, for example, for 1.4, using:

javac -source 1.4 -target 1.4 MyClass.java

However, if MyClass.java uses *any* JDK 1.5 specific features (Generics,
For-each loop, etc), you'll get:

MyClass.java:5: generics are not supported in -source 1.4
(try -source 1.5 to enable generics)
static Vector<MyClass> v = new Vector<MyClass>();
^
1 error

(as already mentioned, the -source argument is mandatory in this case,
although I'm not sure if it implies the target).

Ross
 
T

Tor Iver Wilhelmsen

Ross Bamford said:
MyClass.java:5: generics are not supported in -source 1.4
(try -source 1.5 to enable generics)
static Vector<MyClass> v = new Vector<MyClass>();

Why not try -source 1.5 -target 1.4?
 
R

Ross Bamford

Why not try -source 1.5 -target 1.4?

Why don't you? :)

Quote: "javac: source release 1.5 requires target release 1.5"

You have to understand that Java isn't Perl - it's not interpreted. New
*language* features introduce new *opcodes* which a 1.4 JVM would
probably class as Invalid (look at ClassLoader/SecurityManager).

Javac obviously won't let you specify 'Generate these special 1.5
Opcodes, and then target them for a JVM that's never heard of them".

Cheers,
Ross
 
?

=?ISO-8859-1?Q?Daniel_Sj=F6blom?=

Ross said:
You have to understand that Java isn't Perl - it's not interpreted. New
*language* features introduce new *opcodes* which a 1.4 JVM would
probably class as Invalid (look at ClassLoader/SecurityManager).

I'm not aware of any new opcodes being introduced in a long time. There
is one new variation on the ldc instruction in java 1.5, which however
does not do anything that couldn't be done before (it loads a class
literal.) It is however impossible to compile all 1.5 source to 1.4
bytecode. The most obvious problems are lack of an annotation
specification in the 1.4 class file format, and also the need for
generic signatures, also not present in 1.4.
 
R

Ross Bamford

I'm not aware of any new opcodes being introduced in a long time.

Of course you're right - I said it without thinking, just to try to get
across why it doesn't work. The intent remains the same, that the core
JVM doesn't understand the class file structure.

Sorry for confusion :)
 
J

Juha Laiho

Ross Bamford said:
You have to understand that Java isn't Perl - it's not interpreted.

Apologies for taking this completely off-topic, but just for the record,
Perl isn't interpreted, either - it's compiled into bytecode, but the
compilation results are not (normally) permanently stored. Instead,
there's a compilation phase each time you run a Perl program.

From documentation:
After locating your program, Perl compiles the entire program to an
internal form. If there are any compilation errors, execution of the
program is not attempted. (This is unlike the typical shell script,
which might run part-way through before finding a syntax error.)
 
G

Gerbrand van Dieijen

Tor Iver Wilhelmsen schreef:
Why not try -source 1.5 -target 1.4?

I use these paramaters, and it works fine. Maybe it doesn't work for all
1.5 extensions, but it works fine for generics.
 
T

Thomas Schodt

Gerbrand said:
I use these paramaters, and it works fine. Maybe it doesn't work for all
1.5 extensions, but it works fine for generics.

What does "javah -version" say?
[Or "javac -version" if javac now does -version].
 
T

Tony Morris

Gerbrand van Dieijen said:
Tor Iver Wilhelmsen schreef:

I use these paramaters, and it works fine. Maybe it doesn't work for all
1.5 extensions, but it works fine for generics.

No, you cannot use -source 1.5 -target 1.4.
You want to look at the undocumented compiler switch -jsr14.
If you are using source level 1.5, why are you using a data type
(java.util.Vector) that was obsoleted 7 or 8 years ago?
http://qa.jtiger.org/GetQAndA.action?qids=53

--
Tony Morris
Software Engineer, IBM Australia.
BInfTech, SCJP 1.4, SCJD

http://www.jtiger.org/ JTiger Unit Test Framework for Java
http://qa.jtiger.org/ Java Q&A (FAQ, Trivia)
http://xdweb.net/~dibblego/
 

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
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top