USA Linux Users Group Forum Index
Log in Register FAQ Memberlist Search USA Linux Users Group Forum Index Album

Ok.... this is making my head hurt......

 
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » Shell Scripting and Programming
View previous topic :: View next topic  
Author Message
crouse
Site Admin


Joined: 17 Apr 2003
Posts: 11855
Location: Iowa

PostPosted: Mon Sep 26, 2005 7:38 pm    Post subject: Ok.... this is making my head hurt...... Reply with quote

Trying to do a simple "helloworld" program....... so i can..... well.... get started Wink I'll be the first to admit.... i dont' know anything really about java. However, the cross-platform capabilities intrigue me, and jbsnake is beating me about the head with the big stick to give it a try. I am "trying" ...... just haven't had much success yet Smile PEBKAC error i'm sure Laughing

Code:

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> ls
helloworld.java

crouse@linux:~/Scripts/javastuff> gcj -C helloworld.java
crouse@linux:~/Scripts/javastuff> ls
helloworld.java  Welcome.class

crouse@linux:~/Scripts/javastuff> gij Welcome.class
Exception in thread "main" java.lang.NoClassDefFoundError: Welcome.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> ls
helloworld.java  Welcome.class       


..........
So, if one were to say ....... start from scratch.......
WHAT do i want to install ?? Were should I get it?

IE: download gcc-java compiler ?
download java ... from where ?

Ok..... enough questions..... Smile I think my head stopped hurting finally......



_________________
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
View user's profile Send private message Visit poster's website AIM Address
crouse
Site Admin


Joined: 17 Apr 2003
Posts: 11855
Location: Iowa

PostPosted: Mon Sep 26, 2005 7:43 pm    Post subject: Reply with quote

yeah.... forgot the code (edited it a bit changed Welcome to helloworld ..... just seemed more appropriate Neutral )


Code:

class helloworld {

/* Welcome program by Dave Crouse
   Java Sept 26th, 2005
   Simple program displays hello message
*/

helloworld () {
   System.out.println("Hello World. Isn't that the most famous first program ? LOL ");
      }
   
      public static void main (String [ ] args) {
        new helloworld ();
        }
    }
   



_________________
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
View user's profile Send private message Visit poster's website AIM Address
VHockey86
Advanced Member


Joined: 12 Dec 2004
Posts: 989
Location: Rochester

PostPosted: Mon Sep 26, 2005 7:54 pm    Post subject: Reply with quote

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
View user's profile Send private message
crouse
Site Admin


Joined: 17 Apr 2003
Posts: 11855
Location: Iowa

PostPosted: Mon Sep 26, 2005 8:02 pm    Post subject: Reply with quote

uh huh.......

yours gave me even more errors........ Wink
Code:

crouse@linux:~/Scripts/javastuff> gcj --main=helloworld -o helloworld helloworld.java
helloworld.java:1: error: Public class `HelloWorld' must be defined in a file called `HelloWorld.java'.
   public class HelloWorld {
                ^
helloworld.java:3: error: Invalid method declaration, return type required.
            HellowWorld() {
            ^
2 errors

crouse@linux:~/Scripts/javastuff> gcj -C helloworld.java
helloworld.java:1: error: Public class `HelloWorld' must be defined in a file called `HelloWorld.java'.
   public class HelloWorld {
                ^
helloworld.java:3: error: Invalid method declaration, return type required.
            HellowWorld() {
            ^
2 errors



_________________
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
View user's profile Send private message Visit poster's website AIM Address
VHockey86
Advanced Member


Joined: 12 Dec 2004
Posts: 989
Location: Rochester

PostPosted: Mon Sep 26, 2005 8:04 pm    Post subject: Reply with quote

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
View user's profile Send private message
crouse
Site Admin


Joined: 17 Apr 2003
Posts: 11855
Location: Iowa

PostPosted: Mon Sep 26, 2005 8:12 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address
mr_ed
Site Admin


Joined: 28 Aug 2003
Posts: 3819
Location: 42 miles north of Ogdensburg, NY

PostPosted: Tue Sep 27, 2005 1:26 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » Shell Scripting and Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All content © 2003-2009 - Usa Linux Users Group
This forum is powered by phpBB. © 2001-2009 phpBB Group
Theme created by phpBBStyles.com and modified by Crouse