PDA

View Full Version : New to JAVA > need help on MAC




bushido
Oct 25, 2010, 01:44 PM
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

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?



robbieduncan
Oct 25, 2010, 02:01 PM
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.

lee1210
Oct 25, 2010, 02:49 PM
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

bushido
Oct 25, 2010, 02:49 PM
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

robbieduncan
Oct 25, 2010, 02:52 PM
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).

bushido
Oct 25, 2010, 02:57 PM
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

robbieduncan
Oct 25, 2010, 02:59 PM
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

cd /Users/Manu/Desktop/scratch
javac Programm1.java
java Programm1


(return after each line/command)

bushido
Oct 25, 2010, 03:01 PM
OMG it works ... now i feel so dumb, i thought it's enough just dragging the folder into the terminal ...

THX A LOT

RaceTripper
Oct 25, 2010, 03:09 PM
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

<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.

bushido
Oct 25, 2010, 03:14 PM
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.

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:

Transporteur
Oct 25, 2010, 03:22 PM
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.

robbieduncan
Oct 25, 2010, 03:24 PM
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.

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.

plinden
Oct 25, 2010, 03:28 PM
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.

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.

Transporteur
Oct 25, 2010, 03:39 PM
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.

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.

RaceTripper
Oct 25, 2010, 04:12 PM
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:
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.

bushido
Oct 25, 2010, 05:30 PM
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 ^^ :)

Mikey7c8
Dec 22, 2011, 09:22 PM
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.

I think this really depends on what you're trying to achieve. Agree in principle, but in practice..

tmagman
Dec 23, 2011, 09:04 PM
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.

RaceTripper
Dec 23, 2011, 09:09 PM
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.