Results 1 to 6 of 6

Thread: Please help a complete Java beginner

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458

    Please help a complete Java beginner

    Hi,
    I'm very new to Java.
    I just downloaded jdk1.3.1_01 from SUN and tried to compile the "Hello world" kind of program using dos prompt:

    Code:
    class HelloWorld
    {
      public static void main(String[] arguments)
        {
          System.out.println("Work damn it!");
        }
    }
    I saved the above program in the same folder as my java & javac executables. I compiled with the following:

    Code:
    javac HelloWorld.java
    As expected that produced file HelloWorld.class. So far so good.

    When I tried to run the program with:
    Code:
    java HelloWorld
    I'm getting the following error:
    Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
    Thanks

    Tomexx.

  2. #2
    VirtuallyVB
    Guest
    That is a strange one. Usually my answer would be to check your PATH by typing "set" at the DOS prompt.

    But since you get results from typing javac and java, it seems like your PATH should be set correctly. I followed your instructions to the letter except that I already have Java installed, and it worked.

    Although your post has the correct character case "java HelloWorld" as opposed to "java helloworld" or other variations, I'd REcheck that you really did as you posted.

    You were slightly inconsistent when you posted
    the "Helloworld" kind of program using dos prompt:
    Normally, you would have your custom classes in a different directory than your java and javac binaries, and you would need to set the path.

  3. #3
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Im sorry Vert i didnt read your reply all the way through.
    I went to the city thursday and friday to help out so im a little tired. But i noticed that too. I seems that he is saving his files into the jdk1.3\bin directory and also compiling from there. I dont know what his CLASSPATH is set to but he should try using the -classpath switch to at least get things going. That should be a short term soultion.

  4. #4
    VirtuallyVB
    Guest

    Thumbs up Yes CLASSPATH

    Dil,
    Silly me, I forgot all about the CLASSPATH and -classpath in my reply. I also read about your tuesday incident, but I was speechless. That could have been me a few weeks ago when I was on vacation visiting family in NYC. Glad to see that you are okay.

    Tomexx,
    Dil is right. When you type "set" to see your environment settings, check if CLASSPATH is set to the directory where your *.class files are. In this case, set it to your bin directory

    CLASSPATH=%CLASSPATH%;c:\jdk1.3\bin
    then
    java HelloWorld
    or
    c:\java -classpath c:\jdk1.3\bin HelloWorld

    PATH is really for the DOS shell
    CLASSPATH is for java.exe

    Adjust your "path's" accordingly -- it may not be c:\jdk1.3\bin

    When that works, you might want to have a separate directory for your class files, rather than the bin directory.

  5. #5
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Yes i too forget these things. Im happy too see that your trip was a successful, one and i hope you had fun while you were out there. Looks like your timing was pretty good. Im just glad i was on my way home instead of just getting there when it happened. Even though i was a couple of blocks away it was still scary. I have to fly to South Carolina at the end of October but i think im just going to drive the 10 hours. Maybe ill be safer?

  6. #6
    VirtuallyVB
    Guest
    Dil,
    Luckily we are all safe. Funny that you mention SC. When I lived in NYC, I drove out to SC for a vacation. I took flight lessons for the very first time and soloed in 5 days. I was just looking at my training materials a few hours ago.

    I was going to return the next year, but my instructor had passed away in a non-flight related accident. I didn't find as nice an instructor in the Tri-state area, so I didn't pursue it to completion.

    I've been seeing that compelling "Learn To Fly Here" sign on the news lately and it's stirring up memories and dreams.

    Tom,
    Did the CLASSPATH or -classpath work for you?

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