Learning Java After PHP

java php

Sat Aug 15 02:44:00 -0400 2009

My interest in smartphone development finally breached a level where I felt compelled to download the Android SDK and buy the Hello, Android book.

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);

Method Signatures

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…

Constructor(s!)

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?

package-private

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.)

Inner Classes

…Wow. I can see where this might be useful, but this is something wholly new to me. There is no analogue in PHP

Enums

A built-in enum type? Cool!

Interface Heirarchies

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.

Casting Objects

…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.

Generics

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.

blog comments powered by Disqus