//java architect /
How to Modify javac
Learn the steps for changing javac to implement new language syntax features.
simple new language syntax feature, the Elvis operator. It highlights some of the technical steps
that you would take if you were to
tackle one of the more advanced
projects in the Adopt OpenJDK
program. Of course, to add a language feature, you also would have
to fulfill the requirements of the
OpenJDK process by submitting a
JDK Enhancement Proposal (JEP).
JAVA IN ACTION
ABOUT US
RAOUL-GABRIEL URMA,
JANINA VOIGT, AND
MARTIJN VERBURG
MARTIJN VERBURG’S
PHOTOGRAPH BY BOB ADLER
For Java developers who want o work with the language and
platform they love, the last two
years have been groundbreaking
ones. Java SE 7 was released after a
long five-year wait and—crucially
for developers interested in Java
and the Java Virtual Machine
(JVM) itself—the OpenJDK
project became the Reference
Implementation (RI) for Java.
In addition to the RI code base
becoming fully open source, great
progress was made in simplifying
the complex build process, and
most developers are now able to
build the OpenJDK with a simple
one-line command.
Last, the existing OpenJDK
committers continued their outreach to the wider Java community, encouraging participation.
Today, the OpenJDK is more open
than ever and the barriers to entry
have been significantly lowered.
In late April 2012, the London
Java Community launched the
Adopt OpenJDK program. This
program is a group of projects
and events led by Java user groups
(JUGs) that aims to channel into
the OpenJDK the efforts of the
wider Java community (those
members of the Java commu-
nity that are not already directly
involved in the OpenJDK, such as
Oracle, Red Hat, IBM, and many
others), while keeping in mind a
“do no harm” policy.
Overview of Compilation
Using javac
The Java compiler, javac, takes
a set of Java source files (.java)
as input and produces the cor-
responding .class files as output.
You need to understand the basics
of javac compilation in order to
add features to Java. This process
is performed in three distinct
phases, as shown in Figure 1. We’ll
just give you a quick overview
of the three compilation phases
here; for more details, see the
OpenJDK documentation.
Parse and Enter phase. As a first
step, the javac lexer reads the Java
source files (as an input stream of
characters) and maps these into
a sequence of tokens. The parser
takes these tokens and gener-
ates Abstract Syntax Trees (ASTs)
representing the source program.
These trees are made of AST
nodes that represent the differ-
ent constructs in the source code,
such as method declarations,
statements, and so on.
.java files
blog
.class files