Sneak Peak at Java's New Makeover
SadatChowdhury writes "Aside from templates as already reported in a past slashdot article , a little snooping around revealed the details of the following newly revealed features in the upcoming release of Java 1.5 (codenamed: Tiger) : Autoboxing , Enhanced-For-Loop, Enumerations and Static Imports . Must read for Java fans."
In related news: jdkane writes "Sun Microsystems delays a much-anticipated Java specification by three months to comply with guidelines designed to keep Web services interoperable. Says Ralph Galantine, group marketing manager for Java Web services at Sun: "We thought that this change was important for the industry, so that there was no conflict between J2EE 1.4 and the WS-I, "We thought it was worth taking out to the summer." It's very refreshing to hear that a big software company is looking out for the industry, instead of just their own."
Possibly the "most different" feature that will probably come in. Here.
I'm not too sure I like them, as they do add a completely new and different and more cryptic syntax to Java, but I can definitely see the use for them. No more clumsy casting when you retrieve something from a List.
Daniel
Carpe Diem
I am in awe of the new for() statement. Instead of all that fooling around with the C-style syntax (great for procedural, sucks for OO), they just go ahead and adapt it for collections much like iterators in other high-level languages: for (String s : c) { //do stuff on s's in c
}
Wheeeee!
ph34r teh p0w3r 0f th3 c0w
So, to summarize the changes:
...
...
...) construct. Second, (dolist ...). Third, (mapcar ...) and family. Four, defmacro, which makes these superficial things all seem kinda silly.
1) C-style enums, because Java is too weak to support a true symbol type.
2) Enhanced for-loop for iterations.
So:
for (String s : c) {
}
Is now shorthand for:
for (Iterator i = c.iterator(); i.hasNext(); ) {
String s = i.next();
}
They did this, of course, because it was the least obvious, most ugly way possible to add this to the language.
They said that it seemed "too late" to add a new keyboard to the language, but apparently not too late to add new syntax.
The principle of least surprise tells me that something along the lines of:
foreach (String s, myStringCollection) { }
might be a bit easier to read than their seemingly random for( : ) syntax.
3) Autoboxing to automate the wrapping of Java primitives in classes.
This seems to be because Java didn't want to go pure OO. They wanted to keep their primitives, and yet be mostly OO, which turns out to just be a pain in the ass and gives rise to classes like Integer and Double.
4) C++-Style Templates, because Java would now like to get even closer to their goal of being "Almost all the power of C++, without any of the speed." Templates are pretty much a bad idea in any language. They are a work-around for a bad type system.
But then, what the hell do I know. I'm just a Lisp junky.
For the curious, the Lisp solutions to these problems are, in order:
1) Symbols.
2) Too numerous to count. First, the (loop
3) What? Variables with types? I don't understand! Variables don't have types, values have types!
4) See #3, plus true generics in CLOS.
Justin
... a terse notation for anonymous inner classes with one method.
// do the operation // with a terse notation for one-method anonymous inner classes that could become
// do the operation });
anonoymous inner classes can be used a little bit like blocks in ruby, only the syntax for anonymous inner classes is so verbose. Imagine this:
ArrayList list = new ArrayList();
ArrayList list2 = list.map(new UnaryOperation() {
public object call(object o) {
});
ArrayList list2 = list.map({ |object o|
It may not be possible because the exact interface to implement in the anonymous inner class would have to be derived from the method being called, which might be overloaded.
Anyway, I'd love to be able to use the terse rubyesque style in java, it feels a lot more declarative and communicates much better than all the explicit looping in java, c, C++, C#, VB, VB.net etc.
Personal biases are, imho, always a good thing, as long as it's not BASIC. (sorry, couldn't resist)
The view here is that Java is by far *enforced* on most courses, although most lecturers I personally speak to seem to prefer Lisp/Scheme and C/C++ over Java. For instance, we had a course on data abstraction where the labs were in Java, but the lecturer taught in pseudo-code (claimed he didn't know any language other than C). Worked fine for me; I aced a project on image manipulation using only pseudo-code! B-)
More than mere navel gazing.
Most of the new language features are copying or implementing similar to the C# features Sun has persistently decryed!
... same as boxing in C#
... well both languages have/will have generics now ... still not 100% convinced but prefer to have them than not to have them ;-)
... C# has them same as C/Pascal, now suddenly Java is getting them (are they going to revisit the library and clean up a lot of their class constants into enums now??)
... being able to add custom metadata to any method/property, for example how to serialise to XML correctly, is great!!
... competition is great for Java!!!
Autoboxing
the for-iterator [for(Sting s: Collection)] statement is actually "nicer" (in that intent is clearer from the code) in C# [foreach(String s in Collection)]
Generics
Enumerations
I propose they go full how and add the extremely powerful attributes from C# as well
In short
I agree with you fully when it comes to VB and Java, but C# does not deserve to be lumped into this category. Everybody knows VB wasn't really "designed", it just sort of "happened" over the years. Java had a lot more design work behind it, but it still suffers from weird evolutionary lumps that always "feel wrong" when you're using it. However, C# went through a very long and intensive design period, with more well-defined goals than Java (the set-top-box language), and I believe with a LOT more R&D-phase input from the real world (as anybody who participated in Don Box's .NET listserv discussions can tell you).
C# is a lot like C in that the language itself is limited and well-defined, although not to the extreme basics of a 12-keyword universe like C, owing primarily to the additional keyword overhead needed to express certain modern concepts, many (most?) of which are OOP-related. In that sense it's a little like C++.
For an experienced programmer, the trick is to first understand the .NET class hierarchy (hint: avoid books that harp too heavily on web services buzzwords; web services are just a few pieces of the very large .NET puzzle). Next, understand the C# language on it's own. Most of the books out there seek to tackle both of them simultaneously, and that's a big hinderance to learning, and probably what causes people to make statements like that made by vandel405, above.
Don't judge the subject matter by the quality of instruction...
Slashdot quality declines as the number of hot grits posts decreases. - Provolt's Law, Apr-09-2005