Official announcement of Java and the GPL

Bryan Sant bryan.sant at gmail.com
Tue Nov 14 09:21:15 MST 2006


On 11/13/06, Michael Torrie <torriem at chem.byu.edu> wrote:
> Note how the Java syntax is a bit more awkward.  The good news is that
> if you use the right tools you need never worry about this stuff.  In
> GTK, for example, you can use Glade to build the gui and then use Glade
> classes in C# or Java to build the gui and automatically set up the even
> callbacks.  Most people build Swing guis using a GUI builder which sets
> up all the listener classes for you.

Java's syntax is more awkward, and though GUI builders will do the
work for you, it's still an obvious feature that should exist in the
language.  Method delegates were proposed for Java before they were
implemented in .NET.  That doesn't mean anything, .NET did it first,
but Java decided not to implement them so as to keep the language
syntax consistent with prior versions.  Java 5 was the first Java to
introduce new language features (no doubt pushed by C#).  That release
has been well accepted by the Java community, and now the door is open
for more expansion of the language.  As mentioned before, Java 7 (Java
6 is about to be released -- no new langauge features) will have
delegates and closures.

> I hope Bryan will clarify my comments and also answer this question on
> generics, since my understanding of it all is not so great.
>
> Michael

The concept of Java and C# generics is like templates in C++.  If you
understand C++ templates, then you understand how generics should
work.  The difference being that C++ and C# turn something generic
into something specific at compile time, while Java does so at
runtime.  It's the difference between a "static cast" in C++ and a
"dynamic cast" in C++.  Java's generics do the later.  To the Java or
C# developer the difference doesn't matter at all.  You use them the
same, but the C# and C++ static casts will be slightly faster than
runtime dynamic casts that Java does.

Here is some java 5 code using generics:

List<String> strList = new ArrayList<String>();
strList.add("Hello World!");
String s = strList.get(0);

Here is some java 2 code (no generics):

List strList = new ArrayList();
strList.add("Hello World!");
String s = (String) strList.get(0);

Both of these code snippets compile into exactly the same byte-code.
Java 5 is actually doing the dynamic casting.  With C++ templates or
C# generics the language actually makes a custom version of ArrayList
on-the-fly that accepts and uses strings only.  Java dose it the way
it does it to keep things more backwards compatible.  Java 5 code
using generics could be run on a Java 1.4 JVM.

The primary criticism is that dynamic casting is slower than static
casting, this is true, however the difference in speed is so trivial,
that the Java designers didn't think it was worth breaking backwards
compatibility for an almost non-measurable increase in speed.

The debate is much ado about nothing.  Generics are used the same way
in both Java and C#, and the performance argument is a non-issue.
Even if there was a performance hit for generics in Java vs C#, Java
as a whole is faster than C# (on Linux AND on Windows), so your
software is faster overall anyway.

-Bryan



More information about the PLUG mailing list