GNU Compiler for Java

Java compiler


title: "GNU Compiler for Java" type: doc version: 1 created: 2026-02-28 author: "Wikipedia contributors" status: active scope: public tags: ["free-and-open-source-compilers", "gnu-project-software", "java-compilers", "discontinued-java-virtual-machines"] description: "Java compiler" topic_path: "technology/computing" source: "https://en.wikipedia.org/wiki/GNU_Compiler_for_Java" license: "CC BY-SA 4.0" wikipedia_page_id: 0 wikipedia_revision_id: 0

::summary Java compiler ::

::data[format=table title="Infobox software"]

FieldValue
nameGNU Compiler for Java
logoGcj2.png
logo size70px
developerThe GNU Project
released
discontinuedyes
latest release version
latest release date
latest preview version
latest preview date
operating systemUnix-like
genreCompiler
licenseGNU GPL
website
::

| name = GNU Compiler for Java | logo = Gcj2.png | logo size = 70px | screenshot = | caption = | developer = The GNU Project | released = | discontinued = yes | latest release version = | latest release date = | latest preview version = | latest preview date = | operating system = Unix-like | programming language = | genre = Compiler | license = GNU GPL | website = The GNU Compiler for Java (GCJ) is a discontinued free compiler for the Java programming language. It was part of the GNU Compiler Collection.

GCJ compiles Java source code to Java virtual machine (JVM) bytecode or to machine code for a number of CPU architectures. It could also compile class files and whole JARs that contain bytecode into machine code.

History

The GCJ runtime-libraries original source is from GNU Classpath project, but there is a code difference between the libgcj libraries. GCJ 4.3 uses the Eclipse Compiler for Java as a front-end.

In 2007, a lot of work was done to implement support for Java's two graphical APIs in GNU Classpath: AWT and Swing. Software support for AWT is still in development. "Once AWT support is working then Swing support can be considered. There is at least one free-software partial implementations of Swing that may be usable.". The GNU CLASSPATH was never completed to even Java 1.2 status and now appears to have been abandoned completely.

As of 2015, there were no new developments announced from GCJ and the product was in maintenance mode, with open-source Java toolchain development mostly happening within OpenJDK. GCJ was removed from the GCC trunk on September 30, 2016. Announcement of its removal was made with the release of the GCC 7.1, which does not contain it. GCJ remains part of GCC 6.

Performance

The compilation function in GCJ should have a faster start-up time than the equivalent bytecode launched in a JVM when compiling Java code into machine code.

Compiled Native Interface (CNI)

The Compiled Native Interface (CNI), previously named "Cygnus Native Interface", is a software framework for the GCJ that allows Java code to call, and be called by, native applications (programs specific to a hardware and operating-system platform) and libraries written in C++.

CNI closely resembles the JNI (Java Native Interface) framework which comes as a standard with various Java virtual machines.

Comparison of language use

The authors of CNI claim for various advantages over JNI:

CNI depends on Java classes appearing as C++ classes. For example, given a Java class,

::code[lang=java] public class MyInteger { private int i;

public Int(int i) { 
    this.i = i; 
}

public int get() {
    return i;
}

public void set(int j) {
    i = j;
}

public static final Int ZERO = new Int(0);

} ::

one can use the class thus:

::code[lang=cpp] #include <gcj/cni.h> #include

MyInteger* mult(MyInteger& p, int k) { if (k == 0) { return MyInteger::ZERO; // Static member access. }

return new MyInteger(p.get() * k);

} ::

References

References

  1. Anthony Green, Cygnus Solutions. "GCJ announcement".
  2. "GCJ: The GNU Compiler for Java - GNU Project - Free Software Foundation (FSF)".
  3. Campbell, Bill. (2013). "Introduction to Compiler Construction in a Java World". CRC Press Taylor & Francis Group.
  4. "Compiling Java with GCJ | Linux Journal".
  5. "GNU Compiler for Java".
  6. [https://gcc.gnu.org/java/faq.html#2_4 The GCJ FAQ]
  7. [https://www.phoronix.com/scan.php?page=news_item&px=MTUwOTA GCC Looks To Turn Off Java, Replace With Go Or ADA]
  8. Andrew Haley. (September 30, 2016). "[gcc] Revision 240661".
  9. Tromey, Tom. (October 2, 2016). "The Deletion of gcj".
  10. "GCC 7 Release Series: Changes, New Features, and Fixes".
  11. "GCJ: The GNU Static Java Compiler".
  12. [https://gcc.gnu.org/java/faq.html#2_3 The GCJ FAQ – GNU Project – Free Software Foundation (FSF)]
  13. The example comes from: https://gcc.gnu.org/onlinedocs/gcj/Objects-and-Classes.html#Objects-and-Classes {{Webarchive. link. (2016-10-20)

::callout[type=info title="Wikipedia Source"] This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page. ::

free-and-open-source-compilersgnu-project-softwarejava-compilersdiscontinued-java-virtual-machines