Why does Eclipse use its own Java compiler?
- Details
- Written by Nam Ha Minh
- Last Updated on 21 April 2020   |   Print Email
If you are new to Java development with Eclipse IDE, you may be surprised that Eclipse doesn’t use javac – the Java compiler provided by JDK. Instead, Eclipse implements its own Java compiler – based on the Java Language Specification (JLS). There are some good reasons that Eclipse makes use of its own Java compiler:
1. 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. It doesn’t compile the whole project’s code. It compiles only the changes you have made (incrementally), giving fast response to programmers.
In contrast, javac does not support incremental compilation. If Eclipse uses javac, programmers will experience slow response for changes they have made, which decreases productivity.
Eclipse Java compiler requires JRE to run compiled byte code, so a JRE is enough to use Eclipse IDE – JDK is not necessary.
2. Eclipse Java compiler allows customization of error and warning messages
Eclipse Java compiler may produce more warnings and errors than javac, which is useful for programmers. You can customize errors and warnings for various Java coding issues.
In Eclipse, go to Window > Preferences > Java > Compiler > Errors/Warnings – then you can see what you can customize:
For example, if Value of local variable is not used, you can instruct the compiler to show an error, warning, info or ignore it.
3. Eclipse Java compiler allows slightly broken code to run
The incremental compiler in Eclipse allows to run a Java program even it still contains unresolved errors. For example, you have error in a method and you attempt to run the program, Eclipse will show a warning message like this:
Click Proceed to run the program anyway. This feature is useful if the unresolved errors do not relate to the code you want to test.
4. Eclipse Java compiler vs. javac compiler
Since Eclipse Java compiler and javac compiler are different, they usually produce different error/warning message for the same issue. Consider this line of code:
int x = “20”;
In Eclipse, it will say:
Type mismatch: cannot convert from String to int
But javac will say:
error: incompatible types: String cannot be converted to int
However, both Eclipse Java compiler and javac implement the Java Language Specification (JLS), the bytecode they produce is almost the same. Except for some corner cases they may produce different bytecode or code compiles with Eclipse but not compiles with javac.
So via this post, I hope you understand why Eclipse uses its own Java compiler and the benefits.
Watch the video:
Other Eclipse Tutorials:
- How to import existing projects into Eclipse workspace
- How to create, deploy and run Java Servlet in Eclipse
- How to generate JAR file in Eclipse
- How to create WAR file for Java web application in Eclipse
- How to create Ant build file for existing Java project in Eclipse
- How to generate Javadoc in Eclipse
- How to create Java web project with Maven in Eclipse
- 25 Eclipse Shortcut Keys for Code Editing
- How to Add Copyright License Header for Java Source Files in Eclipse
- How to monitor HTTP requests and responses using TCP/IP Monitor in Eclipse
Comments