A thought occurred to me a while ago, and since the initial thought, I haven’t been able to shake it. Ergo, you, dear readers, can be my catharsis for helping me to rid myself of this thought once and for all.
I’ve not been able to figure out why Java is a statically typed language. There just doesn’t seem to be much logic to why Java chose this path when it was created. Now, I’m not trying to start the usual Static vs. Dynamic typing wars (I understand both of those arguments quite well), but the argument of why Java eludes me. Since Java has the virtual machine (VM), it doesn’t have the same reasons that C or C++ have for static typing (namely the type needs to conform to a physical piece of memory in some fashion). But, since Java has no such constraints, so the reasons for having static types in Java seem more a case of dogmatic adherence rather than anything technical. Now, this is also without much knowledge of how the Java VM really works. Is there something in the way the VM is modeled that causes static typing to be preferred (or even required?)
Inquiring minds want to know!
When Java came out, it benchmarked about about 300x slower than C. Performance has improved dramatically since then. Current systems (just in time compiling, and such) benchmark at about 3x slower than C. My guess is that runtime checking of variable types would make it impossible to have reasonable performance. Given that settop java boxes and other embedded applications were envisioned, performance like this had to have been a goal.
So, what was the design goal for Java? I think Gosling wanted a programming language with garbage collection to eliminate memory management bugs, provides objects to get small scopes for variables, provide a namespace collision strategy that always works, in a package that is small enough to work anywhere. In my opinion, only this last bit – small was a total failure.