Some basic questions about javax vs java packages

When I go to JavaDocs, I find some classes in the java package, while some of them are in javax . Then I came across javax vs java package .

What I get from this link, almost all of the answers are that the javax package is just an extension of the java library. I mean, the first Java must have had the core Java IE java libraries, but when another package appeared, it released javax . Right?

Some question that immediately comes to my mind as a developer. What are the implications of these named packages for the Java developer. Here are the questions and analysis: -

  • Even if I agree, javax is just an extension of the java core. But again, I see completely different packages, such as org.omg.CORBA , etc. Why is it called javax.omg.CORBA ?
  • Will packages like javax , org come with standard JDK and JRE downloads? Do I need to download them separately from JSE 1.6?
  • Does the classloader bootstrap load the classes in these packages by default, as is the case with Java base classes (e.g. java.lang ).
+6
source share
3 answers

I find this pretty arbitrary. As John Skeet says in his answer to the question you are referring to, most of it is historical. A good example of this is javax.sql - it contains JDBC-related classes that were originally part of J2EE, but which were added to J2SE in 1.4. So now there is a useless separation of classes between java.sql and javax.sql. There is no particular meaning associated with the java / javax section inside the JDK.

  • CORBA classes are where they are because they are not defined by the Java standard; they are translations of the interfaces defined in the CORBA specifications.
  • There are many javax packages. * that come with the standard J2SE JDK / JRE (javax.sql, javax.xml). There are also javax packages. * Which are not (javax.inject, javax.servlet, etc.). But there is no java. * Packages that are not in the JDK.
  • I believe the bootstrap bootloader loads java. * and javax. * classes.
+4
source

Historically, the idea was that java packages. * would be the ones sent along with the JDK, and the javax packages. * - These are the ones that need to be downloaded separately. He still works this way, to some extent; all java packages. * come with JDK, and there are many javax packages. *, for example, for servlets that need to be downloaded separately.

The monkey key was thrown into this circuit when Sun decided to move some javax. * Packages, such as Swing, in the main JDK. They were actually going to change the package name from javax.swing to java.swing, but when it became clear that it would break backward compatibility for a huge amount of code, they decided to move the packages instead, but keep javax. swing name. Thus, the name is no longer indicative, but exists for historical reasons.

I would not be surprised if this happened with the org.omg and org.w3c packages (these were third-party libraries that were moved to the main JDK and the names could not be changed). Regardless if it is in the JDK API docs, you can use it without loading anything other than the main JDK, and the class loader will find it in order.

+2
source
  • They often come from parties that are not Sun / Oracle. EG. The org.omg package was created (apparently) by people at http://omg.org/. Do you see a connection between the package name and the domain name?
  • No, if they are specified in J2SE JavaDocs for a specific version, they are included in the standard version of this version. Here are the packages available (by default included) J2SE versions 6 and 7 .
  • Yes, they are on the way to the class automatically. Try to import one of the classes and compile / run it to confirm it. OTOH note that they are similar to AWT classes ( Color , Font , etc.), where they can be imported, and not to the java.lang , whose classes should not have import in the code.

java.lang does not need to be imported. Is this because lang classes are used more often?

I guess, yes. Please note that this applies only to the compiler. Class files contain the fully qualified class name AFAIU.

+1
source

Source: https://habr.com/ru/post/909647/


All Articles