tags:

views:

91

answers:

4

Where is exactly is the demarkation between a version of Java and the 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. But with the implementation of a java.* class...I just don't know.

This leads to two derivative questions:

  • Could BufferedInputStream's default buffer size change between versions of Java?
  • Could BufferedInputStream's default buffer size be different on various vendor's JVMs?

(Surely there are other similar examples, like in the implementation of various collections.)

+1  A: 

Basically the line is the specification, which is mostly in the Java doc. The specification outlines a contract for the API and an implementation would have to honor that contract. 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.

Yishai
+5  A: 

Since the API specification of BufferedInputStream doesn't specify a value, it is entirely up to the implementation to choose one.

This means that the default buffer size can change between Java versions as well as between different implementations of the same Java specification.

It's pretty much the same in other areas: the real specification is the documentation (i.e. JLS, JVM Specification and API specification, or rather the corresponding JCPs).

Everything else (i.e. everything you can see from looking at the source) is an implementation detail and depending on it is a bug.

Joachim Sauer
Thanks. This has only wetted my appetite for information on the history of `BufferedInputStream`. In the JavaDocs for JDK1.1 it explicitly states that the default buffer is 512KB, but any reference to the default size is gone from their on out. Interesting stuff.
Stu Thompson
+2  A: 

"Java" is a language and API specification. The JVM is covered by a completely different specification, which describes the format of a class file and the way that bytecode works.

To be called "Java," an implementation must pass a series of tests defined by Sun and the JCP. These tests say nothing about the internal implementation of the API or JVM.

The implementation of the API can and does change between revisions, in response to bug reports and general cleanup.

kdgregory
A: 

Java is the language. There's a specification for that.
The JVM is a piece of software than can execute Java bytecodes.There's a specification for that.
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.
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.
The JVM does not have to run Java applications, see for example Jython and JRuby and many other examples

Kevin Jones