2011年12月31日星期六

第10天第3节: 包、访问控制权限

1. package definition and import
a. definition:   package org.tx.msdn
b. import:        import org.tx.msdn.*
c. refer: Person per = new org.tx.msdn Person();  or Person per=new Person() if not confict
d. import static: import static org.tx.msdn.Math;
                    if a class contains only static method, using "import static" can assume the method defined is in the current class. ( which means use the mehtod name directly without the class name)

2. compile
  javac -d . Person.java  ==> creates ./org/tx/msdn/Person.class
  java org/tx/msdn/Person

3. jar: same as a directory
  jar -cvf my.jar org
  set classpath=.;my.jar

4. access control of class
public: all
protected: class from same package, derived class from different package
default: class from same package
private: only current class

5. common package
 a. java.lang => implicitly import, contains String...
 b. java.lang.refect ==> low level system
c. java.util ==> tool
d. java.io ==> I/O
e. java.net ==> netowrk
f. java.sql ==> database
g. java.txt ==> internationlaztion


没有评论: