When to use java.* and jdk.* packages

Viewed 60

I'm using IntelliJ and JDK 11. In the library packages, I see two types of package naming. java.* and jdk.* like shown in the below image:

enter image description here

The jdk.* packages have sun.* packages inside them. What does this mean to developers? Is the general advice to avoid using jdk.*/sun.* as written over here: https://www.oracle.com/java/technologies/faq-sun-packages.html ?

1 Answers

You are misreading: these are not packages, but modules.

You should use java.* modules and avoid jdk.* because their access/api are not guaranteed to be stable. sun (and com.sun.*) are mostly moved into jdk.* modules.

This all boils down to the JEPs:

The modular structure of the JDK implements the following principles:

  • Standard modules, whose specifications are governed by the JCP, have names starting with the string "java.".

  • All other modules are merely part of the JDK, and have names starting with the string "jdk.".

Related