简体   繁体   中英

Where are the implementation details of Java located within the JDK?

I have asked my peers and I have found various different answers, so which has led me to ask here. I apologize if this is a very simple question, but where are the implementation details or built in classes located at in Java? I have heard that the compiler will hold the implementation details of Java. However, I have also heard how the JRE will have the classes or details of the implementation for Java, specifically the rt.jar. I originally thought that the java standard library would have all the details to run java and be able to write java code since it comes with the java.lang package, which carries classes that are fundamental to the design of the Java programming language. Sorry for the confusion, but is there a clear answer to this. Is it possible that multiple of these things hold such info.?

Where are the implementation details or built in classes located at in Java?

The implementation details are... everything. The entire Java JRE or JDK installation is implementation details. You could say... everything in the OpenJDK source tree is implementation details.

The builtin (Java) classes that comprise the Java SE class libraries are in different places depending on the Java version.

  • For Java 8 and earlier, the compiled classes for the Java SE class libraries are in the "rt.jar" file. Additional classes (for example the JDK tools) are in other JAR files.

  • For Java 9 and later, the compiled classes are stored in the "jmods" directory. These are no longer JAR files.

Note that "rt.jar" (+ other JARs) and the "jmods" directory are not the complete implementation:

  • Some Java SE classes have native methods which are implemented in native (C or C++) code. Classloading, threads and low-level I/O support are examples of this.

  • Much of the Java runtime implementation does not have any direct relation with any Java classes. For example, the bytecode interpreter, the JIT compiler and the garbage collector, along with the various agent and monitoring hooks are implemented in C / C++ and (typically) part of the main java executable.


I have heard that the compiler will hold the implementation details of Java.

That is not correct. The compiler has a small amount of built-in knowledge of the signatures for some classes in the java.lang package. However, in most cases a Java compiler loads ".class" files from "rt.jar" or "jmods" or wherever.


I originally thought that the java standard library would have all the details to run java and be able to write java code since it comes with the java.lang package, which carries classes that are fundamental to the design of the Java programming language.

That is certainly not true.

Besides you are conflating lots of things. Firstly, you are conflating design and implementation. They are different things. Really.

  • The design is documents: specifications, javadocs and so on.
  • The implementation is code, written in (at least) 3 programming languages.

Secondly, you are conflating the design of the Java language with the design of the Java runtime system . In reality, the design has many parts:

  • The Java language... specified in the JLS.
  • The Java Virtual Machine... specified in the JVMS.
  • The Java SE class libraries... specified in the Java SE javadocs.
  • Various other aspects of the design... specified in other documents.

It is worth noting that the respective specifications are separable to a significant degree:

  • You can implement the Java language without the JVM spec; eg Android used Dalvik and then ART.
  • You can implement other programming languages on top of the JVM spec; eg by writing a compiler that emits JVM bytecodes.
  • You could implement the Java language with class libraries that have nothing in common with the Java SE libraries.

Finally, as explained above, most of the implementation of the JLS and JVMS is in native code and (to a lesser extent) Java classes that are not formally 1 part of the Java SE class library.


Would it be safe to say that the java.lang basically provides the barebones of the java language?

No. See above. The design of the Java language (its syntax and semantics) are in the JLS. The implementation (which maps the design to something that works) comprises the Java bytecode compiler, bytecode interpreter, JIT compiler and so on.

If you really want to understand how this all works, you should start by downloading the OpenJDK source tree. All of the code is in there...


1 - I am talking here about "internal" classes, and classes that (in Java 8 and earlier) were part of "tools.jar". For example, the Java source code for the javac bytecode compiler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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