I did not understand why there is "x" appended to "java" for few of the import packages. What is the reason? Can't it be just java.swing.*
like others java.io.*
?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Swing was originally an extension to Java - a separately downloadable library. It became part of the "main" JRE in Java 1.2. It would have been odd for a separate library to have claimed a java.* package, hence the current situation. There are plenty of other extensions which have a similar story.
The Wikipedia article on Swing has a bit more information on its history.
The x was because they were extensions. In version 1.1 of java there was not swing and when it was added they decided to name it like that: javax
There are a number of packages with similar histories.
For historical reasons and backward compatibility. Before java 1.2 swing was distributed as an separate package from java (hence javax as extension).
When swing became part of standard java-distribution package name was kept for backward compatibility. More info in wikipedia article
From Core Java 2:
alt text http://bks5.books.google.fr/books?id=W6bomXWB-TYC&printsec=frontcover&img=1&zoom=5&edge=curl&sig=ACfU3U3IeRSfENUVokGf-d9GUZZBU-tYMQ
The name
javax
indicates a Java extension package, not a core package. The Swing classes are indeed an extension to Java 1.1. Because the Swing classes were not part of the core hierarchy, it is possible to load the Swing classes into a Java 1.1-compatible browser.(the security manager of the browser does not allow adding any packages that start with "java.
".) On the Java 2 platform, the Swing package is no longer an extension, but is instead part of the core hierarchy. Any Java implementation that is compatible with Java 2 must supply the Swing classes. Nevertheless, the javax name remains, for compatibility with Java 1.1 code. (Actually, the Swing package started out ascom.sun.java.swing
, then briefly got moved tojava.awt.swing
during early Java 2 beta versions, then went back tocom.sun.java.swing
in late Java 2 beta versions, and after howls of protest by Java programmers, found its final resting place injavax.swing
.)