package:

package:

i hv created created a package and save it into D directive and also set permanent path when i compile it ,it compile successfully but it can't run with following command: java mypackage.classname

what's problem ?

View Answers

September 28, 2011 at 3:22 PM

Suppose we have a file called HelloWorld.java, and put this file in a package world. The we specify the keyword package with the name of the package.

package world;

public class HelloWorld {
  public static void main(String[] args) {
    System.out.println("Hello World");
  }
}

When compiling HelloWorld class, just go to the world directory and type the command:

C:\world\javac HelloWorld.java

Then run as:

C:\world>java world.HelloWorld









Related Tutorials/Questions & Answers:

Ads