aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes packages from KB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "packages from KB" Watch "packages from KB" New topic
Author

packages from KB

mohammed khan
Greenhorn

Joined: Jun 22, 2007
Posts: 3
not able to execute below 2 programs ?how to execute it .

package cert;
public class Beverage
{
}


package exam.stuff;
import cert.Beverage;
class Tea extends Beverage

{
public static void main(String argd[])
{
System.out.println("hello world");
}

}


I am able to compile above 2 programs but when i am executing i am geting exception in thread main. so how can i execute this Tea program
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
Check if the current directory is in your classpath. I think that's your problem.

More information over the classpath can be found here

Setting classpath


Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

in the parent directory of exam :
java -cp . exam.stuff.Tea


[My Blog]
All roads lead to JavaRanch
mohammed khan
Greenhorn

Joined: Jun 22, 2007
Posts: 3
thanks it worked but for all programs regarding packages will it work
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

You have to understand how java is looking for your classes. When you run your program java looks for the main class, into your CLASSPATH.

For example, if you have :
c:\java\exam\stuff\Tea.class
and you want to run it from d:\, you have to tell java that the top package is in c:\java. There are different ways to do it, one of which being to pass the classpath as a command line argument :
d:\java -cp c:\java exam.stuff.Tea
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: packages from KB
 
Similar Threads
Question on Packages from Kathy Sierra Book
Troubling with this code
what happens at runtime?
Certification cx 310-035
Unable to grasp compiling and running multiple files