javax 与 java 包

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/727844/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 18:46:13  来源:igfitidea点击:

javax vs java package

java

提问by Jaka Jan?ar

What's the rationale behind the javax package? What goes into java and what into javax?

javax 包背后的基本原理是什么?什么进入了java,什么进入了javax?

I know a lot of enterprise-y packages are in javax, but so is Swing, the new date and time api (JSR-310) and other J2SE packages.

我知道很多企业级包都在 javax 中,但 Swing、新的日期和时间 api (JSR-310) 和其他 J2SE 包也是如此。

采纳答案by Jon Skeet

I think it's a historical thing - if a package is introduced as an addition to an existing JRE, it comes in as javax. If it's first introduced as partof a JRE (like NIO was, I believe) then it comes in as java. Not sure why the new date and time API will end up as javaxfollowing this logic though... unless it will also be available separately as a library to work with earlier versions (which would be useful). Note from many years later: it actually ended up being in javaafter all.

我认为这是一个历史性的事情 - 如果一个包作为现有 JRE 的补充被引入,它会以javax. 如果它首先作为JRE 的一部分引入(我相信就像 NIO 那样),那么它会以java. 不知道为什么新的日期和时间 API 最终会javax遵循这个逻辑......除非它也可以作为库单独使用以与早期版本一起使用(这会很有用)。多年后的笔记:它实际上最终进入java了。

I believe there are restrictions on the javapackage - I think classloaders are set up to onlyallow classes within java.*to be loaded from rt.jaror something similar. (There's certainly a check in ClassLoader.preDefineClass.)

我相信对java包有限制- 我认为类加载器被设置为允许java.*rt.jar或类似的东西中加载类。(肯定有签到ClassLoader.preDefineClass。)

EDIT: While an official explanation (the search orbfish suggested didn't yield one in the first page or so) is no doubt about "core" vs "extension", I still suspect that in many cases the decision for any particular package has an historical reason behind it too. Is java.beansreally that "core" to Java, for example?

编辑:虽然官方解释(建议的搜索 orbfish 在第一页左右没有产生)毫无疑问是关于“核心”与“扩展”的,但我仍然怀疑在许多情况下,任何特定包的决定都有背后的历史原因也是如此。例如,这java.beans真的是 Java 的“核心”吗?

回答by duffymo

javapackages are base, and javaxpackages are extensions.

java包是基础javax包是扩展。

Swing was an extension because AWT was the original UI API. Swing came afterwards, in version 1.1.

Swing 是一个扩展,因为 AWT 是最初的 UI API。Swing 是在 1.1 版之后出现的。

回答by Vineet Reynolds

The javax namespace is usually(that's a loaded word) used for standard extensions, currently known as optional packages. The standard extensions are a subset of the non-core APIs; the other segment of the non-core APIs obviously called the non-standard extensions, occupying the namespaces like com.sun.* or com.ibm.. The core APIs take up the java.namespace.

javax 命名空间通常(这是一个加载的词)用于标准扩展,目前称为可选包。标准扩展是非核心 API 的一个子集;非核心 API 的另一部分显然称为非标准扩展,它们占用了 com.sun.* 或 com.ibm 之类的名称空间。. 核心 API 占用了 java. 命名空间。

Not everything in the Java API world starts off in core, which is why extensions are usually born out of JSR requests. They are eventually promoted to core based on 'wise counsel'.

并非 Java API 世界中的一切都始于核心,这就是为什么扩展通常产生于 JSR 请求的原因。他们最终根据“明智的建议”晋升为核心。

The interest in this nomenclature, came out of a faux pas on Sun's part - extensions could have been promoted to core, i.e. moved from javax.* to java.* breaking the backward compatibility promise. Programmers cried hoarse, and better sense prevailed. This is why, the Swing API although part of the core, continues to remain in the javax.* namespace. And that is also how packages get promoted from extensions to core - they are simply made available for download as part of the JDK and JRE.

对这种命名法的兴趣源于 Sun 的失职——扩展本可以提升到核心,即从 javax.* 移动到 java.* 打破了向后兼容性承诺。程序员哭得沙哑,理智占了上风。这就是为什么 Swing API 虽然是核心的一部分,但仍然保留在 javax.* 命名空间中的原因。这也是包从扩展升级到核心的方式——它们只是作为 JDK 和 JRE 的一部分可供下载。

回答by TofuBeer

Originally javaxwas intended to be for extensions, and sometimes things would be promoted out of javaxinto java.

最初javax是为了扩展,有时东西会被提升javax到java中。

One issue was Netscape (and probably IE) limiting classes that could be in the java package.

一个问题是 Netscape(可能还有 IE)限制了可能在 java 包中的类。

When Swing was set to "graduate" to javafrom javaxthere was sort of a mini-blow up because people realized that they would have to modify all of their imports. Given that backwards compatibility is one of the primary goals of Java they changed their mind.

当 Swing 被设置为javajavax那里“毕业”时,有点小麻烦,因为人们意识到他们将不得不修改所有的导入。鉴于向后兼容性是 Java 的主要目标之一,他们改变了主意。

At that point in time, at least for the community (maybe not for Sun) the whole point of javaxwas lost. So now we have some things in javax that probably should be in java... but aside from the people that chose the package names I don't know if anyone can figure out what the rationale is on a case-by-case basis.

在那个时候,至少对于社区(可能不是对于 Sun)来说,整个点javax都丢失了。所以现在我们在 javax 中有一些可能应该在java......但除了选择包名称的人之外,我不知道是否有人可以根据具体情况弄清楚其基本原理是什么。

回答by Lakshmi Prasanna

java.* packages are the core Java language packages, meaning that programmers using the Java language had to use them in order to make any worthwhile use of the java language.

java.* 包是核心 Java 语言包,这意味着使用 Java 语言的程序员必须使用它们才能对 java 语言进行任何有价值的使用。

javax.* packages are optional packages, which provides a standard, scalable way to make custom APIs available to all applications running on the Java platform.

javax.* 包是可选包,它提供了一种标准的、可扩展的方式,使 Java 平台上运行的所有应用程序都可以使用自定义 API。

回答by Miroslav

Javax used to be only for extensions. Yet later sun added it to the java libary forgetting to remove the x. Developers started making code with javax. Yet later on in time suns decided to change it to java. Developers didn't like the idea because they're code would be ruined... so javax was kept.

Javax 过去仅用于扩展。然而后来sun将它添加到java库中忘记删除x。开发人员开始使用 javax 编写代码。然而后来suns决定将其更改为java。开发人员不喜欢这个想法,因为他们的代码会被破坏……所以保留了 javax。

回答by m.r226

Some packages like javax.swingwere not included in java standard library at first. Sun company decided to consider them official and included them into the early versions of java as standard libraries or standard extensions.

一些包,比如javax.swing最初没有包含在 java 标准库中。Sun 公司决定将它们视为正式版本,并将它们作为标准库或标准扩展包含在 Java 的早期版本中。

By convention, all the standard extensions start with an Xwhile they can get promoted to first-class over time like what happened for javax.swing.

按照惯例,所有标准扩展都从一段X时间开始,随着时间的推移,它们可以像javax.swing.