• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

K&B Exercise 1-1

 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do as illustrated in code and the I got following


my class path is set ok to directory which have food directory inside it and I placed Fruit class as instructed ,
can you please tell me where I am wrong
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there.
Can you give a little more information?
Your classpath should be set to a directory that contains
the directory food as a subdirectory.That's assuming you placed
the class file in a directory called food.

For example:
package foo;
public class MyClass{}

Say I am in directory, C:\My Java
and the source file MyClass.java is there,
I would compile MyClass.java like so:
(Note javac will look in the current directory for the source file,
by default)

javac -d . MyClass.java

The -d flag specifies where you want to place the resulting class file.
Here I specified '.' which means the current directory (C:\My Java)
and it will also create the necessary directory 'foo' in which you will find the class file.
Now to run the class file you have to make sure your class path contains an entry that will have the directory 'foo' as a subdirectory.
Lets say we have the classpath set as a system variable like:
C:\My Java;. this means, look in C:\My Java or the current directory.
Note the ; delimiter that separates classpaths.
OR You could specifiy the classpath on the command line and
run the above class file like so: (Assume you are in the C:\My Java directory) C:\My Java>java -classpath . foo.MyClass
Hope this helps.
Best regards,
K
[ June 22, 2008: Message edited by: Keith Nagle ]
 
vaibhav mishra
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is entry in my classpath


and I placed my food file in
and after copiling fruit file source I placed in directory food as instructed and then I give the command

however I didn't use -d option
 
Keith Nagle
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by vaibhav katyayan:
this is entry in my classpath


and I placed my food file in
and after copiling fruit file source I placed in directory food as instructed and then I give the command

however I didn't use -d option



Hi again. Im looking at the exercise now and there is no food file.
food represents the directory where the Fruit.class should reside.
It's important that you remember that the classpath is evaluated from left to right.
Try this: Go to the directory that you have the source file in i.e from the command line type: cd G:\Documents and Settings\vaibhav\Desktop\source
Make sure teh Fruit.java is in there. Compile it like this:
G:\Documents and Settings\vaibhav\Desktop\source>javac -d . Fruit.java
This will create a sub directory in source that will be called food.
AND it will have Fruit.class in there.
So lets assume that Apple.java is in source also.To compile it, you will have to tell it where Fruit.class is, and you do that like this:
G:\Documents and Settings\vaibhav\Desktop\source>javac -classpath . Apple.java
That should then produce your class file. Note that since your system class path already contains a '.' which means "Current directory" supplying -classpath . at the command line is superfluous but im only saying this assuming that your classpath is correct.
Try that and see how you get on.
Best regards.
[ June 22, 2008: Message edited by: Keith Nagle ]
 
vaibhav mishra
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Keith, It seems that I totally misunderstood the problem but your explanation helps
thanks again
 
Popeye has his spinach. I have this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic