Java Reference
In-Depth Information
A lesser-known feature of ECJ is its support for scrapbook pages. A scrapbook page
allows programmers to test small pieces of Java expressions without creating a surrounding
Java class or method for the specific code snippet.
This can be created by either simply creating a file with .jpage extension, or using the
scrapbook page wizard in Eclipse [Eclipse, 2011]. One can write a single line of code as:
newjava.util.Date()
inside the new scrapbook page, and then evaluate it. Notice that, a semicolon at the end
of line is omitted, which would normally cause a compile-time error in a java file; yet ECJ
understands what is intended here and evaluates the expression. The scrapbook editor also
supports code assist, showing the possible completions when writing a qualified name.
Another convenience is the ability to Inspect a highlighted expression, which will open
a pop-up window inside the editor and show all the debug information on the highlighted
object without having to switch to the Debug perspective.
There is also the ability to Execute scrapbook expressions on the JVM. Suppose a
scrapbook page has the following lines:
java.util.Datenow=newjava.util.Date();
System.out.println("Currentdateandtime:"+now);
Executing these two lines in scrapbook produce the requisite output:
Currentdateandtime:MonSep2623:33:03EDT2011
The scrapbook provides that immediate feedback that LISP users find so useful.
The ECJ is also used in Apache Tomcat for compiling JSP pages and the Java IDE called
IntelliJ IDEA. In addition, GCJ, discussed in the next section, uses ECJ as its front-end
compiler (as of GCJ 4.3).
8.4 GNU Java Compiler (GCJ)
8.4.1 Overview
The GNU Java Compiler (GCJ) [GNU, 2012] is one of the compilers provided in the GNU
Compiler Collection (GCC). Although GCC started as a C compiler (aka the GNU C
Compiler), compilers for other languages including Java were soon added to the collection.
Today, GCC is the standard compiler for many Unix-like operating systems.
GCJ may directly produce either native machine code or JVM bytecode class files. GCJ
can deal with both Java source files or zip/jar archives, and can package Java applications
into both .jar files and Windows executables (.exe files), as well as producing class files.
GCJ uses the Eclipse Java Compiler (ECJ) as its front end. Programs that are compiled
into bytecode with ECJ are linked with the GCJ run-time called libgcj. Libgcj provides
typical run-time system components such as a class loader, core class libraries, a garbage
collector 7 , and a bytecode interpreter. Libgcj can also interpret source code to machine code
directly. Figure 8.2 shows possible routes a Java source code can take when fed to GCJ.
7 Hans Boehm's conservative garbage collector, which is known as Boehm GC, is used. Detailed informa-
tion can be found at http://www.hpl.hp.com/personal/Hans_Boehm/gc/.
 
Search WWH ::




Custom Search