Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between javac and the Eclipse compiler?

People also ask

Does Eclipse use javac?

Eclipse Java compiler is an incremental Java builder The Java compiler built in Eclipse is a part of JDT Core component (JDT: Java Development Tool). An incremental compiler automatically compiles code when changes are detected.

What compiler does Eclipse use?

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.

Is Eclipse a compiler?

Eclipse does have it's own compiler, it does not use the JDK compiler (javac). However, Eclipse's compiler produces standard bytecode that complies with the Java Language Specification (JLS) and JVM Specification, so the compiled code it produces will work on any compliant JVM.

What is the difference between compiler and Java compiler?

Compiler translate the entire code at once whereas Java interprer translate the code line by line. Java compiler compiles the source code into bytecode. JVM i.e. Java virtual machine is an interpreter which interprets the byte code. Bytecode make Java a platform independent language.


Eclipse has implemented its own compiler called as Eclipse Compiler for Java (ECJ).

It is different from the javac, the compiler that is shipped with Sun JDK. 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.

Another difference is that the Eclipse compiler allows for incremental builds from within the Eclipse IDE, that is, all code is compiled as soon as you finish typing.

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.

A few examples where ECJ is preferred over javac is:

  • Apache Tomcat uses ECJ to compile JSPs,
  • IntelliJ IDEA has support for ECJ, as of GNU Compiler for Java (GCJ) 4.3,
  • GCJ integrates with ECJ,
  • Liferay builds with ECJ.

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

  • Eclipse bug? Switching on a null with only default case

Generics type inferrence related


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).


It is a separate 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.