Java
Javax
Programming
Software Development
Java Packages

javax vs java package

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

java and javax are both package prefixes in the Java ecosystem, but they do not mean "core" versus "non-core" in any strict technical sense. Historically, java.* held the main platform APIs, while javax.* was used for Java extensions and later for many enterprise and standard APIs that still became widely used.

What java.* Usually Represents

Packages under java.* are the foundational Java platform APIs. These are the classes most developers use constantly for collections, strings, I/O, concurrency, and networking.

Examples include:

  • 'java.lang'
  • 'java.util'
  • 'java.io'
  • 'java.time'

A simple example:

java
1import java.time.LocalDate;
2import java.util.List;
3
4public class Example {
5    public static void main(String[] args) {
6        List<String> names = List.of("Ada", "Linus");
7        System.out.println(LocalDate.now());
8        System.out.println(names);
9    }
10}

When people say "the Java standard library", they often think first of java.* packages because they contain the most obviously central APIs.

What javax.* Historically Represented

javax.* originally stood for Java extensions, but over time it became home to many APIs that were effectively standard in real-world Java development. Examples included:

  • 'javax.servlet'
  • 'javax.persistence'
  • 'javax.validation'
  • 'javax.xml'

For example, older servlet code often looked like this:

java
1import java.io.IOException;
2import javax.servlet.http.HttpServlet;
3import javax.servlet.http.HttpServletRequest;
4import javax.servlet.http.HttpServletResponse;
5
6public class ExampleServlet extends HttpServlet {
7    @Override
8    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
9        resp.getWriter().write("Hello");
10    }
11}

So while javax.* was not simply "core Java", it was also not some obscure third-party namespace. Many important APIs lived there for years.

The Jakarta Transition Changed the Picture

A major source of confusion today is that many enterprise APIs formerly under javax.* moved to jakarta.* after the Java EE transition to the Eclipse Foundation.

That means older code may import:

java
import javax.persistence.Entity;

while newer Jakarta-based code imports:

java
import jakarta.persistence.Entity;

This is not just a cosmetic rename. Framework compatibility matters. Mixing javax.* and jakarta.* dependencies in the same application often causes painful classpath problems during migration.

How to Think About the Difference Today

A practical rule is:

  • 'java.* is the long-standing base platform namespace'
  • 'javax.* contains older extension and enterprise-era APIs'
  • 'jakarta.* is the modern home for many former Java EE APIs'

So if you are reading older tutorials or maintaining legacy code, javax.* is normal. If you are starting new enterprise Java work on current stacks, you will often see jakarta.* instead.

Common Pitfalls

The biggest mistake is assuming javax.* always means third-party or unofficial. Many javax.* APIs were standard parts of mainstream Java application development for a long time.

Another common issue is mixing javax.* and jakarta.* artifacts without understanding framework compatibility. A library compiled against one namespace does not automatically work with the other.

People also oversimplify the history and say "javax was for optional packages only". That description was closer to the original naming intent than to how the ecosystem actually evolved.

Finally, do not assume package prefix alone tells you whether an API is available in your runtime. Some javax.* APIs were never part of every JDK distribution in the same way as java.lang or java.util.

When migrating older enterprise applications, always check your framework version first. The right namespace is often determined by the surrounding platform rather than by personal preference.

Summary

  • 'java.* contains the main Java platform APIs.'
  • 'javax.* historically held Java extension and many widely used enterprise-oriented APIs.'
  • Many former javax.* enterprise APIs have moved to jakarta.*.
  • Do not mix javax.* and jakarta.* dependencies casually in one application.
  • Read package names in historical context, not as a strict "official versus unofficial" split.

Course illustration
Course illustration

All Rights Reserved.