PDA

View Full Version : Java programming in gcj



kumarannair
25th November 2004, 12:50 PM
Hai,
Could anyone explain how to compile a simple java program using the gcj compiler in Fedora Core 1. Iam a newbie. I mastered how to compile and run c and C++ programs in gcc. But my gcj doesn't work, but saying the it could not find the system.io package in the system. How could I specify the location of the package when compiling java programs. Is there any way other than this? Please help me!
Kumar

Jman
26th November 2004, 05:41 AM
If it was Sun's Java SDK the you would import java.io.

I don't know much about this, but I'll refer you to the gcj FAQ (http://gcc.gnu.org/java/faq.html#2_1).

kumarannair
27th November 2004, 11:40 AM
Hai,
Could anyone explain how to compile a simple java program using the gcj compiler in Fedora Core 1. Iam a newbie. I mastered how to compile and run c and C++ programs in gcc. But my gcj doesn't work, but saying the it could not find the system.io package in the system. How could I specify the location of the package when compiling java programs. Is there any way other than this? Please help me!
Kumar
I need help for compiling java programs with .java extension using gcj (which I prefer) .
From where I could download java SDK for Fedora core 1?

kumarannair
27th November 2004, 11:41 AM
Hai,
Could anyone explain how to compile a simple java program using the gcj compiler in Fedora Core 1. Iam a newbie. I mastered how to compile and run c and C++ programs in gcc. But my gcj doesn't work, but saying the it could not find the system.io package in the system. How could I specify the location of the package when compiling java programs. Is there any way other than this? Please help me!
Kumar
I need help for compiling java programs with .java extension using gcj (which I prefer) .
From where I could download java SDK for Fedora core 1?

Myra
27th November 2004, 12:32 PM
If you want to compile to native binaries, not .class files:


gcj --main=Example -o Example Example.java


It seems your code isn't right, because you have to "import java.io.*;" not "import system.io.*;".

You do not need a Java SDK for this. The plain FC3 install with GCJ is enough.

kumarannair
29th November 2004, 08:22 AM
If you want to compile to native binaries, not .class files:


gcj --main=Example -o Example Example.java


It seems your code isn't right, because you have to "import java.io.*;" not "import system.io.*;".

You do not need a Java SDK for this. The plain FC3 install with GCJ is enough.
First of all, Thank You Myra. You timely helped me to compile my java programs using gcj. I made a mistake by using System.io instead of java.io. Thank You Very Much.
Another question in my mind is that, whether we could use gcj to create a .class file instead of binary file. Could you provide more information of this matter.

( I could not download java SDK from sun's site.(due to heavy traffic or for some other reason) Could anyone suggest another respository for java SDK. )

crackers
30th November 2004, 04:35 AM
gcj won't build .class files - it's not intended to do that. You have to use a "regular" javac compiler to get .class files.

www.blackdown.org - their latest one is based on 1.4.2_pre07 plus it also has a fix for the WebStart issue on FC3.

Myra
30th November 2004, 02:50 PM
Actually crackers, you are wrong. GCJ can be used to compile Java code to .class files, and does it very well. Use the following syntax:



gcj -C Example.java


To run these .class files, you can use free GIJ runtime, which is shipped with FC3:



gij Example


Again, Sun's Java SDK is not needed. The only reason *I* still run it, is for Eclipse, Azureus and university work. I don't know any other place to download it, though the JRE can be downloaded from one of the known yum/apt repositories (freshrpms?).

However, when installing Sun's SDK, please set the path to look first in Sun's bin dir, since in FC3, javac and java point to gcj and gij respectively.

crackers
1st December 2004, 05:59 AM
Actually crackers, you are wrong.
Ah, thank you - I didn't know that. I avoid using gcj for much the same reasons, plus the fact that I work/play in J2EE space and that stuff does not like "non standard" compilers. And I really do like Swing. Plus, I've seen some things that Jikes compiled just fine that broke the standard compiler and totally violated the language specification as well! It's either Sun or Blackdown for me - and I don't give a rat's rear-end what RMS says... ;)