• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Package Problem

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote a java program(named vechile.java) in a file in the package Automobile.

package Automobile;

public abstract class vechile
{
public abstract void speed();
}


Now in diffrent file but in a same package i wrote another java program (named car.java)

package Automobile;

public class car extends vechile
{
public void speed()
{
System.out.println("car specific speed");
}
}


My problem is that i can not compile car.java. The compiler error is "vechile class not found".

I have kept the two program in the Automobile folder.

And when compile then i write this way

f:/Automobile/>javac car.java;


why the second one is not compiling..

Please give me your valueable suggestion.
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Back out to the root directory that contains the Automobile folder and execute:

javac Automobile\car.java
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kausik,


Your problem is obvious!

Did you compile the Vehicle.java.

Because Car extends Vehicle so, javac finds Vehicle.class, that is not yet created. Dont think like javac finds for .java files.

You can do like this also;

> javac Vehicle.java Car.java

or

> javac Car.java Vehicle.java

Order doesn't matter here!


Does this help you?


Why do you go inside Automobile to just compile your .java
if no package exits, Automobile will automatically created when you
compile your source file.


You need to mention the full class name when executing you .class file:

> java Automobile.Car
or
? java Automobile/Car




Regards,
cmbhatt
[ April 11, 2007: Message edited by: Chandra Bhatt ]
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dont think like javac finds for .java files.


javac does find dependent .java files on the source path and compile them.
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


javac does find dependent .java files on the source path and compile them.




Then what is the case of Kaushik, why Vehicle not found. And very importantly referring to package while compiling is hard to swallow. Package is created when you compile the source if not already existing.

I found the obvious reason to answer because of the compiler error "Vehicle.class" not found. If your statement is right, why didn'y it compile Vehicle.java on which Car.java is dependent (Car extends Vehicle).


Please give your kind comments on this!

cmbhatt
 
catch it before it slithers away! Oh wait, it's a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic