LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Java Newbie Question (https://www.linuxquestions.org/questions/programming-9/java-newbie-question-150975/)

patpawlowski 02-26-2004 09:00 PM

Java Newbie Question
 
I just started working on the Java tutorial on Sun's website and didn't make it past the second program. First I downloaded j2eesdk-1_4-dr-linux-eval but couldn't get it to run. However, Mandrake apparently came with a Java compiler so I was going to proceed using it. The Hello World app worked just fine but now I am on the second app and I am having a problem. Here are the details:

The error:

[pat@linux java]$ javac TestMusicStore.java

TestMusicStore.java:3: error: Type `MusicStore' not f
MusicStore m = new MusicStore();
^
1 error

The contents of the 2 files:

[pat@linux java]$ cat TestMusicStore.java

public class TestMusicStore {
public static void main(String[] args) {
MusicStore m = new MusicStore();
m.displayHoursOfOperation();
System.exit(0);
}
}

[pat@linux java]$ cat MusicStore.java

// Copyright MageLang Institute; Version $Id: //depot
ore/MusicStore.java#2 $
public class MusicStore {
void displayHoursOfOperation() {
System.out.println("Store Hours:");
System.out.println("Daily: 9am - 9pm"
}
}

Any help would be greatly appreciated. Expecially since I basically just cut and pasted these from the tutorial.

retep 02-26-2004 09:16 PM

You need to comple MusicStore before TestMusicScore. (e.g. check the .class file exists).

javac -classpath . -sourcepath . *.java should work. Or maybe just javac *.java

Looking_Lost 02-27-2004 02:19 AM

Unless it's a typo/cut'n'paste error, the bracket hasn't been closed

System.out.println("Daily: 9am - 9pm"

should be

System.out.println("Daily: 9am - 9pm");

patpawlowski 02-27-2004 05:20 AM

It was a cut-n-paste error. Which, by the way, is really starting to tick me off in linux. Sometimes cut-n-paste works sometimes not. In order to get that posted to this board I had open up a different terminal so I could save the history as a text file and then open the text file so I could then cut and paste and it still screwed up. Anyway, back to the topic at hand.

TestMusicStore.java, MusicStore.java, and MusicStore.class are all in the same ~/java directory which is where I am running javac from. I didn't fully understand the command line switches. Everthing that I tried, the compiler didn't understand and I'm not getting any information from my system "man javac", "javac --help", "javac -h", "javac -?" all produce nothing.

coolman0stress 02-27-2004 09:37 AM

compile both files at the same time:
javac TestMusicStore.java MusicStore.java

then run the app:
java TestMusicStore

patpawlowski 02-27-2004 09:51 AM

Excellent! Is that always necessary? Probably not! I don't understand why it couldn't find MusicStore.class, is it looking somewhere other than the current directory? I'm not sure how Java is installed on my system since it was installed by default.

coolman0stress 02-27-2004 04:25 PM

Regular, yes, that's required. l But there are ways around it (dynamic class loading)


All times are GMT -5. The time now is 12:55 PM.