javax vs java package

I think it’s a historical thing – if a package is introduced as an addition to an existing JRE, it comes in as javax. If it’s first introduced as part of a JRE (like NIO was, I believe) then it comes in as java. Not sure why the new date and time API will end up as javax following this logic though… unless it will also be available separately as a library to work with earlier versions (which would be useful). Note from many years later: it (date and time API) actually ended up being in java after all.

I believe there are restrictions on the java package – I think classloaders are set up to only allow classes within java.* to be loaded from rt.jar or something similar. (There’s certainly a check in ClassLoader.preDefineClass.)

EDIT: While an official explanation (the search orbfish suggested didn’t yield one in the first page or so) is no doubt about “core” vs “extension”, I still suspect that in many cases the decision for any particular package has an historical reason behind it too. Is java.beans really that “core” to Java, for example?

Leave a Comment

error code: 523