Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why import javax.swing.* instead of java.swing.*

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.*?

like image 791
giri Avatar asked Jan 05 '10 08:01

giri


People also ask

Why do we import javax swing?

swing. Provides interfaces that enable the development of input methods that can be used with any Java runtime environment. Provides a set of "lightweight" (all-Java language) components that, to the maximum degree possible, work the same on all platforms.

What is meant by Javax Swing in Java?

Java Swing is a lightweight Java graphical user interface (GUI) widget toolkit that includes a rich set of widgets. It is part of the Java Foundation Classes (JFC) and includes several packages for developing rich desktop applications in Java.

What has replaced Java Swing?

JavaFX was intended to replace Swing as the standard GUI library for Java SE, but it has been dropped from new Standard Editions while Swing and AWT remain included, supposedly because JavaFX's marketshare has been "eroded by the rise of 'mobile first' and 'web first applications." With the release of JDK 11 in 2018, ...

Is Swing still used in Java 2021?

Absolutely yes. Legacy swing applications are still supported and enhanced.


2 Answers

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.

like image 173
Jon Skeet Avatar answered Sep 28 '22 11:09

Jon Skeet


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 as com.sun.java.swing, then briefly got moved to java.awt.swing during early Java 2 beta versions, then went back to com.sun.java.swing in late Java 2 beta versions, and after howls of protest by Java programmers, found its final resting place in javax.swing.)

like image 26
JRL Avatar answered Sep 28 '22 12:09

JRL