Results 1 to 9 of 9
  1. #1
    rudy272 is offline Member
    Join Date
    Jan 2014
    Posts
    3
    Rep Power
    0

    Default New to Java! Would like help :D

    Hello everyone I'm Rudy! I am a complete beginner when it comes to programming, I hold my A+ certification but programming is a whole other realm. Anyway, I purchases " Java A beginners Guide" by Herbert Schildt and I like the way it teaches so far. However I am starting the first few examples of code they give me and I run into a problem. For example I compile a program so.. "javac Example2.java", everything goes smoothly but then when I try java Example2 I get what I assume is an error. The first line reads " Exception in thread "main" java.lang.NoClassDefFoundError: Example2 (wrong name: example2)" Then it follows with about 10 lines of

    at.java.lang
    at.java.security
    and then a bunch of other at. blah blah.

    Any advice??

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,784
    Rep Power
    5

    Default Re: New to Java! Would like help :D

    Quote Originally Posted by rudy272 View Post
    Any advice??
    Yes! For starters, show your code and the exception trace.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,572
    Rep Power
    25

    Default Re: New to Java! Would like help :D

    Java is case sensitive. Make sure to use the same case when defining and using variables and class names.
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    rudy272 is offline Member
    Join Date
    Jan 2014
    Posts
    3
    Rep Power
    0

    Default Re: New to Java! Would like help :D

    Quote Originally Posted by jim829 View Post
    Yes! For starters, show your code and the exception trace.

    Regards,
    Jim
    Here is the code the book has me using, forgive me if this is not the format the forum wants it displayed in as im not sure how to do it.

    /*this demonstrates a variable
    call this file example2.java
    */
    class example2 {
    public static void main(String args[]) {
    int var1; //this declares a variable
    int var2; //this declares another variable
    var1 = 1024; // this assigns 1024 to var1

    System.out.println("var1 contains " + var1);

    var2 = var1 / 2;

    System.out.println("var2 contains var1 / 2: ");
    System.out.println(var2);
    }
    }



    And the error I get is attached in this screenshot:
    New to Java! Would like help :D-java-error.jpgClick image for larger version. 

Name:	java error.JPG 
Views:	19 
Size:	56.8 KB 
ID:	5875

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,784
    Rep Power
    5

    Default Re: New to Java! Would like help :D

    Looks like the actual name of the file is Example2.java and not example2.java.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  6. #6
    rudy272 is offline Member
    Join Date
    Jan 2014
    Posts
    3
    Rep Power
    0

    Default Re: New to Java! Would like help :D

    Quote Originally Posted by jim829 View Post
    Looks like the actual name of the file is Example2.java and not example2.java.

    Regards,
    Jim
    Could that cause the error i'm receiving? I didnt even notice the "e" was lower case in the code.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,572
    Rep Power
    25

    Default Re: New to Java! Would like help :D

    See post#3
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    zFollette is offline ▼ dafuq did I do?
    Join Date
    Dec 2013
    Posts
    203
    Rep Power
    0

    Default Re: New to Java! Would like help :D

    Quote Originally Posted by rudy272 View Post
    Could that cause the error i'm receiving? I didnt even notice the "e" was lower case in the code.
    It is causing it, no questions. All class names have to equal the name of the file.

    EDIT: Except when you combine multiple classes, but even then, the first defined class name has to equal the file name.
    1000011 1100001 1101110 100000 1111001 1101111 1110101 100000 1110010 1100101 1100001 1100100 100000 1000010 1101001 1101110 1100001 1110010 1111001 111111

  9. #9
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,658
    Blog Entries
    7
    Rep Power
    21

    Default Re: New to Java! Would like help :D

    Quote Originally Posted by zFollette View Post
    EDIT: Except when you combine multiple classes, but even then, the first defined class name has to equal the file name.
    The file name should equal the name of the public class defined in the file, not the first class in the file.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Posting Permissions

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