LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-26-2004, 10:00 PM   #1
patpawlowski
Member
 
Registered: Mar 2003
Location: Centreville, Virginia
Distribution: Mandrak, Red Hat
Posts: 163

Rep: Reputation: 30
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.
 
Old 02-26-2004, 10:16 PM   #2
retep
Member
 
Registered: Sep 2003
Distribution: RedHat/Debian
Posts: 50

Rep: Reputation: 15
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
 
Old 02-27-2004, 03:19 AM   #3
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
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");
 
Old 02-27-2004, 06:20 AM   #4
patpawlowski
Member
 
Registered: Mar 2003
Location: Centreville, Virginia
Distribution: Mandrak, Red Hat
Posts: 163

Original Poster
Rep: Reputation: 30
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.
 
Old 02-27-2004, 10:37 AM   #5
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

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

then run the app:
java TestMusicStore
 
Old 02-27-2004, 10:51 AM   #6
patpawlowski
Member
 
Registered: Mar 2003
Location: Centreville, Virginia
Distribution: Mandrak, Red Hat
Posts: 163

Original Poster
Rep: Reputation: 30
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.
 
Old 02-27-2004, 05:25 PM   #7
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie question on java coolguy_iiit Programming 6 05-12-2005 01:47 PM
newbie java swing question... window size true_atlantis Programming 1 10-07-2004 11:17 AM
A very basic newbie question on Java lmellen Programming 5 07-19-2004 04:59 PM
newbie java question lmellen Programming 6 06-30-2004 05:34 PM
Newbie question about executing java command oldoldcat Linux - General 4 01-30-2004 02:15 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration