Java»Øµ÷¹¦ÄÜʹÓÃ
JavaµÄ»Øµ÷·½·¨²»ÏñcÄÇÑù¿ÉÒÔÖ±½Ó´«µÝÒ»¸ö·½·¨£¬java´«µÝµÄÊÇÒýÓã¬ËùÒÔjava¶Ô·½·¨»Øµ÷µÄ½â¾ö°ì·¨ÊÇÖ±½Ó´«µÝÒ»¸ö½Ó¿Ú£¬¶Ô½Ó¿Ú½øÐÐʵÏÖ¡£ÏÂÃæÊÇÒ»¸öÀý×Ó
Ê×Ïȶ¨ÒåÒ»¸ö½Ó¿ÚCar£¬ÓÐÒ»¸örunµÄ·½·¨ÉùÃ÷
Java´úÂë
package ocm.callback;
public interface Car {
public void run();
}
package ocm.callback;
public interface Car {
public void run();
}
¶¨ÒåÒ»¸öEmployeeÀ࣬¹ÍÔ±¿ª³µÈ¥Éϰ࣬ÓиöshangBan(Car car)·½·¨
Java´úÂë
package ocm.callback;
public class Employee {
public void shangBan(Car car){
System.out.println("********run() start***********");
car.run();
System.out.println("********run() end***********");
System.out.println("µ½ÁË!");
}
public void otherMethod(){
System.out.println("ÆäËü·½·¨");
}
}
package ocm.callback;
public class Employee {
public void shangBan(Car car){
System.out.println("********run() start***********");
car.run();
System.out.println("********run() end***********");
System.out.println("µ½ÁË!");
}
public void otherMethod(){
System.out.println("ÆäËü·½·¨");
}
}
¶¨Òå¿Í»§¶ËClient
Java´úÂë
/**
* »Øµ÷·½·¨Ö÷ÒªÊDZ»µ÷Õߣ¨·½·¨£©µ÷Óõ÷ÓÃÕߣ¨·½·¨£©£¬ÒÔ»ñÈ¡µ÷ÓÃÕßµÄһЩÐÅÏ¢£¬»ò´«µÝÐÅÏ¢ºÍ״̬µÈ
*/
class Client{
private int speed;
 
Ïà¹ØÎĵµ£º
java¼¯ºÏ¿ò¼Üͼ¼°½éÉÜ
¼ò»¯Í¼£º
Javaƽ̨ÌṩÁËÒ»¸öȫеļ¯ºÏ¿ò¼Ü¡£“¼¯ºÏ¿ò¼Ü”Ö÷ÒªÓÉÒ»×éÓÃÀ´²Ù×÷¶ÔÏóµÄ½Ó¿Ú×é³É¡£²»Í¬½Ó¿ÚÃèÊöÒ»×鲻ͬÊý¾ÝÀàÐÍ¡£
Java 2¼¯ºÏ¿ò¼Üͼ
¼¯ºÏ½Ó¿Ú£º6¸ö½Ó¿Ú£¨¶ÌÐéÏß±íʾ£©£¬±íʾ²»Í¬¼¯ºÏÀàÐÍ£¬ÊǼ¯ºÏ¿ò¼ÜµÄ»ù´¡¡£
³éÏóÀࣺ5¸ö³éÏóÀࣨ³¤ÐéÏß±íʾ£©£¬¶Ô¼¯ºÏ½Ó¿ÚµÄ²¿·ÖʵÏÖ¡£ ......
Java 7ÒѾÍê³ÉµÄÆß´óй¦ÄÜÔ¤ÀÀzz
2009-12-12 09:15
×î½üµÄDevoxx´ó»áÉÏ£¬Java 7½«°üº¬±Õ°üµÄÏûÏ¢ÁîºÜ¶àÈ˸е½Õñ·Ü——Õ⽫×öΪһ¸ö¶ÀÁ¢µÄJSR±»ÊµÏÖ¡£ÔÚÖÚ¶àJava 7еÄÓïÑÔÌØÐÔÖУ¬ÓÐһЩÏÖÔÚÒѾÍê³ÉÁË¡£Devoxx´ó»áµÄһλ²Î»áÕßÔÚ²©¿ÍÖб¨¸æÁËÏÂÃæÕâЩJava 7ÒѾÍê³ÉµÄ7´óй¦ÄÜ£º
1£©¶Ô¼¯ºÏÀàµÄÓïÑÔÖ§³Ö£»
......
JAVAºìºÚÊ÷
¸ÅÄÿ¸ö½Úµã¶¼´øÓÐÑÕÉ«ÊôÐԵĶþ²æ²éÕÒÊ÷£¬ÑÕÉ«»òºìÉ«»òºÚÉ«;
ÌØÐÔ£º
ÐÔÖÊ1. ½ÚµãÊǺìÉ«»òºÚÉ«¡£
¡¡¡¡ÐÔÖÊ2. ¸ùÊǺÚÉ«¡£
¡¡¡¡ÐÔÖÊ3. ÿ¸öºìÉ«½ÚµãµÄÁ½¸ö×ӽڵ㶼ÊǺÚÉ«¡£(´Óÿ¸öÒ¶×Óµ½¸ùµÄËùÓз¾¶Éϲ»ÄÜÓÐÁ½¸öÁ¬ÐøµÄºìÉ«½Úµã)
¡¡¡¡ÐÔÖÊ4. ´ÓÈÎÒ»½Úµãµ½Æäÿ¸öÒ¶×ÓµÄËùÓз¾¶¶¼°üº¬ÏàͬÊýÄ¿µÄºÚÉ«½Úµã¡£
......
¶àÏ̵߳Äͬ²½ÒÀ¿¿µÄÊǶÔÏóËø»úÖÆ£¬synchronized¹Ø¼ü×ֵı³ºó¾ÍÊÇÀûÓÃÁË·âËøÀ´ÊµÏÖ¶Ô¹²Ïí×ÊÔ´µÄ»¥³â·ÃÎÊ¡£
ÏÂÃæÒÔÒ»¸ö¼òµ¥µÄʵÀýÀ´½øÐжԱȷÖÎö¡£ÊµÀýÒªÍê³ÉµÄ¹¤×÷·Ç³£¼òµ¥£¬¾ÍÊÇ´´½¨10¸öỊ̈߳¬Ã¿¸öÏ̶߳¼´òÓ¡´Ó0µ½99Õâ100¸öÊý×Ö£¬ÎÒÃÇÏ£ÍûÏß³ÌÖ®¼ä²»»á³öÏÖ½»²æÂÒÐò´òÓ¡£¬¶øÊÇ˳ÐòµØ´òÓ¡¡£
ÏÈÀ´¿´µÚÒ»¶ ......
ϱßÊÇ×Ô¼º¶ÔÀàµÄһЩʹÓÃÈÏʶ£¬Èç¹ûÓв»¶ÔµÄ£¬¾´Çë´ïÈËÖ¸Õý¡£
ÈκÎÀàµÄʹÓö¼¾Àú£ºÀà¼ÓÔغÍÀà³õʼ»¯µÄ½×¶Î¡£
Àà³õʼ»¯:
*ÆÕͨ³ÉÔ±ÊôÐÔ£º
1.ϵͳĬÈϳõʼ»¯£¬»ù±¾ÀàÐÍĬÈÏΪ0»òfalse£¬ÒýÓÃÀàÐÍĬÈÏΪnull¡£
2.ÉùÃ÷ʱÏÔʾ³õʼ»¯»òÆÕͨ³õʼ»¯¿é(×¢Ò⣺ÆÕͨ³õʼ»¯Ö»ÓÐÔÚnew¹¹Ô캯Êý´´½¨ÊµÀýʱ£¬²Å»á±»×Ô¶¯µ÷ ......