javaÉè¼Æģʽ ²ßÂÔģʽ
¶¨Òå:¶¨ÒåÁËËã·¨×壬·Ö±ð·â×°ÆðÀ´£¬ÈÃËüÃÇÖ®¼ä¿ÉÒÔ»¥ÏàÌæ»»£¬´ËģʽÈÃËã·¨µÄ±ä»¯¶ÀÁ¢ÓÚʹÓÃËã·¨µÄ¿Í»§¡£
ÊÊÓÃÐÔ
Ðí¶àÏà¹ØµÄÀà½ö½öÊÇÐÐΪÓÐÒì¡£“²ßÂÔ”ÌṩÁËÒ»ÖÖÓöà¸öÐÐΪÖеÄÒ»¸öÐÐΪÀ´ÅäÖÃÒ»¸öÀàµÄËã·¨¡£
ÐèҪʹÓÃÒ»¸öËã·¨µÄ²»Í¬±äÌå¡£ÀýÈ磬Äã¿ÉÄܻᶨÒåһЩ·´Ó³²»ÈݵĿռä/ʱ¼äȨºâµÄËã·¨¡£µ±ÕâЩ±äÌåʵÏÖÁËÒ»¸öËã·¨µÄÀà²ã´Îʱ[H087],¿ÉÒÔʹÓòßÂÔģʽ¡£
Ë㷨ʹÓÿͻ§²»Ó¦¸ÃÖªµÀµÄÊý¾Ý¡£¿ÉÒÔʹÓòßÂÔģʽÒÔ±ÜÃⱩ¶¸´Ôӵġ¢ÓëËã·¨Ïà¹ØµÄÊý¾Ý½á¹¹¡£
Ò»¸öÀඨÒåÁ˶àÖÖÐÐΪ£¬²¢ÇÒÕâЩÐÐΪÔÚÕâ¸öÀàµÄ²Ù×÷ÖÐÒÔ¶à¸öÌõ¼þÓï¾äµÄÐÎʽ³öÏÖ¡£½«Ïà¹ØµÄÌõ¼þ·ÖÖ§ÒÆÈëËüÃǸ÷×ÔµÄStrategyÀàÖÐÒÔ´úÌæÕâЩÌõ¼þÓï¾ä¡£
Àý×Ó:ÒÔϵÄÀý×ÓÈ¡×ÔÒ»¸ö¶¯×÷ðÏÕÓÎÏ·¡£Ä㽫¿´µ½´ú±íÓÎÏ·½ÇÉ«µÄÀàºÍ½ÇÉ«¿ÉÒÔʹÓõÄÎäÆ÷ÐÐΪµÄÀࡣÿ¸ö½ÇÉ«Ò»´ÎÖ»ÄÜÖ»ÓÃÒ»ÖÖÎäÆ÷£¬µ«ÊÇ¿ÉÒÔÔÚÓÎÏ·µÄ¹ý³ÌÖÐÇл»ÎäÆ÷¡£
1£º¶¨ÒåÎäÆ÷½Ó¿Ú¼°ÊµÏÖÀà
package strategy;
/**
* ¶¨ÒåÎäÆ÷ÐÐΪ½Ó¿Ú
* @author User
*
*/
public interface WeaponBehavior {
public void userWeapon();//Ñ¡ÔñËùʹÓõÄÎäÆ÷
}
package strategy;
public class BowAndArrorBehavior implements WeaponBehavior {
/**
* ʵÏÖÓù¼ýÉä»÷
*/
public void userWeapon() {
System.out.println("Óù¼ýÉä»÷");
}
}
package strategy;
public class SwordBehavior implements WeaponBehavior {
/**
* ʵÏÖÓñ¦½£¹¥»÷ÐÐΪ
*/
public void userWeapon() {
System.out.println("Óñ¦½£¹¥»÷!!");
}
}
package strategy;
public class KnightBehavior implements WeaponBehavior {
/**
* ʵÏÖÓÃØ°Ê×´ÌɱµÄÐÐΪ
*/
public void userWeapon() {
System.out.println("ÓÃØ°Ê×´Ìɱ!!");
}
}
2£º¶¨Òå½ÇÉ«
package strategy;
/**
*
Ïà¹ØÎĵµ£º
Java NIO APIÏê½â
ÔÚJDK
1.4ÒÔÇ°£¬JavaµÄIO²Ù×÷¼¯ÖÐÔÚjava.ioÕâ¸ö°üÖУ¬ÊÇ»ùÓÚÁ÷µÄ×èÈû£¨blocking£©API¡£¶ÔÓÚ´ó¶àÊýÓ¦ÓÃÀ´Ëµ£¬ÕâÑùµÄAPIʹÓúܷ½
±ã£¬È»¶ø£¬Ò»Ð©¶ÔÐÔÄÜÒªÇó½Ï¸ßµÄÓ¦Óã¬ÓÈÆäÊÇ·þÎñ¶ËÓ¦Óã¬ÍùÍùÐèÒªÒ»¸ö¸üΪÓÐЧµÄ·½Ê½À´´¦ÀíIO¡£´ÓJDK 1.4Æð£¬NIO
API×÷Ϊһ¸ö»ùÓÚ»º³åÇø£¬²¢ÄÜÌṩ·Ç×èÈû(non-blo ......
Õª×Ô£ºÇ§Àï±ù·â
/*
* CaptureScreen.java
*
* Created on 2007Äê8ÔÂ30ÈÕ, ÏÂÎç12:46
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package hadeslee.swing;
/**
*
* @author lbf
* ......
SunÔÚJava5ÖУ¬¶ÔJavaÏ̵߳ÄÀà¿â×öÁË´óÁ¿µÄÀ©Õ¹£¬ÆäÖÐÏ̳߳ؾÍÊÇJava5µÄÐÂÌØÕ÷Ö®Ò»£¬³ýÁËÏ̳߳ØÖ®Í⣬»¹Óкܶà¶àÏß³ÌÏà¹ØµÄÄÚÈÝ£¬Îª¶àÏ̵߳ıà³Ì´øÀ´Á˼«´ó±ãÀû¡£ÎªÁ˱àд¸ßЧÎȶ¨¿É¿¿µÄ¶àÏ̳߳ÌÐò£¬Ï̲߳¿·ÖµÄÐÂÔöÄÚÈÝÏÔµÃÓÈΪÖØÒª¡£
ÓйØJava5Ïß³ÌÐÂÌØÕ÷µÄÄÚÈÝÈ«²¿ÔÚjava.util.concurrentÏÂÃ棬ÀïÃæ°üº¬ÊýÄ¿ÖÚ¶à ......
Ò»¸öÓÅÐãµÄjava±à³Ì³ÌÐòÔ±±ØÐëÁ˽âGCµÄ¹¤×÷ÔÀí¡¢ÈçºÎÓÅ»¯GCµÄÐÔÄÜ¡¢ÈçºÎÓëGC½øÐÐÓÐÏ޵Ľ»»¥£¬ÒòΪÓÐһЩӦÓóÌÐò¶ÔÐÔÄÜÒªÇó½Ï¸ß£¬ÀýÈçǶÈëʽϵͳ¡¢ÊµÊ±ÏµÍ³µÈ£¬Ö»ÓÐÈ«ÃæÌáÉýÄÚ´æµÄ¹ÜÀíЧÂÊ £¬²ÅÄÜÌá¸ßÕû¸öÓ¦ÓóÌÐòµÄÐÔÄÜ¡£±¾ÆªÎÄÕÂÊ×Ïȼòµ¥½éÉÜGCµÄ¹¤×÷ÔÀíÖ®ºó£¬È»ºóÔÙ¶ÔGCµÄ¼¸¸ö¹Ø¼üÎÊÌâ½øÐÐÉîÈë̽ÌÖ£¬×îºóÌá³öһЩjava± ......
1 JAVAµÄ·´Éä,Æäʵ¾ÍÊÇͨ¹ýÒ»¸öʵÀý»¯µÄ¶ÔÏó·´¹ýÀ´È¥ÕÒµ½Ò»¸öÀàµÄÍêÕûÐÅÏ¢,±ÈÈç¶ÔÓÚÈçϵÄÐÎʽ:
X x=new X();
x.getClass().getName();
ÕâÀï¾Í»áÊä³öÕâ¸öÀàËùÔÚµÄÍêÕûÐÅÏ¢,¼´"°üÃû.ÀàÃû";
×î³£ÓõÄÈýÖÖʵÀý»¯CLASSÀà¶ÔÏó
Class<?> c1 = null ; // Ö¸¶¨·ºÐÍ
C ......