Which Java version to target?

W

wizofaus

Chris said:
(e-mail address removed) wrote:

[me:]
True, but for instance, I just wasted at least an hour today trying to
figure out why I was getting an ArrayStoreException - turned out it was
because I was accidentally adding the wrong object type to a Vector
(and subsequently converting it to an array).

I am surprised.
Surprised by what? Maybe years as a C++ programmer has made me
careless from being too reliant on the compiler catching my
screw-ups...
 
A

Andrew T.

That interests me...but at least with NetBeans, I haven't been able to
get it to target an earlier version.

The commands are in the basic tools distributed
with the SDK, but you need access to the earlier
JRE version to make the process work correctly.

I expect Netbeans has ways to connect into that,
but I'm not here to tell you how to work an IDE I
don't use (often).
..You say a warning - what's likely
to occur if they continue to use the application?

A variety of things that usually result in exceptions
or errors.
It does seem from what I've read elsewhere that this is the only
reliable way of gracefully handling older JVM/JRE installations that
works across all browsers.

Nope. Some browsers have no Java at all. Your best bet
for them is the (HTML 4.01 invalid) nested OBJECT/EMBED elements.
I gather JWS is java web start - which seems to be related to starting
standalone applications, which I've no need to do at this point.

Nope. JWS can be used to launch applets as well.
(If I had more time I'd hunt down the URL of an applet/
application I wrote that is JWS'd in both modes..)

Andrew T.
 
C

Chris Uppal

Surprised by what? Maybe years as a C++ programmer has made me
careless from being too reliant on the compiler catching my
screw-ups...

Maybe something of that sort. I work with dymamically-typed OO languages a
lot, and in my experience such errors are very rare (hence my surprise). It's
not that I take extra care to avoid type errors in an language without type
checking -- it's just not natural to make them in the first place.

So maybe you have become "careless", but to me it seems more likely that the
way you stucture your code is fundamentally different from the way I structure
mine. That would be supported by it taking so long to track down the error.
On the rare occasions when I do make type errors, it is normally obvious in
seconds, and fixed in not much longer.

Or maybe you were just unlucky ;-)

-- chris
 
T

Thomas Kellerer

That interests me...but at least with NetBeans, I haven't been able to
get it to target an earlier version.

Right click on your project, then choose Properties

In the "Source" node, choose Source level: 1.4

Then click on the "Compiling" node, add "-target 1.4" (without the
quotes) into the input field labelled "Additional Compiler Options"

Or - as an alternative - use a JDK 1.4 for compiling inside NetBeans
(Set it up through Tools -> Java Platform manager, then select it in the
"Libraries" node of your project properties)

Thomas
 
T

Thomas Hawtin

Thomas said:
In the "Source" node, choose Source level: 1.4

Then click on the "Compiling" node, add "-target 1.4" (without the
quotes) into the input field labelled "Additional Compiler Options"

You should also use -bootclasspath to point to the 1.4 rt.jar, unless
you want to get totally confused.

Tom Hawtin
 
M

Mike Amling

That's my current intention. It means no generics, which as a C++
programmer is frustrating, but I can live with it.

That's odd. I haven't used it myself, but I'd read that Java's
generics facility involves no changes to the bytecode language. What
happens if you try to compile with
javac -source 1.5 -target 1.4

--Mike Amling
 
U

u.int.32.t

That's my current intention. It means no generics, which as a C++
programmer is frustrating, but I can live with it.

It isnt too hard to use java -target 1.4 => target the 1.4 jvm using
the java 1.5 compiler.

Theoretically
 
T

Thomas Hawtin

Mike said:
That's odd. I haven't used it myself, but I'd read that Java's
generics facility involves no changes to the bytecode language.

The bytecode instructions themselves remain the same, but there are
extra attributes added to the class files.
What
happens if you try to compile with
javac -source 1.5 -target 1.4

Try it. It wont.

1.5 has the undocumented and unsupported -source jsr14 (IIRC).

Does anyone have any figures for which versions browsers have installed?
The online installer for Windows should have updated most to 1.5.
Windows/Solaris/Linux users that have used offline installers in the
last year and three quarters will presumably mostly installed 1.5. No
idea about Mac users, other than Apple is usually around a year behind.

Tom Hawtin
 
W

wizofaus

Thomas said:
Try it. It wont.

1.5 has the undocumented and unsupported -source jsr14 (IIRC).

Does anyone have any figures for which versions browsers have installed?
The online installer for Windows should have updated most to 1.5.
Windows/Solaris/Linux users that have used offline installers in the
last year and three quarters will presumably mostly installed 1.5. No
idea about Mac users, other than Apple is usually around a year behind.
Most of the Windows systems I've tried it on only have 1.4.2_03, so
that's my target at this point. But apparently even that's not enough
- there are things that fail mysteriously under that version that work
fine when you have the 1.5 JRE installed (e.g. JFrame.add() vs
JFrame.setContentPane()), so you absolutely have to test on a system
that only has 1.4.2 installed.

The advantages of using Generics don't seem enough to be worth the risk
that something's going to be behave unpredictably on another system, so
I'm just getting used to having my code littered with casts. The fact
that it took till version 1.5 of Java until there were typed resizable
collections in the language is a little baffling to me.
 
T

Thomas Hawtin

Most of the Windows systems I've tried it on only have 1.4.2_03, so

Seems a bit old. 1.4.2 is up to at least 1.4.2_11 (some of those
security updates).
that's my target at this point. But apparently even that's not enough
- there are things that fail mysteriously under that version that work
fine when you have the 1.5 JRE installed (e.g. JFrame.add() vs
JFrame.setContentPane()), so you absolutely have to test on a system
that only has 1.4.2 installed.

I'm sure you can develop it on a machine that has both 1.5 and 1.4.2
installed.
I'm just getting used to having my code littered with casts. The fact
that it took till version 1.5 of Java until there were typed resizable
collections in the language is a little baffling to me.

It was dragged out, but it isn't so easy to retrofit such a feature.

Tom Hawtin
 

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,780
Messages
2,569,611
Members
45,265
Latest member
TodLarocca

Latest Threads

Top