New to JAVA > need help on MAC

Discussion in 'Mac Programming' started by bushido, Oct 25, 2010.

  1. macrumors 604

    bushido

    Joined:
    Mar 26, 2008
    Location:
    Planet Earth
    #1
    i just started programming at college and i got the same task working at the school computer running a windows os but i can't get it to work on my mac book pro at home.

    i got JAVA SE 6 installed

    i saved

    Code:
    class Programm1
    {
    	public static void main (String [] args)
    	{
    	double zahl = 0.0;
    	
    	System.out.print("Bitte Zahl eingeben: ");
    	zahl = TerminalInput.readDouble();
    	System.out.println(zahl);
    	} // endmethod main
    
    } // endclass Programm1
    into the text editor and renamed it to "Programm1.java" then i opened the terminal and used javac Programm1.java to open it but when i try "java Programm1" i get the following error


    Exception in thread "main" java.lang.NoClassDefFoundError: Programm1
    Caused by: java.lang.ClassNotFoundException: Programm1
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    Manu-MacBook-Pro:~ Manu$


    what does that even mean?
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    It means java could not find the compiled class file for the class called "Programm1". Are you running java Programm1 from the same directory a teh Programm1.class file? If so ./ is not in your CLASSPATH.
     
  3. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #3
    robbieduncan has it covered, i just wanted to point out a common item that comes up that people might want to be aware of. By copying/pasting from the terminal with the default prompt in OS X you reveal the name of your machine and your username, and if you use the default machine name, then your full name in real life. That may not be a big deal for some, but could be for others. I'm not going to rove the German countryside searching for you now that I know your real name, just a tip in the future if you're worried about people looking for your machine on a large network (then trying to guess your password since they have your username) or knowing you real name.

    Viel Glück!

    -Lee
     
  4. thread starter macrumors 604

    bushido

    Joined:
    Mar 26, 2008
    Location:
    Planet Earth
    #4
    i don't even have a Programm1.class file bc it doesn't make one, on the windows machine it made one after i entered "javac Programm1.java" at school but nothing here on my mac. i think there might be something wrong with my path ...

    i got a folder called "scratch" with the files Programm1.java TerminalInput.class and TerminalInput.html inside which i drag & dropped into the terminal and then ive tried javac Programm1.java

    the main problem is that my teacher won't help me bc i'm not running windows... i really need help i'm kinda screwed
     
  5. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    Right, if you don't have a .class file after running javac then the compiler has errors. Most likely you are not executing javac in the correct place. In the Terminal can you do an ls from just before you execute javac? And paste the exact javac command you are executing (copy and paste it, don't type sort-of what you are executing: we need the exact command).
     
  6. thread starter macrumors 604

    bushido

    Joined:
    Mar 26, 2008
    Location:
    Planet Earth
    #6
    Last login: Mon Oct 25 21:55:32 on ttys000
    Manu-MacBook-Pro:~ Manu$ /Users/Manu/Desktop/scratch
    -bash: /Users/justapurehunk/Desktop/scratch: is a directory
    Manu-MacBook-Pro:~ Manu$ javac Programm1.java
     
  7. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #7
    1) You did not use the ls command: we did not get a list of files
    2) Pasting a path into the terminal does not change directories to that directory. You need to use the cd command.

    Try
    Code:
    cd /Users/Manu/Desktop/scratch
    javac Programm1.java
    java Programm1
    
    (return after each line/command)
     
  8. thread starter macrumors 604

    bushido

    Joined:
    Mar 26, 2008
    Location:
    Planet Earth
    #8
    OMG it works ... now i feel so dumb, i thought it's enough just dragging the folder into the terminal ...

    THX A LOT
     
  9. macrumors 68030

    RaceTripper

    Joined:
    May 29, 2007
    #9
    <rant>Wow. Glad I never had that teacher. Too lazy to help with a simple problem. The "it's not Windows" response is a copout. It's the same problem and solution on Windows and Mac, except that the directory separators for the path are different.

    Disclaimer: I'm a Java programming instructor and strive to help students without wimpy excuses.</rant>

    To the OP. Sounds to me like your instructor didn't do a very good job of explaining the java compiler, interpreter, their relationship, and how they fit into the workflow. But I'm glad the others got you covered here.
     
  10. thread starter macrumors 604

    bushido

    Joined:
    Mar 26, 2008
    Location:
    Planet Earth
    #10
    he really didnt ... he goes through his powerpoint presentation and we have no clue what those words he uses even mean. (he's always like ... we'll get to that later) i basically just typed this code down from my worksheet and saved it as java .... looking forward to tmrw when we have to get a clock app working without any help :eek:
     
  11. macrumors 68030

    Joined:
    Nov 30, 2008
    Location:
    UK
    #11
    Just a little hint from me, get yourself a Java IDE (Eclipse or Netbeans, from which I recommend the former one).

    It really isn't worth "developing" with a text editor and executing the applications via terminal.
     
  12. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #12
    I fundamentally disagree. Do you know what the compiler switches your code is being compiled with are? Do you even know what those switches do? Gain knowledge of the fundamentals, of how things work before obscuring those details with a bulky IDE.
     
  13. macrumors 68040

    plinden

    Joined:
    Apr 8, 2004
    #13
    Hmm no - continue with using the Terminal. Beginners shouldn't use an IDE.

    You learn a lot about the language from the mistakes you make.

    Not only that. Although IDEs are great productivity enhancers for real coding, they become crutches. When you go for job interviews, many places ask you to whiteboard real working code (I know Google, Yahoo and Salesforce do - yes, I've interviewed with them in the past two years) and will mark you down if you make syntax errors - if you use an IDE from the beginning, you'll never learn to pick out errors by eye.
     
  14. macrumors 68030

    Joined:
    Nov 30, 2008
    Location:
    UK
    #14
    I agree with you that IDE's can make you not remembering correct syntax, however, considering that he is in college, he will certainly have to prove his knowledge without using an IDE.

    When I started learning Java in college, we immediately started with using Eclipse instead of using text editors and I although it seemed to be totally overkill in the first lessons to all of us, today I'm really pleased that we did it that way. And yes, there have always been written tests about correct syntax, at least in the first year.
     
  15. macrumors 68030

    RaceTripper

    Joined:
    May 29, 2007
    #15
    I instruct numerous Java classes, and "we'll get to that later" is not a teaching technique I use. ;)

    Bruce Eckel's Thinking in Java is a pretty good book, as is Head First Java from O'Reilly Publishing. They might help you with the "we'll get to that later" parts.

    On the discussion of IDEs, I prefer not using them for the beginner. The complexity of them tend to hinder the learning process more than they help. Until students understand the basic tools and using them on the command line, classpath (i.e. Java, the bad bits), and making some syntax and tools errors they learn from, I don't think an IDE is very helpful.
     
  16. thread starter macrumors 604

    bushido

    Joined:
    Mar 26, 2008
    Location:
    Planet Earth
    #16
    we arent allowed to use any software this first semester bc the exam in late january is about writing the steps down on paper etc without any help. tho we'll get to use eclipse in the 2nd semester. i might come back in here tmrw after my lesson and hopefully someone can help me out once again to get the clock ticking ^^ :)
     
  17. macrumors regular

    Joined:
    Sep 15, 2009
    Location:
    Montreal, Canada
    #17
    I think this really depends on what you're trying to achieve. Agree in principle, but in practice..
     
  18. macrumors 6502

    Joined:
    Nov 7, 2010
    Location:
    Calgary AB
    #18
    I started using Eclipse about half way through my cpsc course that covered Java. This was after I programmed for a full semester in python and then learned java in a text editor. Only once the assignments became larger and more tedious did i start using Eclipse, only because of the helpfulness of it to integrate multiple files and catch my syntax/stupid spelling errors right away rather than having to compile 100+ times just to flush those out.
     
  19. macrumors 68030

    RaceTripper

    Joined:
    May 29, 2007
    #19
    For what it's worth I've been on an assignment where I have to use Eclipse. I can't wait to get back to using Netbeans. I was initially dragged kicking and screaming into Netbeans, but now Eclipse seems primitive and clunky to me.
     

Share This Page