Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > javac -source 1.6 -target 1.4

Reply
Thread Tools

javac -source 1.6 -target 1.4

 
 
Kenneth P. Turvey
Guest
Posts: n/a
 
      03-15-2008
In a post to this newsgroup recently I mentioned that I've never seen
source and target used where there was a difference in the values
supplied. A reader on this newsgroup replied indicating that normally
they were different in his application of them.

I thought this was interesting since I would very much like to be able to
target 1.3 or 1.4 class files using source code that included the 1.5
changes, including the new looping construct and the assert keyword (I
know that generics won't work). Even if I couldn't get these later
language constructs, one would expect that the 1.6 compiler would do a
better job than the 1.3 or 1.4 one would.

So I decided to try this out. I couldn't get it to work at all when
applying it to some of my already written source code (and including the
-bootclasspath option), so I thought I would try a simple hello world
example.

This is the class I'm trying to compile:

----
public class Main {
public static void main(String[] args) {
System.out.println("This is a test app");
}
}
----

It can't get much simpler than that.

When I try to compile it and target the 1.5 class file format, this is
what I get:

----
kt@lovelace:~/src/TestApp/src/testapp$ javac -source 1.6 \
-target 1.5 Main.java
javac: source release 1.6 requires target release 1.6
----

Would somebody tell me what magic I need to do to get the Sun 1.6 compiler
to target an earlier version of the class file?

Thank you.

--
Kenneth P. Turvey <(E-Mail Removed)>
 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      03-15-2008
Kenneth P. Turvey wrote:
> Would somebody tell me what magic I need to do to get the Sun 1.6 compiler
> to target an earlier version of the class file?


<http://java.sun.com/javase/6/docs/technotes/tools/solaris/javac.html#crosscomp-example>

--
Lew
 
Reply With Quote
 
 
 
 
Kenneth P. Turvey
Guest
Posts: n/a
 
      03-15-2008
On Sat, 15 Mar 2008 00:19:28 -0400, Lew wrote:

> Kenneth P. Turvey wrote:
>> Would somebody tell me what magic I need to do to get the Sun 1.6 compiler
>> to target an earlier version of the class file?

>
> <http://java.sun.com/javase/6/docs/technotes/tools/solaris/javac.html#crosscomp-example>
>


Ok, thanks. I got it to compile to a 1.5 class file and then to a 1.3
class file. The only problem is that I still can't get it to compile to a
1.3 version of the class file without specifying a 1.3 source as well.

What I really want is something like this:

javac -source 1.5 -target 1.3 -bootclasspath /my/jre/lib/rt.jar Main.java

Unfortunately it only seems to work correctly when source and target have
the same value. Am I missing something here?

Thank you.

--
Kenneth P. Turvey <(E-Mail Removed)>
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      03-15-2008
On Mar 15, 2:49*pm, "Kenneth P. Turvey" <(E-Mail Removed)>
wrote:
> In a post to this newsgroup recently I mentioned that I've never seen
> source and target used where there was a difference in the values
> supplied. *..


I was scanning Lew's link when I noticed that
the page actually mentions the compiler itself
*presumes* different options for certain values
of -target. See the second and third items in
the bulleted list.

<http://java.sun.com/javase/6/docs/te...tools/solaris/
javac.html#crosscomp-options>

And I am (almost) certain that
- Not even language constructs such as foreach
can be back ported. (Though it would be
interesting to see an example that proves that.)
- Whatever the 1.6 compiler does that might be
better than earlier compilers (if anything),
will become redundant once the code is loaded
into a JRE.

--
Andrew T.
PhySci.org
 
Reply With Quote
 
Zig
Guest
Posts: n/a
 
      03-15-2008
On Fri, 14 Mar 2008 23:49:33 -0400, Kenneth P. Turvey
<(E-Mail Removed)> wrote:

> In a post to this newsgroup recently I mentioned that I've never seen
> source and target used where there was a difference in the values
> supplied. A reader on this newsgroup replied indicating that normally
> they were different in his application of them.
>
> I thought this was interesting since I would very much like to be able to
> target 1.3 or 1.4 class files using source code that included the 1.5
> changes, including the new looping construct and the assert keyword (I
> know that generics won't work). Even if I couldn't get these later
> language constructs, one would expect that the 1.6 compiler would do a
> better job than the 1.3 or 1.4 one would.
>


I think the "-source" exists in order to make the compiler aware that the
source code was written in a version older than the language itself.
Namely, -source 1.3 should allow you to correctly compile any code still
using variables named "assert" or "enum".

I guess Sun's compiler doesn't permit a source attribute > your target
attribute. For the most part newer language features do require the newer
VM (foreach needs method definitions on java.lang.Iterable), though
foreach on an array could work in theory. You might could find another
compiler besides Sun's that can do this, but I guess Sun didn't see much
value in this support?

HTH,

-Zig
 
Reply With Quote
 
Kenneth P. Turvey
Guest
Posts: n/a
 
      03-15-2008
On Fri, 14 Mar 2008 21:44:40 -0700, Andrew Thompson wrote:

[Snip]
> - Whatever the 1.6 compiler does that might be
> better than earlier compilers (if anything),
> will become redundant once the code is loaded
> into a JRE.


Maybe not. The compiler might make optimizations in generating the
classfile that the JRE wouldn't know how to make.

--
Kenneth P. Turvey <(E-Mail Removed)>
 
Reply With Quote
 
Kenneth P. Turvey
Guest
Posts: n/a
 
      03-15-2008
On Sat, 15 Mar 2008 01:01:40 -0400, Zig wrote:

[Snip]
> I think the "-source" exists in order to make the compiler aware that
> the source code was written in a version older than the language itself.
> Namely, -source 1.3 should allow you to correctly compile any code still
> using variables named "assert" or "enum".


Disappointing, but I guess it makes sense. I guess I can still use the
later version of the compiler even if my source isn't able to use the
modern 1.5 features.

> I guess Sun's compiler doesn't permit a source attribute > your target
> attribute. For the most part newer language features do require the
> newer VM (foreach needs method definitions on java.lang.Iterable),
> though foreach on an array could work in theory. You might could find
> another compiler besides Sun's that can do this, but I guess Sun didn't
> see much value in this support?


I guess the people at Sun haven't been writing applets.


--
Kenneth P. Turvey <(E-Mail Removed)>
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      03-15-2008
What would the poor compiler do with a 1.6 annotation? with a -target
1.4? There is no support for it in the 1.4 class file format.

There are actually only a small number of legal combinations. My rules
of thumb are posted at http://mindprod.com/jgloss/javacexe.html

--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      03-15-2008
On Sat, 15 Mar 2008 01:01:40 -0400, Zig <(E-Mail Removed)> wrote,
quoted or indirectly quoted someone who said :

>I guess Sun's compiler doesn't permit a source attribute > your target
>attribute


I think that is generally true, but when target is 1.1 or 1.2 you have
to set source to 1.3.
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      03-15-2008
On Mar 15, 5:13*pm, "Kenneth P. Turvey" <(E-Mail Removed)>
wrote:
> On Sat, 15 Mar 2008 01:01:40 -0400, Zig wrote:
>
> [Snip]

...
> > I guess Sun's compiler doesn't permit a source attribute > your target
> > attribute. For the most part newer language features do require the
> > newer VM (foreach needs method definitions on java.lang.Iterable),
> > though foreach on an array could work in theory. You might could find
> > another compiler besides Sun's that can do this, but I guess Sun didn't
> > see much value in this support?

>
> I guess the people at Sun haven't been writing applets. *


Not only have they been shying away from writing
applets, they also seem to have gone through a
process of removing most of them from their site.

But I am curious as to what you meant by that.

What target version (for the applets) are you
talking about? Why that version?

--
Andrew T.
PhySci.org
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ant javac : How to print classpath? Ronald Fischer Java 1 09-19-2003 01:13 AM
Re: Problem with ant's javac task z3 Java 0 07-23-2003 06:39 PM
javac doesn't show decprecated API calls to me Richard Ivarson Java 1 07-14-2003 03:33 PM
Re: JDK 1.4.2 javac compiler bug with final local variables? Jon Skeet Java 5 07-04-2003 03:17 PM
Sun JDK 1.4.2 javac compiler bug xarax Java 1 07-02-2003 05:08 PM



Advertisments