What is inside com.sun package?

It contains Sun Oracle reference implementations of the standard Java (EE) APIs. Among others Mojarra (the reference JSF implementation of Oracle) and Glassfish (the reference Java EE implementation of Oracle) use this package. It’s preferable to not use those classes directly in your code as it would make your code tight coupled to the implementation. Coding against the java(x) API directly enables you to change the implementation without changing your code (e.g. MyFaces instead of Mojarra and JBoss AS instead of Glassfish). Also JDK’s own HttpServer sits in the com.sun.* package, see Simple HTTP server in Java using only Java SE API.

Please note that the com.sun.* package should not be confused with sun.* package which are the internal classes behind Oracle JRE which you should absolutely not import/use in your code as it would make your code tight coupled to the JRE make/version. Not using sun.* package at all enables you to run your code on all other JRE implementations (OpenJDK, GCJ, etc).

Leave a Comment