you're reading...
GNU/Linux, Java, Programming

Brewing Java Using GNU gcj

Being a Huge Fan|User|Preacher|Addict of GNU/Linux i felt it was my duty to follow up the previous post “Brewing Your First Cup of Java on Linux” with this post showing users how to use GNU compiler for the Java programming language.So lets not waste any time and start Brewing Java with GNU gcj 🙂

Let me just start with what is GNU gcj

GCJ is a compiler for the Java Programming Language.It can compile Java source code to Java bytecode (class files) or directly to native machine code, and Java bytecode to native machine code.

libgcj provides the core class libraries, a garbage collector.The GNU Interpreter for Java (GIJ) which is a Java bytecode interpreter is included with libgcj.

The GNU compiler for the Java comes as default in most of the linux distributions.Just to be sure about its installed just issue the following command  in your terminal.

$ gcj





If you get the above out put then its working fine 🙂

Now write a  simple Java program ..Here am using vi editor.









Now to invoke gcj to compile and link the brewingjava.java

file issue the following command

$ gcj --main=brewingjava -o brewingjava brewingjava.java

The ––main=brewingjava option is used to link to specify the name(brewingjava) of the class whose main method should be invoked when the resulting executable is run.

The –o brewingjava option tells the gcj compiler to name the executable file brewingjava .

The brewingjava.java argument is the name of the source file that gcj is compiling.

If any errors are found in the program then gcj will display them.





Once compiling and linking are done Execute the program using the dot-hash way

$ ./brewingjava






A .exe executable file can also be generated using gcj ..

$ gcj --main=brewingjava -o brewingjava.exe brewingjava.java

The pictures below show ‘brewingjava.exe’ being generated and executed

This was a ‘HelloWorld’ tutorial on Brewing java using GNU gcj!! 🙂 🙂

The home page for GNU gcj can be found here and the official manual can be found here

The official manual is kind of complicated for noobs so i request you guys to have a look at this pdf which is a Technical Paper written by some wonderful people from redhat


The Inspiration for this post was a article i found at LinuxJournal


About Suhas Dwarakanath

Embedded Engineer interested in Electronics and GNU/Linux


No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: