problem compiling with JAVA

hello, I am learning Java, on my first “Hello World” program, this is what I get

alon@linux-6xrt:~/java> javac Ch2Sample1.java
/usr/lib/gcc/i586-suse-linux/4.3/…/…/…/crt1.o: In function _start': /usr/src/packages/BUILD/glibc-2.9/csu/../sysdeps/i386/elf/start.S:115: undefined reference to main’
collect2: ld returned 1 exit status
alon@linux-6xrt:~/java>

I googled around but could not figure out. what is gcj?
I am running openSUSE 11.1

Thanks

Hello only-trouble,

Here’s the homepage of gcj: GCJ: The GNU Compiler for Java - GNU Project - Free Software Foundation (FSF)

It’s a very strange error.
I’ve never seen it before, maybe because I use an IDE.
Do you have java-sun or openJDK?

If you use java-sun what happens when you run this command:

/usr/lib/jvm/java-1.6.0-sun-1.6.0/bin/javac Ch2Sample1.java 

Just to make sure: I assume your file looks like this:

public class Ch2Sample1 {public static void main(String] args) {[INDENT]System.out.println("Hello World!");
}
[/INDENT]}

If not could you post your source code.

Best of luck!:wink:

Hello Edward,

So I change the code to

Code:
public class hello2 {
public static void main(String] args) {
System.out.println(“Hello World!”);
}
}

and no change, still

alon@linux-6xrt:~/java> javac hello2.java
/usr/lib/gcc/i586-suse-linux/4.3/…/…/…/crt1.o: In function _start': /usr/src/packages/BUILD/glibc-2.9/csu/../sysdeps/i386/elf/start.S:115: undefined reference to main’
collect2: ld returned 1 exit status
alon@linux-6xrt:~/java>

I also discovered I dont have the directory
/usr/lib/jvm/java-1.6.0-sun-1.6.0/bin
this is the output of my directory

alon@linux-6xrt:~/java> cd /usr/lib/jvm/
alon@linux-6xrt:/usr/lib/jvm> ls
java java-gcj jre-1.6.0-openjdk
java-1.5.0 jre jre-gcj
java-1.5.0-gcj jre-1.5.0 jre-openjdk
java-1.5.0-gcj-4.3-1.5.0.0 jre-1.5.0-gcj
java-1.6.0-openjdk-1.6.0 jre-1.6.0
alon@linux-6xrt:/usr/lib/jvm>

Where do I find my java compiler?
I got the java compiler from the openSUSE repository.
Where do I take it from here? Anysuggestions ? should I download the java compiler from the Sun website?
Thanks

Hello only-trouble,

Your java compiler isn’t in the ‘java-1.6.0-sun-1.6.0’ directory because you most likely haven’t got the java-sun version installed.
By default the openJDK is installed.
The only problem with it is that it some times doesn’t work.

So I recommend you install these packages:

  • java-1_6_0-sun
  • java-1_6_0-sun-devel
  • java-1_6_0-sun-plugin

And remove all the java-1_6_0-openjdk packages.

Then you’ve got the /usr/lib/jvm/java-1.6.0-sun-1.6.0/bin directory.
But if you don’t want to uninstall openJDK then the javac command is in:
/usr/lib/jvm/java-1.6.0-openjdk-1.6.0/bin

Good luck!:wink: