This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Package Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Package Problem" Watch "Package Problem" New topic
Author

Package Problem

kaushik saha
Greenhorn

Joined: Sep 22, 2005
Posts: 18
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.
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
Back out to the root directory that contains the Automobile folder and execute:

javac Automobile\car.java


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
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 ]

cmbhatt
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
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

Joined: Feb 28, 2007
Posts: 1707

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
 
jQuery in Action, 2nd edition
 
subject: Package Problem
 
Similar Threads
Is Java too difficult for me? Trying to learn with Head first Javabook
need packages help
constructor to add to an array list
instanceof operator
abstract class