views:

229

answers:

4

I asked this in a comment, but figured it's a separate question:

Is Eclipse's compiler just a wrapper around the same compiler core that the javac program is wrapped around, or is it a separate compiler altogether? If the latter, why would they reinvent the (possibly inferior) wheel?

+18  A: 

Eclipse has implemented it's own compiler. It actually uses a couple compilers.

One compiler is a very quick compiler that brings you the red squiggles. It is fast, but can be inaccurate.

The other compiles your code when you want to run a project. It is different from the standard java compiler. One notable difference is that the Eclipse compiler lets you run code that didn't actually properly compile. If the block of code with the error is never ran, your program will run fine. Otherwise it will throw an exception indicating that you tried to run code that doesn't compile.

The fact that Eclipse comes with its own compiler is also apparent because you can write, compile, and run Java code in Eclipse without even installing the Java SDK.

jjnguy
Ok, but if you want to make a release build, which is better to use?
Bart van Heukelom
@Bart, the Eclipse compiler works well enough for enterprise release builds.
jjnguy
If you are compiling OSGi bundles instead of regular java, then the Eclipse compiler is more correct because it allows specifying package access rules. PDE will manage these access rules for you to match the OSGi runtime classloaders. https://bugs.eclipse.org/bugs/show_bug.cgi?id=106631 provides an example of problems that can happen without these rules.
Andrew Niefer
+4  A: 

It is a seperate compiler altogether. This is needed as javac doesn't allow compilation of slightly broken code, from the eclipse site

An incremental Java compiler. Implemented as an Eclipse builder, it is based on technology evolved from VisualAge for Java compiler. In particular, it allows to run and debug code which still contains unresolved errors.

BenM
+2  A: 

Eclipse's built-in compiler is based on IBM's Jikes java compiler. (Note that Eclipse also started its life at IBM). It is completely independent of Sun's Java compiler in the JDK; it is not a wrapper around Sun's javac.

Jikes has existed for a long time, it used to be a lot faster than the standard JDK Java compiler (but I don't know if that's still true). As to why IBM wanted to write their own Java compiler: maybe because of licensing reasons (they also have their own Java implementation).

Jesper
They didn't *really* write their own Java compiler. Eclipse has a long lineage back to Visual Age for Smalltalk, before Java even existed. Since the two languages are actually somewhat similar, they simply adapted their existing technology. Sun's compiler is also completely unsuitable for use in an IDE, *especially* in an incremental Smalltalk-style IDE like the original Visual Age for Java since it always wants to compile whole files. IBM's compiler can incrementally compile only the fragments that have changed. It can even compile snippets that aren't even legal Java, which is used in the
Jörg W Mittag
Eclipse scrapbook where you can simply write snippets of code, highlight them and run them, without having to put them into a class, a main method, or even into a method *at all*.
Jörg W Mittag
+3  A: 

Everyone has already explained that they're different. Here are some difference in behaviors I've noticed between the two compilers. They all boil down to a bug in (at least) one of the implementations.

Compile-time optimization related

Generics type inferrence related

polygenelubricants
Actually I knew about this difference after a long night: Eclipse was reporting an error about something that to me seemed legal (I don't remember what), in my desperation (I barely could stay awake) I just feed the code to javac and then it worked smoothly! I found in Google that I had to upgrade the JDT in order to get the fix for that issue.
Abel Morelos