Java·´Éä2
1.2.3.ConstructorÀࣺ
ConstructorÀà´ú±íij¸öÀàµÄÒ»¸ö¹¹Ôì·½·¨¡£
µÃµ½Ä³¸öÀàËùÓеĹ¹Ôì·½·¨£º
Constructor[] constructor = Class.forName(“java.lang.String”).getConstructor();
µÃµ½Ä³Ò»¸ö¹¹Ôì·½·¨£º
Constructor constructor =
Class.forName(“java.lang.String”).getConstructor(StringBuffer.class);
´´½¨ÊµÀý¶ÔÏó£ºString str2 = (String)constructor1.newInstance(new StringBuffer("abc"));
1.2.4.FieldÀࣺ
Field´ú±íij¸öÀàµÄÒ»¸ö³ÉÔ±±äÁ¿¡£ÌṩÓйØÀà»ò½Ó¿ÚµÄÊôÐÔµÄÐÅÏ¢£¬ÒÔ¼°¶ÔËüµÄ¶¯Ì¬·ÃÎÊȨÏÞ¡£·´ÉäµÄ×ֶοÉÄÜÊÇÒ»¸öÀࣨ¾²Ì¬£©ÊôÐÔ»òʵÀýÊôÐÔ£¬¼òµ¥µÄÀí½â¿ÉÒÔ°ÑËü¿´³ÉÒ»¸ö·â×°·´ÉäÀàµÄÊôÐÔµÄÀà¡£
public void setAccessible(boolean flag)
ÉèÖÃÊÇ·ñÓÐȨÏÞ·ÃÎÊ·´ÉäÀàÖеÄ˽ÓÐÊôÐԵģ¬Ö»ÓÐÉèÖÃΪtrueʱ²Å¿ÉÒÔ·ÃÎÊ£¬Ä¬ÈÏΪfalse¡£
public void set(Object obj,Object value)
ÉèÖÃÖ¸¶¨ÊôÐÔµÄÖµ¡£
public Object get(Object obj)
µÃµ½ÊôÐÔµÄÖµ
ÎÊÌ⣺µÃµ½µÄField¶ÔÏóÊǶÔÓ¦µ½ÀàÉÏÃæµÄ³ÉÔ±±äÁ¿£¬»¹ÊǶÔÓ¦µ½¶ÔÏóÉϵijÉÔ±±äÁ¿£¿ÀàÖ»ÓÐÒ»¸ö£¬¶ø¸ÃÀàµÄʵÀý¶ÔÏóÓжà¸ö£¬Èç¹ûÊÇÓë¶ÔÏó¹ØÁª£¬ÄǹØÁªµÄÊÇÄĸö¶ÔÏóÄØ£¿
²âÊÔ´úÂ룺
public class ReflectPoint {
private int x;
public int y;
public ReflectPoint(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}
²âÊÔ´úÂ룺
ReflectPoint pt1 = new ReflectPoint(3,5);
Field fieldY = pt1.getClass().getField("y");
//fieldYµÄÖµÊǶàÉÙ£¿ÊÇ5,´í£¡fieldY²»ÊǶÔÏóÉíÉϵıäÁ
Ïà¹ØÎĵµ£º
Javaѧϰ´ÓÈëÃŵ½¾«Í¨
Ò»¡¢ JDK (Java Development Kit)
JDKÊÇÕû¸öJavaµÄºËÐÄ£¬°üÀ¨ÁËJavaÔËÐл·¾³£¨Java Runtime Envirnment£©£¬Ò»¶ÑJava¹¤¾ßºÍJava»ù´¡µÄÀà¿â(rt.jar)¡£²»ÂÛʲôJavaÓ¦Ó÷þÎñÆ÷ʵÖʶ¼ÊÇÄÚÖÃÁËij¸ö°æ±¾µÄJDK¡£Òò´ËÕÆÎÕJDKÊÇѧºÃJavaµÄµÚÒ»²½¡£×îÖ÷Á÷µÄJ ......
µÚÒ»£¬Ì¸Ì¸final, finally, finalizeµÄÇø±ð¡£
×î³£±»Îʵ½¡£
µÚ¶þ£¬Anonymous Inner Class (ÄäÃûÄÚ²¿Àà) ÊÇ·ñ¿ÉÒÔextends(¼Ì³Ð)ÆäËüÀ࣬ÊÇ·ñ¿ÉÒÔimplements(ʵÏÖ)interface(½Ó¿Ú)?
µÚÈý£¬Static Nested Class ºÍ Inner ClassµÄ²»Í¬£¬ËµµÃÔ½¶àÔ½ºÃ(ÃæÊÔÌâÓеĺÜÁýͳ)¡£
µÚËÄ£¬&ºÍ&&µÄÇø±ð¡£
Õâ¸öÎʵúÜÉÙ¡£
......
±àÒëʱ´ò°ü£º
javac -d "Òª°Ñ°ü´òµ½ÄÄ£»ÅÌ·û»òÕß.(.±íʾµ±Ç°Ä¿Â¼)" ÎļþÃû.java
Ö´Ðдò°üµÄ.classÎļþ
java -cp(cp´ú±íÁÙʱµÄ»·¾³±äÁ¿) "ÊäÈë.classÎļþËùÔÚµÄÅÌ·û£¬Èç¹ûÔÚµ±Ç°Îļþ¼Ð£¬¾ÍÊäÈë“.”" "¼Èë.classÎļþËùÔڵķ¾¶£¨°üÀ¨ÎļþÃû£¬²»ÐèÒª´ò.java£©"
ÉèÖÃÁÙʱ»·¾³±äÁ ......
·¢²¼JavaÓ¦ÓóÌÐòʱÄã»á¸Ðµ½À§ÄÑ£¿ºÃÔÚJavaÌṩÁËһϵÁдò°üºÍ·¢²¼¹¤¾ß£¬¿ÉÒÔÏÔÖøµÄ¼ò»¯·¢²¼¹ý³Ì
¡¡¡¡
¡¡¡¡¸ÃÎÄÕÂÌṩÁË´ò°üJava codeµÄ¼¸ÖÖ·½·¨£¬ÎÒÃǽ«»á̽ÌÖJava manifest Îļþ£¬¸ø³öÓÃÓÚ¹ÜÀíJARÎļþËùÒÀÀµÎļþ¡¢¹À¼Æ¿çƽ̨·¢²¼ËùÐèµÄCLasspathµÄºÏÊÊ·½·¨.ÎÒÒ²»á½âÊÍÈçºÎʹÓÃmanifest°ü°æ±¾ÌØÐÔÀ´È·ÈÏ°üµÄ¼æÈÝÐÔ...
¡ ......
½ñÌ칫˾²»ÊǺÜ棬¾Í»Ø¹ËÁËÒ»ÏÂÒÔÇ°µÄðÅÝÅÅÐòºÍ²åÈëÅÅÐò
package chen;
import java.util.Date;
public class Sort {
/**
* ðÅÝÅÅÐò
* @param list
* @author chenpengye
*/
public void sort(int[] list){
long begain=new Date().getTime();
&n ......