I have installed CYGWIN Emulator Terminal on windows 7 in order to use GCC, i know that it can compile too many language, i can use it with C properly but don't know how to use it to compile java files?
-
To summarize the answers below: If you want to compile Java, use the Oracle compiler javac or the built in compilers in one of the common IDEs like Eclipse or Netbeans. These compilers tend to be maintained better than gcj – Jochen Nov 10 '12 at 12:02
-
@Jochen is right. `gcj` has been removed from GCC since [GCC 7](https://gcc.gnu.org/gcc-7/changes.html) (not yet released). – kaartic Jul 16 '17 at 11:12
5 Answers
If anyone is reading this question past September 30, 2016:
The GNU Compiler for Java (GCJ) has been discontinued and is no longer part of the GNU Compiler Collection (GCC), as it can be seen in the release notes for GCC 7.

- 4,993
- 1
- 30
- 35
Did you read the manual? gnu java
They have a compiler called gcj dedicated to Java language.

- 786
- 1
- 11
- 17

- 2,509
- 4
- 27
- 37
GCC Java compiler
Once upon a time, there existed a GCC Java frontend, but it has been deprecated.
Notably, the package is not present anymore in Ubuntu 18.04, but it was in Ubuntu 16.04.
Why it was depreated: Java JRE vs GCJ
Just for fun though, we can try it out this historical software in an old Docker container. But TODO: I couldn't get this to work on Ubuntu 16.04 or 14.04 guests today, and I'm lazy to debug it. But I swear that I got this working at least once when I first answered this question.
Main.java
public class Main {
public static void main(String args[]) {
System.out.println("hello world");
}
}
Compile and run:
sudo apt-get install gcj-4.8 libgcj16-dev
gcj-4.8 -c Main.java
gcj --main=Main -o Main Main.o
./Main
Compilation fails with:
gcj-4.8: error: libgcj.spec: No such file or directory
Related: https://bugs.launchpad.net/ubuntu/+source/gcj-4.0/+bug/24906
Android ART
Since Android 5, Android has been using the "ART runtime", which compiles the Java in apps ahead of time: https://en.wikipedia.org/wiki/Android_Runtime
Therefore, if you were to look into Java to binary compilation today 2019, that's where you should look.
Like everything else in Android, running ART without the rest of the bloat of Android might be impossible or insane unfortunately.
Here I briefly unpacked some precompiled Android apps: What is the native keyword in Java for? showing that they are actually compiled to shared objects.

- 347,512
- 102
- 1,199
- 985
GCC is a front-end to compile several languages (GNU Pascal, Mercury, Cobol, GNU Modula-2, Modula-3, GHDL, PL/1, GCC Unified Parallel C...).
Currently the main GCC distribution contains front ends for C (gcc), C++ (g++), Objective C, Fortran, Java (GCJ), Ada (GNAT), and Go.
GCJ is the equivalent of javac, but as you can see the latest news is dated 2009.

- 14,617
- 9
- 61
- 84
On top of the accepted answer, I would recommend not using GCC to compile Java according to the following post: Java JRE vs GCJ . Javac is a much better option! However it may still be worth looking at if you are using GCC to compile Java to native code (maybe). As I see it, GCJ is dead (the last news update is in 2009! https://gcc.gnu.org/java/index.html)

- 8,008
- 26
- 77
- 177

- 26,997
- 35
- 140
- 231