• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

packages from KB

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in the parent directory of exam :
java -cp . exam.stuff.Tea
 
mohammed khan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks it worked but for all programs regarding packages will it work
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic