Results 1 to 28 of 28

Thread: [RESOLVED] java noob question

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Resolved [RESOLVED] java noob question

    Hello

    i was trng to run a simple "hello world" program, i have got j2sdk1.4.2_04

    i am using the windows command prompt

    i can get javac to compile to come up with the hello.class file, and my hello world program compiles fine, however when i try to execute it using java hello command i get the following error message

    exception in thread "main" java.lang.NoClassDefFoundError: hello

    my hello world program contains the following java code

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

    please can you guys help me

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Re: java noob question

    hey computerjy i had added ;c:\j2sdk1.4.2_04\bin to my path, the path variable looks like
    C:\Program Files\Alias\Maya6.0\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\VoiceAge\Common;c:\matlab6p5\bin\win32;C:\Program Files\Rational\common;C:\Program Files\QuickTime\QTSystem\;c:\j2sdk1.4.2_04\bin

    i can get the program to compile using javac but it does not execute

  4. #4
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: java noob question

    make sure that the file name is "hello.java" (Case sensitive)
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  5. #5
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: java noob question

    1- Goto the "java control panel" in control panel
    2- goto the "Java" tab"
    3- click on "view" under "Java Application Runtime Settings"
    4- make sure both user and system have values set and a vaild path.

    if any of them doesn't, then Add one or find it
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Re: java noob question

    thanks for the replies

    the file is hell.java it produced hello.class upon compilation.
    i then tried to do java hello and it came up with the error

    i went to the java control panel and under "Java application runtime settings" the user and system have their values sets and the following paths

    for the system the path is c:\program files\java\jre1.5.0_01\bin\javaw.exe (product 1.5.0)


    for the user the paths are c:\program files\java\jre1.5.0_01\bin\javaw.exe (product 1.5.0_01) &
    c:\program files\java\j2re1.4.2_06\bin\javaw.exe (product 1.4.2_06)

  7. #7
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: java noob question

    try to remove the 1.4.2 from the user
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Re: java noob question

    i could nto remove 1.4.2 from user, the remove button is greyed out.

    i disabled 1.4.2 by unchecking the check btton, but i get the same error message, i disabled 1.5.0 by unchecking the check, but the result was the same

  9. #9
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: java noob question

    There are no more solutions in my head, so I recommend you use an IDE you can get the links from the other thread I gave you
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Re: java noob question

    thanks for the help

    i have downloaded netbeans and will use that to learn java

  11. #11
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: java noob question

    run java as exe files.
    This download is a very wonderful tool for all people who can compile java but can't get it to run properly
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  12. #12
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: java noob question

    The problem is most likely the CLASSPATH variable. Search this forum for CLASSPATH and you will find the solution.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  13. #13
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: java noob question

    Quote Originally Posted by CornedBee
    The problem is most likely the CLASSPATH variable. Search this forum for CLASSPATH and you will find the solution.
    we already tried that
    But it didn't work
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  14. #14
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: java noob question

    Well, I see nothing in this thread to indicate that vb_student checked the CLASSPATH. Just the PATH.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  15. #15

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Re: java noob question

    my CLASSPATH is C:\Program Files\Java\jre1.5.0_01\lib\ext\QTJava.zip

    that does not look good to me, should i change it?

  16. #16
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: java noob question

    Yes. Append ";." to the value.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  17. #17
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: java noob question

    Quote Originally Posted by CornedBee
    Yes. Append ";." to the value.
    No, that's not it
    This is not what the classpath should be set to
    it should be: C:\Program Files\Java\jdk1.5.0_01\bin
    (with or without the ";") it doesn't make a difference if it's at the end of the line
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  18. #18
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: java noob question

    No, it should not. There are no Java .class files in that directory, and that is the only thing CLASSPATH is good for.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  19. #19
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: java noob question

    error message shows that the hello.class file can not be found. so after compiling checkout that hello.class file is there.

    java is case sensitive. takecare of it.

    set the path correctly to your working folder as well.

  20. #20

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Re: java noob question

    thanks for the replies

    i am confised, not sure if i should append

    ";." to the original classpath i.e.

    C:\Program Files\Java\jre1.5.0_01\lib\ext\QTJava.zip

    or set the class path to

    C:\Program Files\Java\jdk1.5.0_01\bin

    and should i reset the path to the working folder too?

  21. #21
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: java noob question

    You should only do what I told you to do, i.e. append ;. to the original classpath.

    The /bin thing is confusing CLASSPATH and PATH. Adding the working directory to PATH has exactly no effect in Windows.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  22. #22

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Re: java noob question

    eureka, appending the ;. to the original classpath worked.

    what does that do?
    why was the original classpath pointing to .zip file?

  23. #23
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: java noob question

    The CLASSPATH tells Java where to look for .class files when trying to load classes that you use. It consists of several paths, separated by semicolons. (Colons in *nix.)
    The problem is that it really looks only there. If your classpath is set and doesn't contain the current working directory ".", you can't run classes even if their .class file is in the same directory as you are.

    My guess is that you installed some Java program that needs the Java QT bindings, and thus sets the CLASSPATH to the ZIP file containing the classes of the binding. This is an incredibly rude thing for an installer to do, but unfortunately it happens.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  24. #24

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Re: java noob question

    thanks for the reply

    is classpath an environment variable which is only used with Java?

    i just removed the ;. in the classpath in the control panel, however when i do an echo 5CLASSPATH%, i still get
    C:\Program Files\Java\jre1.5.0_01\lib\ext\QTJava.zip;. !
    why can't i remove the ;.
    Last edited by vb_student; Jun 23rd, 2006 at 03:25 PM.

  25. #25
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: java noob question

    You need to close and re-open the console to have changes in environment variables take effect. And yes, Java is AFAIK the only thing to care about the CLASSPATH.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  26. #26

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Re: java noob question

    thanks for the reply

    why does one need to close the command prompt before the changes take place

    did windows have the classpath environment variable before java come onto the scene

  27. #27
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: java noob question

    1) Because that's the way environment variables work. Every application has its own set of vars that cannot be modified from the outside, only the inside. The settings you do in the control panel merely change the defaults with which an app is created, but they cannot change the current set of envvars of the running applications. In addition, every program receives the variables of its creator. The creator of the Java process is the console, so Java receives the outdated variables from the console until you close and recreate that process.

    2) No. CLASSPATH was invented by Sun. Since it only has meaning for Java applications (there's no such thing as a classloader in other applications), there was no reason for it to be there.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  28. #28

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Re: java noob question

    thamks for the reply

    it makes sense now

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width