简体   繁体   English

Java版本和JVM之间的标记到底在哪里?

[英]Where is exactly is the demarkation between a version of Java and the JVM?

Where is exactly is the demarkation between a version of Java and the JVM? Java版本和JVM之间的标记到底在哪里?

I'm asking because of a recent 'educational' comment thread with a fellow SOpedian regarding the default buffer size of java.io.BufferedInputStream , which I see is 8192. (Has it always been 8192?) When thinking about just the API, it is clear to be what is what. 我之所以问是因为最近有一个“教育性”注释线程与SOpedian一起讨论了java.io.BufferedInputStream的默认缓冲区大小,我看到的是8192。(一直是8192吗?)仅考虑API时,很明显是什么。 But with the implementation of a java.* class...I just don't know. 但是随着执行 java.*类...我只是不知道。

This leads to two derivative questions: 这导致两个派生问题:

  • Could BufferedInputStream 's default buffer size change between versions of Java? BufferedInputStream的默认缓冲区大小可以在Java版本之间更改吗?
  • Could BufferedInputStream 's default buffer size be different on various vendor's JVMs? 各个供应商的JVM上BufferedInputStream的默认缓冲区大小是否可以不同?

(Surely there are other similar examples, like in the implementation of various collections.) (当然,还有其他类似的示例,例如在实现各种集合时。)

Since the API specification of BufferedInputStream doesn't specify a value, it is entirely up to the implementation to choose one. 由于BufferedInputStream的API规范未指定值,因此完全取决于实现来选择一个值。

This means that the default buffer size can change between Java versions as well as between different implementations of the same Java specification. 这意味着默认缓冲区大小可以在Java版本之间以及同一Java规范的不同实现之间进行更改。

It's pretty much the same in other areas: the real specification is the documentation (ie JLS, JVM Specification and API specification, or rather the corresponding JCPs). 在其他方面几乎是相同的:真正的规范是文档(即JLS,JVM规范和API规范,或者相应的JCP)。

Everything else (ie everything you can see from looking at the source) is an implementation detail and depending on it is a bug. 其他所有内容(即,从源代码中可以看到的所有内容)都是实现细节,并且取决于它是一个错误。

"Java" is a language and API specification. “ Java”是一种语言和API规范。 The JVM is covered by a completely different specification, which describes the format of a class file and the way that bytecode works. JVM由完全不同的规范涵盖,该规范描述了类文件的格式以及字节码的工作方式。

To be called "Java," an implementation must pass a series of tests defined by Sun and the JCP. 要被称为“ Java”,实现必须通过Sun和JCP定义的一系列测试。 These tests say nothing about the internal implementation of the API or JVM. 这些测试没有提及API或JVM的内部实现。

The implementation of the API can and does change between revisions, in response to bug reports and general cleanup. 该API的实现可以并且确实会在版本之间进行更改,以响应错误报告和常规清理。

Basically the line is the specification, which is mostly in the Java doc. 基本上,这行是规范,这主要是Java文档中的内容。 The specification outlines a contract for the API and an implementation would have to honor that contract. 该规范概述了API的合同,并且实现必须遵守该合同。 What the contract does not specify would be up to the implementation. 合同未指定的内容取决于实施情况。

Of course, in practice no specification is perfect, so there are practical details that get relied on even if they are not specified. 当然,在实践中,没有一个规范是完美的,因此即使没有指定,也要依靠一些实际细节。 Joel Spolsky has a good article on it, although in Java things are much better than in W3C. Joel Spolsky上有一篇不错的文章 ,尽管Java中的情况比W3C中的要好得多。

Java is the language. Java是语言。 There's a specification for that. 有一个规范。
The JVM is a piece of software than can execute Java bytecodes.There's a specification for that. JVM是一种可以执行Java字节码的软件,它有一个规范。
There are many implementations of the JVM (Sun's, IBM's and various mini versions for phones etc.), and there are many implementations of Java. JVM有许多实现(Sun的,IBM的以及电话的各种微型版本等),还有Java的许多实现。
The Java language may compile to bytecode, but it doesn't have to, it could compile to IL (for the .Net CLR) or to native code or to anything else. Java语言可以编译为字节码,但不是必须的,它可以编译为IL(对于.Net CLR)或本机代码或其他任何东西。
The JVM does not have to run Java applications, see for example Jython and JRuby and many other examples JVM不必运行Java应用程序,例如参见Jython和JRuby以及许多其他示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM