I have installed my own JDK 8 at folder Java\jdk1.8.0_152. Eclipse allows us to specify the Java compiler from Window/Preferences/Java/Compiler. If I specify the compiler version 1.8 (see below), which compiler is actually used by Eclipse, my own installed JDK located at Java\jdk1.8.0_152 or Eclipse's own bundled JDK? What's the difference between these two compilers?
Please correct me if I am wrong. My second question is that when we specify installed JREs for Eclipse (Window/Preferences/Java/installed JREs), we must specify our own installed JREs, because Eclipse does not include any JRE. Am I right?
Note, this question is not off-topic due it does not ask to recommend or find a book, tool, software library, tutorial or another off-site resource, but rather the meaning of a specific compiler setting. Does it switch the compiler, does it delegate the setting to the JDK compiler (so that the meaning can be found there) or does it mean something else? To produce the same bytecode on two different computers, you need to know that.
Eclipse has its own Java compiler, which is called [JDT Core][1] (org.eclipse.jdt.core). The compiler itself is included in the org.eclipse.jdt.core plugin. Eclipse won't use any user installed JDK. Instead it uses its own JDT core to compile Java program due to the following primary reason:
The primary reason is that JDT core has the ability of incremental compilation, which means that it incrementally compiles changes in your code (this is also why Eclipse does not need a compilation button because it automatically compiles when changes are detected). But Oracle's JDK does not support incremental compilation.
Does Eclipse's JDT core compiler include a JRE?
In summary, Eclipse uses its own JDT core as the Java compiler. The JDT core compiler does not have a JRE. So Eclipse requires user installed JRE to run the .class code.
References:
[1] JDT Plug-in Developer Guide, http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.jdt.doc.isv%2Fguide%2Fjdt_api_compile.htm
[2] JDT Core Component, https://www.eclipse.org/jdt/core/
[3] How does Eclipse compile classes with only a JRE? How does Eclipse compile classes with only a JRE?
In contrast to other Java IDEs, Eclipse uses its own incremental compiler written in Java. It can display more warnings and errors than javac
. Both, the Eclipse compiler and javac
implement the Java Language Specification. There are corner cases where the two compilers produce different bytecode or one of them fails (e. g. see this Stack Overflow question).
The Eclipse compiler requires at least a JRE for the class files, e. g. java/lang/String.class
. A JDK is only to see the source code, but not required by the Eclipse compiler.
So far Eclipse was not shipped with a JRE (see Eclipse bug 506244). But this could change soon after the Java virtual machine OpenJ9 became an Eclipse project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With