I want to understand if package com.sun.net.httpserver
is standard and required by all Java implementations or only OpenJDK-specific? I checked and even OpenJDK 13 includes it and it was there since Java 6. Documentation for those classes is public, so it seems like official, yet its package name looks like something proprietary.
2 Answers
This is now clearly a public API1. As of Java 11, there is a module (jdk.httpserver) that exports the com.sun.net.httpserver
and com.sun.net.httpserver.spi
packages and 17 public classes.
The javadocs are published (https://docs.oracle.com/en/java/javase/11/docs/api/jdk.httpserver/com/sun/net/httpserver/package-summary.html) and there are no visible caveats in the package summary to say that these APIs are intended for internal use only.
While the jdk.httpserver
is standardized, it is not guaranteed2 to be present in all (Java 11+) Java SE implementations. As the Overview page says:
This document is divided into two sections:
Java SE: The Java Platform, Standard Edition (Java SE) APIs define the core Java platform for general-purpose computing. These APIs are in modules whose names start with
java
.JDK: The Java Development Kit (JDK) APIs are specific to the JDK and will not necessarily be available in all implementations of the Java SE Platform. These APIs are in modules whose names start with
jdk
.
The module we are are talking about falls into the second category.
1 - The old (inconsistent) package name conventions about com.sun.*
and so on are mooted by Java 9+ modules and their associated explicit visibility control mechanisms.
2 - Oracle and most other publishers of Java 11+ only provide JDK distributions, so this caveat is largely moot.
-
3The
jdk.*
modules are not required to be present in a Java SE implementation, though. Realistically almost all deployments of recent Java versions will use the JDK (given that Oracle no longer publishes JREs), but it's not strictly required. Nov 8, 2019 at 10:50 -
1Yes ... but ... someone might decide that it is in their interest to create a JRE build that leaves out "non-essential" modules. Oct 24, 2022 at 11:08
Modules that are not defined in the Java SE 9 Platform Specification but instead specific to the JDK will, by convention, share the “jdk.” name prefix.
Source: The State of the Module System / Platform Modules
It means it's available in full JDK distribution but you will have to require it in module-info.java
when using modules (with or without jlink).