Page 1 of 2 12 LastLast
Results 1 to 20 of 24

Thread: just starting

  1. #1
    specbailey is offline Member
    Join Date
    Jul 2007
    Posts
    10
    Rep Power
    0

    Default just starting

    I am just starting to learn java, I have some programs coded, but when I enter javac into the command prompt, it gives me an error saying "javac is not recognized as an internal or external command, operable program or batch file." I adjusted my environment variables (class path & path), but still no luck. What do I need to configure to get this to work?

  2. #2
    Seemster is offline Member
    Join Date
    Jul 2007
    Posts
    55
    Rep Power
    0

    Default

    Add the location of your java home to your path. Try running java -version from the command prompt. I'm thinking it'll throw an error. Once you've defined the entry correctly, the above command should work.

  3. #3
    specbailey is offline Member
    Join Date
    Jul 2007
    Posts
    10
    Rep Power
    0

    Default

    when i type in java -version it comes back fine, with a version of 1.6.0_01. what is the java home path location?

  4. #4
    specbailey is offline Member
    Join Date
    Jul 2007
    Posts
    10
    Rep Power
    0

    Default

    ok, i added the java path location, now I can compile the program but can't run it. I get an error that says "Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld"

    How do I fix this?

  5. #5
    Seemster is offline Member
    Join Date
    Jul 2007
    Posts
    55
    Rep Power
    0

    Default

    are you running the javac from the same directory the program is in? you can supply classpath information by:

    javac -cp <classpath>

  6. #6
    specbailey is offline Member
    Join Date
    Jul 2007
    Posts
    10
    Rep Power
    0

    Default

    yes, I'm running it from the folder that my program is saved on. but still getting the same error message

  7. #7
    Seemster is offline Member
    Join Date
    Jul 2007
    Posts
    55
    Rep Power
    0

    Default

    Can you post the exact command your using to execute the code.

  8. #8
    specbailey is offline Member
    Join Date
    Jul 2007
    Posts
    10
    Rep Power
    0

    Default

    in the directory that my program is saved in I type:
    javac HelloWorld.java

    that comes back fine, and a HelloWorld.class file is created
    then I type:
    java HelloWorld

    and then i receive the error:
    "Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld"

  9. #9
    Seemster is offline Member
    Join Date
    Jul 2007
    Posts
    55
    Rep Power
    0

    Default

    I don't know what your doing wrong. I just wrote a quick class to that. From the command prompt where your file is at:

    1. javac HelloWorld.java
    2. java HelloWorld

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

    >>>>>>>>>>>>>>>>>>>>>>
    output
    >>>>>>>>>>>>>>>>>>>>>>
    HelloWorld

  10. #10
    specbailey is offline Member
    Join Date
    Jul 2007
    Posts
    10
    Rep Power
    0

    Default

    the only thing i can think of are the environment variables, but i've tried changing them, with no luck.

  11. #11
    levent Guest

    Default

    specbailey: Working with classpath is not easy. You will need to practice about it. There are several resources to read for learning managing classpath.

    But alternatively you can try to use an IDE (Eclipse or Netbeans) which will make the classpath management intuitive.

  12. #12
    specbailey is offline Member
    Join Date
    Jul 2007
    Posts
    10
    Rep Power
    0

    Default

    I am still having the same problems. I cannot compile programs or execute them. I have checked the path and the classpath. What else do I need to do to run java programs?

  13. #13
    specbailey is offline Member
    Join Date
    Jul 2007
    Posts
    10
    Rep Power
    0

    Default

    when I type javac HelloWorld.java I get an error that says:
    'javac' is not recognized as an internal or external command, operable program or batch file.

    which means that it will not compile so I cannot go on from there.

    When I type java -version i get:
    java version "1.6.0_01"
    Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
    Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)

  14. #14
    vibhor.ec is offline Member
    Join Date
    Aug 2007
    Posts
    2
    Rep Power
    0

    Default

    do 1 thing,just save ur programm in bin folder in ur jdk directory and then simply compile it.........javac HelloWorld.java

    else tell me ur full path of java directory

  15. #15
    Neon Blue is offline Member
    Join Date
    Aug 2007
    Posts
    5
    Rep Power
    0

    Default

    specbailey,
    Thank you for your post. It sounds as though you and I are having the same kind of problems. I infer that you are using Java 2 SDK 1.6.x.x. Is the OS WinXP? and you are trying to compile and run a "Hello World" program from Command Prompt.

    The error message you get when you try javac Hello World.java is the same as I get.

    So when I try to configure SDK 1.3.1_20 according to the text I am reading I need to find a file AUTOEXEC.BAT, which I cannot. Apparently the OS in play when the book was published was 2000 and NT. Not being a Windows user I asked another forum about this file and was directed to a MS instruction page where I learn that the variables once maintained by AUTOEXEC.BAT are now maintained by the Registry in XP. Going to My Computer, as you did, I found the editing feature for environmental variables under Propeerties, but I do not know what information to add so as to point to PATH and CLASSPATH for Java. What entrys did you make?

    Thanks

  16. #16
    Vengeance45 is offline Member
    Join Date
    Aug 2007
    Posts
    2
    Rep Power
    0

    Default

    Spec, can you copy your code in? Wondering if you have declared a package.

  17. #17
    marco is offline Member
    Join Date
    Jul 2007
    Posts
    23
    Rep Power
    0

    Default

    its not a problem with the code, in cmd u were passing arguments wrong, what i did was just right clicked on the .java and selected "open with" and opened it with javac.exe, i would also recommend downloading JKD 6.0 or higher and running it with the javac.exe in the JDK bin
    :)

  18. #18
    specbailey is offline Member
    Join Date
    Jul 2007
    Posts
    10
    Rep Power
    0

    Default

    I copied my .java file into the bin folder, now I am able to compile the program and there is a .class created, but now I can't execute the program by typing:
    java HelloWorld

    I get an error that says:
    Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld/class

    even though it compiled ok.

  19. #19
    marco is offline Member
    Join Date
    Jul 2007
    Posts
    23
    Rep Power
    0

    Default

    what type of template is the program? hsa, applet, application?

  20. #20
    specbailey is offline Member
    Join Date
    Jul 2007
    Posts
    10
    Rep Power
    0

    Default

    I don't know what template the program is... here is the code:
    public class HelloWorld {
    public static void main(String[] args) {
    System.out.println("Hello World");
    }
    }

Page 1 of 2 12 LastLast

Similar Threads

  1. Indexing starting with 1
    By ravian in forum New To Java
    Replies: 4
    Last Post: 01-04-2008, 01:03 PM
  2. Help, starting with java
    By mathias in forum New To Java
    Replies: 2
    Last Post: 08-15-2007, 08:15 AM

Posting Permissions

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