But this post isn’t about that. As the examples became more involved I realized I was having to do a lot of guessing with regard to syntax, and that I was probably missing the point of the Android examples due to that. So I poked around a small bit and found Sun’s excellent primer, Trail: Learning the Java Language.
As someone who has done PHP programming for years and has never once done anything Java, I found some surprises….
Redundant Language Is Redundant
Static typing means you have to be so overly-verbose that statements like this are necessary: Bicycle myBike = new Bicycle(30, 0, 8);
You can create multiple methods with the same name, and the compiler will consider them unique if they have different parameter counts/types. No possibility of human error there…
Method signatures mean you can have multiple constructors which is just astonishing to me. This seems as if it would encourage building classes that do too much. No?
Not explicitly declaring an access level modifier for a class or member means it will be considered package-private, which is basically public within a namespace (Java package). I think I prefer PHP’s way, where not declaring an access level leaves a member public. (Though maybe that’s changed with the recent introduction of namespaces.)
…Wow. I can see where this might be useful, but this is something wholly new to me. There is no analogue in PHP
A built-in enum type? Cool!
You can extend interfaces! Now that’s cool. You don’t have to go back and revise all classes that implement the interface, just extend it and use the extended interface.
…What? Really? WHY?
Primitive Types As Objects
This is actually pretty cool, and having some experience with Ruby, I like the idea of basic types being objects so I’m tempted to just use Number and subclasses rather than the primitive types all the time. Boxing/unboxing is awesome.
Seemed like a lot of bother initially but the flexibility of the system seems well thought-out and useful.
It’s still hard to get over how redundantly verbose Java is, and how far from readable English it is. But I’m excited to see where it takes me with respect to Android and perhaps GWT.