| View previous topic :: View next topic |
| Author |
Message |
crouse Site Admin

Joined: 17 Apr 2003 Posts: 11855 Location: Iowa
|
|
| Back to top |
|
crouse Site Admin

Joined: 17 Apr 2003 Posts: 11855 Location: Iowa
|
|
| Back to top |
|
VHockey86 Advanced Member

Joined: 12 Dec 2004 Posts: 989 Location: Rochester
|
Posted: Mon Sep 26, 2005 7:54 pm Post subject: |
|
|
you need to put your S.O.P statement inside the helloworld class' constructor if you want to instantiate an object....(not that you need to). The main method does not go in the constructor
| Code: |
public class HelloWorld {
HelloWorld() {
System.out.println("Hello World");
}
public static void main(String[]args) {
HelloWorld foo = new HelloWorld();
}
}
|
The file name MUST match the class name and is case sensitive (ya, java is a pain in the a**).
So you need HelloWorld.java in my little example
This would also work perfectly fine without actually instantiating an object. Just use the main method procedurally and inside a random class that is your file name
| Code: |
public class HelloWorld {
public static void main(String[]args) {
System.out.println("Hello World");
}
}
|
_________________ Main Desktops : Kubuntu 10.4. ArchLinux 64-bit. Windows7 64-bit. Windows XP 32-bit.
MacBook: OS X Snow Leopard (10.6)
|
|
| Back to top |
|
crouse Site Admin

Joined: 17 Apr 2003 Posts: 11855 Location: Iowa
|
|
| Back to top |
|
VHockey86 Advanced Member

Joined: 12 Dec 2004 Posts: 989 Location: Rochester
|
Posted: Mon Sep 26, 2005 8:04 pm Post subject: |
|
|
Its case sensitive, you file MUST be "HelloWorld.java" using my code.
Download the sun JDK
https://sdlcweb3a.sun.com/ECom/EComActionServlet;jsessionid=775B0FDDAA5B876EAF2BA1B81FFE1AE7
It's by far the best compiler I've ever used in terms of helpful errors messages and stuff.
Get on IRC and this will be easier =)
I also had a typo that I fixed by editing the post,
Change "HellowWorld" to "HelloWorld" =).
_________________ Main Desktops : Kubuntu 10.4. ArchLinux 64-bit. Windows7 64-bit. Windows XP 32-bit.
MacBook: OS X Snow Leopard (10.6)
|
|
| Back to top |
|
crouse Site Admin

Joined: 17 Apr 2003 Posts: 11855 Location: Iowa
|
Posted: Mon Sep 26, 2005 8:12 pm Post subject: |
|
|
| Code: |
crouse@linux:~/Scripts/javastuff> ls
helloworld.class helloworld.java HelloWorld.java
crouse@linux:~/Scripts/javastuff> gcj --main=HelloWorld -o HelloWorld HelloWorld.java
/usr/lib/gcc-lib/i586-suse-linux/3.3.4/../../../../i586-suse-linux/bin/ld: cannot find -lz
collect2: ld returned 1 exit status
crouse@linux:~/Scripts/javastuff> gcj -C HelloWorld.java
crouse@linux:~/Scripts/javastuff> ls
helloworld.class HelloWorld.class helloworld.java HelloWorld.java
crouse@linux:~/Scripts/javastuff> gij HelloWorld.class
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld.class
at gnu.gcj.runtime.FirstThread.run() (/usr/lib/libgcj.so.4.0.0)
at _Jv_ThreadRun(java.lang.Thread) (/usr/lib/libgcj.so.4.0.0)
at _Jv_RunMain(java.lang.Class, byte const, int, byte const, boolean) (/usr/lib/libgcj.so.4.0.0)
at main (Unknown Source)
at __libc_start_main (/lib/tls/libc.so.6)
at _start (Unknown Source)
crouse@linux:~/Scripts/javastuff>
|
_________________ Archie/Jughead (Servers)- Arch Linux 32-bit -- Kernel 2.6.34-2
Betty/Reggie (VBox)- Arch Linux 32-bit -- Kernel 2.6.34-2
Cybertron (Laptop)- Arch Linux 32-bit -- Kernel 2.6.34-2
BumbleBee (Desktop)- OpenSolaris-SunOS 5.11
|
|
| Back to top |
|
mr_ed Site Admin

Joined: 28 Aug 2003 Posts: 3819 Location: 42 miles north of Ogdensburg, NY
|
Posted: Tue Sep 27, 2005 1:26 pm Post subject: |
|
|
| crouse wrote: | | Code: | /usr/lib/gcc-lib/i586-suse-linux/3.3.4/../../../../i586-suse-linux/bin/ld: cannot find -lz
collect2: ld returned 1 exit status
|
|
Do you have the development package for the zlib library? That may be the cause.
_________________ Desktop: Ubuntu 7.10 "Gutsy Gibbon"
Laptop: Ubuntu 7.04 "Feisty Fawn"
|
|
| Back to top |
|
|