• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

javac question

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q.5 of K&B-

Given the directory structure-
foo
|
test
|
xcom
|--A.class
|--B.java

And the two files-
package xcom;
public class A {}

package xcom;
public class B extends A {}

Why doesn't the invocation,
javac -classpath . B.java
work, when given from xcom directory?

In the first para on pg. 768 of the book, it is clearly mentioned that by adding the . to the classpath, the java command looks for the required class in the current directory - so where is the problem?, A.class is in the current directory.

Why does the invocation,
javac -classpath . xcom/B.java
work, when given from test directory?

Please explain.

Regards
Percy
[ May 26, 2007: Message edited by: Percy Dadabhoy ]
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class A has a signature xcom.A

when you run

javac -classpath . B.java
starting from xcom dir it searches for another xcom directory in xcom having class A (some thing like this xcom/xcom/A) since B is extending A and A has signature as xcom.A

so if you make a dir in xcom named "xcom" and copy the A.class in it the command javac -classpath . B.java will work

but when you use

javac -classpath . xcom/B.java

it is able to locale xcom.A as xcom is a directory within test.
 
Percy Dadabhoy
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Kedar in clarifying my doubt.
 
Joel Salatin has signs on his property that say "Trespassers will be Impressed!" Impressive tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic