Have you ever been confused by java manual compilation and running? Now, let's summarize:
Step 1: Find out the role of-classpath/-cp
In javac/java: add this parameter to tell the compiler to specify the parameter to be referenced. class file or. java location, accurate to the target file, or the Directory Name of the upper layer of the target folder (if there is a package mechanism.
Step 2: Find out the role of-d
In javac: If the java file contains the package mechanism and the-d + path parameter is added, the corresponding package is generated under the path.
Third point:
If you compile or run the program in the current directory, You can omit the-cp parameter.
Fourth: in java, the default modifier is default, which can be accessed and referenced only under the same package.
Fifth: Well, let's first try it out:
A. java
package p1;public class A{ public int i; public void m() {}}
B. java
package p2;import p1.*;public class B extends A{ public static void main(String[] args){ B b=new B(); System.out.println(b.i); b.m(); }}
A. java/B. java Directory:/home/luo/jdk/lab
Explanation:
Under the lab directory, I find A. java/B. java and compile and generate p1 translate under the jdk directory? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> keys + keys/2z8LE3NXStb2howo8YnI + Cgo8YnI + Cgo8YnI + keys" http://www.2cto.com/uploadfile/Collfiles/20140425/20140425090854398.png "alt =" \ ">
Next, we will explain:
When compiling A. java/B. java, pwd =/home/luo/jdk.
Generate p1.A under jdk/lab and p2. B under jdk,
When the class is finally loaded, the directory I am in IS/home/luo.
So when you load a class, you need to specify the p1.A p2. B path, and use"
: "Connected, and then specify the name of the class to be run, that is, the class containing the main () function.