Thread: new to java

  1. #1
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589

    new to java

    I'm trying to write my first hello world java program.
    I do not know what I'm doing wrong.

    Code:
    public class helloworld
     {
     																															  
     		System.out.println("Hello World");
     																															  
     }
    here are my errors
    helloworld.java:4: Invalid method declaration, method name required.
    System.out.println("Hello World");
    ^
    helloworld.java:4: Class or interface declaration expected.
    System.out.println("Hello World");
    ^
    2 errors
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Just like C/C++, you still need a main function.

    Code:
    public class helloworld
    {
    
      public static void main( String args[] )
      {
        
        System.out.println("Hello World");
     
      }
    
    }
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    thank you for the response.
    i made the adjustments, but it provides me the following error.
    /usr/lib/gcc-lib/i386-redhat-linux/3.2.3/../../../crt1.o(.text+0x18): In function `_start':
    : undefined reference to `main'
    collect2: ld returned 1 exit status
    is this due to i have no return type?
    or does the gcc-lib portion of the error path mean i do not have the needed libraries?

    I tried to add a return type, but with no luck.
    Last edited by xviddivxoggmp3; 06-06-2004 at 01:58 AM.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    What command are you using to compile it?
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #5
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    Code:
    gcj helloworld.java
    Isn't gcj similar to gcc and g++ for compile commands?

    i read the man page and it states that it is similar to gcc

    SYNOPSIS
    gcj [-Idir...] [-d dir...]
    [--CLASSPATH=path] [--classpath=path]
    [-foption...] [--encoding=name]
    [--main=classname] [-Dname[=value]...]
    [-C] [--resource resource-name] [-d directory]
    [-Wwarn...]
    sourcefile...
    I'm assuming, and correct me if i'm wrong, but the helloworld program is so simple that it shouldn't require any special options or header files. At least that is what I take from reading Oreilly Java in a Nutshell
    Last edited by xviddivxoggmp3; 06-06-2004 at 02:11 AM.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  6. #6
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    I guess noone knows what I'm doing wrong?
    Please someone help.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  7. #7
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Try using javac instead of gcj.

    Code:
    javac helloworld.java
    java helloworld
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  8. #8
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    i can only get javac man pages.
    javac itself doesn't work on my version of red hat.
    I tried to use an rpm to fix, but the rpm keeps saying i have a key error.
    So do you think it is a compiler issue?
    i will post the rpm error when i get home.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  9. #9
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Try this:
    Code:
    gcj --main=helloworld helloworld.java
    GCJ needs you to tell it which class contains the main function.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  10. #10
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    thank you the --main=helloworld worked.
    i finished my first java program due to your help.
    you rock.
    now that i know how to compile a program, i'm guessing the remainder is going to be similar to c and c++
    if i could only figure out rpm files now.
    do you know anything about red hat and rpm (red hat package manager)
    I'm using this command line syntax
    Code:
     rpm -i  redhat-java-rpm-scripts-1.0.2-2.src.rpm
    this is the error i'm getting.
    warning: redhat-java-rpm-scripts-1.0.2-2.src.rpm: V3 DSA signature: NOKEY, key ID db42a60e
    i'm starting to think this means the signature is invalid, so the origin of the package is not guaranteed, causing the error.

    this kicks royal butt.
    i can write more java code with just the capability of compiling. it is amazing how many languages you can pick up with only knowing c and the compiler.
    Last edited by xviddivxoggmp3; 06-07-2004 at 01:03 AM.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  11. #11
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    I don't know anything about the RPM system, 'cuz I'm using Gentoo and Portage.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  12. #12
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    http://www.linuxquestions.org/questi...hreadid=190568

    this is the link to my linux question. just in case anyone wants to see what the kind people as
    linuxquestions.org wanted to say about it. sorry to post a thread from another forum here, but i needed to know and i figured someone else may want to know.

    x, thanks again for the help.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C#, Java, C++
    By incognito in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 10-05-2004, 02:06 PM
  2. First Java Class at college
    By GanglyLamb in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 09-29-2004, 10:38 PM
  3. The Java language is being expanded
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 06-11-2004, 09:07 PM
  4. Java woes
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 07-06-2003, 12:37 AM
  5. C or Java as a first language
    By CorJava in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 10-23-2002, 05:12 PM