I just know how to create a package just开发者_高级运维 by declaring it at the top of the class but I dont know the code for creating it
package myPackage;
class test{
system.out.println("Hello every one");
}
please provide me the code to compile it
This should be your lesson of the day :)
http://download.oracle.com/javase/tutorial/java/package/packages.html
Read from end to end, and don't forget this page http://download.oracle.com/javase/tutorial/java/package/managingfiles.html
Read these for compiling options:
- http://www.cs.princeton.edu/courses/archive/fall97/cs461/jdkdocs/tooldocs/win32/javac.html
- http://download.oracle.com/javase/1.4.2/docs/tooldocs/windows/javac.html
A package is 'created' by the folder hierarchy it is in. For example, your test
class is in the myPackage
package, which has to be in a folder called myPackage.
If your classes are in packages, then Java expects your source files to be in a directory structure that looks like the package structure. In this case, make a directory called myPackage and put test.java in that directory. Then from the directory the myPackage directory is in, run javac myPackage/test.java
. This will create a test.class file in the myPackage directory. If test.java had a main function defined in it, you could then, from the same directory, run java myProject.test
.
The 'test' class is supposed to be public, and put it under folder "myPackage". The folder is package.
精彩评论