For Programmers: Free Programming Magazines  


Home > Archive > Java Help > February 2006 > Re: HelloWorld









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: HelloWorld
Bjorn Abelli

2006-02-28, 7:04 pm


"Ivan" wrote...
> I'm trying to teach myself Java. I downloaded AND installed
> j2se, and set the JAVA_HOME path. I installed gcj as a compiler,
> and it seems to work just fine..


If you're just beginning with Java, I would suggest that you skip the gcj
compiler for now, and simply use the one provided with J2SE, "javac".

> But that's when all my problems start.
>
> I end up with a file called HelloWorld.o
>
> Perhaps I'm not using the compiler correctly..


>
> But when I type java HelloWorld.o I come up with error
> Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld/o
>
> Let me know what am doing wrong plz..


You probably use gcj in a way that it compiles Java source code into native
code, instead of bytecode. As I said, skip "gcj" for now.

The result you've got, HelloWorld.o, isn't bytecode that can be run with a
JVM, but some kind of native code, that in turn would need to be linked with
other libraries to be able to run, at all.

Though it's possible to use gcj to do "ordinary" compilations to bytecode, I
think it would be easier for you to start with the javac compiler. Then it
would be straight forward to compile your code into bytecode,
HelloWorld.class, which can be run by the JVM, java.

// Bjorn A


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com