• Post Reply Bookmark Topic Watch Topic
  • New Topic

Importing Swing and AWT

 
Suzie Russell
Greenhorn
Posts: 22
Android C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's consider the simplest Swing program that prints "Welcome",


Now, for importing AWT, i simply write it as java.awt.(Whatever), but for importing SWING I have to write "javax"? Why?
 
Bharvi Dixit
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Suzie, Because javax is an extension of java. Before java version 2 it was not included in the standard java library.
At that time packages like java.io, java.awt were shipped and they were part of the standard library.
All the standard extensions, by convention starts with an 'X' appended to the regular java package starter. 
In java all the packages which were not included in standard library are called extensions and mother of all these extensions was the swing library which includes many packages introduced later.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even though the reasons are historical, and somewhat obscure to begin with, the important point to take away is: for all practical purposes, there is no difference between java.* and javax.* packages that are part of the JRE.

Note that there are javax.* packages that are not part of the JRE, though -JavaSpeech, for example. Those need to be downloaded and installed separately. All java.* packages, on the other hand, are part of the JRE.
 
Bharvi Dixit
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Even though the reasons are historical, and somewhat obscure to begin with, the important point to take away is: for all practical purposes, there is no difference between java.* and javax.* packages that are part of the JRE.

Note that there are javax.* packages that are not part of the JRE, though -JavaSpeech, for example. Those need to be downloaded and installed separately. All java.* packages, on the other hand, are part of the JRE.


Is it because sun didn't considered those packages standard and not included officially in the JRE?? I am asking about the packages like -JavaSpeech as you mentioned.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the additional "x" stands for "extension". Lots of those extension packages have found their way into the JRE subsequently, not just Swing, but also others like JMX, JAF, JCE, JNDI, JAXP, JAX-WS etc. None of those was part of the JRE when they came out, but they are now.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!