Ïê½âJava»Øµ÷»úÖÆ (Callback) ½²½â+ʵÀý
JavaÖеĻص÷£¨callback£©ÊǺÜÖØÒªµÄÒ»¸ö¸ÅÄspringÕûºÏhibernate´óÁ¿Ê¹ÓÃÁËÕâÖÖ¼¼Êõ¡£
¾¿¾¹ÔõÑù²ÅÊǻص÷ÄØ£¿
ÕâÊÇÍøÉÏ×î¶à¼ûµ½µÄ˵Ã÷£º
1.class A,class B
2.class AʵÏÖ½Ó¿Úcallback
3.class BÓµÓÐÒ»¸ö²ÎÊýΪcallback½Ó¿ÚÀàÐ͵ĺ¯Êý
4.class AÔËÐÐʱµ÷ÓÃclass BÖеĺ¯Êý,ÒÔ×ÔÉí´«Èë²ÎÊý
5.class BÒÑÈ¡µÃA£¬¾Í¿ÉÒÔËæʱ»Øµ÷AËùʵÏÖµÄcallback½Ó¿ÚÖеķ½·¨
ÏÂÃæÎÒ¾ÙÒ»¸öÀý×Ó£º
ÖйúµçÐÅ(ChinaTelecom)ÊÇÒƶ¯ÔËÓªÉÌÖ®Ò»£¬Ïë±Ø½üÁ½ÄêÂúÌì·ÉµÄ“ÌìÒí3G”´ó¼Ò¶¼ÖªµÀ°É¡£¿ÕÖÐÍø£¨KongNet£©ÊÇÄǸö×ÜÊǺ°“ÓÃÊÖ»ú¿´NBA”µÄ·þÎñÌṩÉÌ£¨ServiceProvider£¬¼ò³Æ“SP”£©¡£
Òƶ¯ÔËÓªÉ̺ÍSPºÏ×÷²ÅÄÜΪÎÒÃǹã´óÒƶ¯Óû§Ìṩ¸÷ÖÖ·þÎñ¡£±ÈÈçÒôÀÖ£¬²ÊÁ壬ÊÖ»ú¿´NBAµÈµÈ¡£
ÕâÀïÓÐÒ»¸ö½Ó¿ÚServiceProvider£¬Ò²¾ÍÊÇCallback½Ó¿Ú£»
/**
* ÓëÖйúµçÐźÏ×÷µÄspʵÏִ˽ӿڼ´¿É
* Õâ¸ö¾ÍÊÇCallback½Ó¿Ú
* @author wanghe
*
*/
public interface ServiceProvider {
/**
* sp¿ÉÒÔ×Ô¶¨ÒåÌáʾ
*/
public void customHint();
}
Ò»¸öChinaTelecomÀ࣬¼´class B£»
/**
* ÖйúµçÐÅ
* @author wanghe
*
*/
public class ChinaTelecom {
private ServiceProvider sp;//callback½Ó¿Ú×÷ΪÊôÐÔ
public void setSp(ServiceProvider sp) {
this.sp = sp;
}
/**
* ³õʼ»¯
*/
public void init(){
System.out.println("Welcome, This is ChinaTelecom! ");
sp.customHint();//sp×Ô¶¨ÒåµÄ²Ù×÷
}
}
Ò»¸öKongNetÀ࣬¼´ class A
/**
* ·þÎñÌṩÉÌ(SP)--¿ÕÖÐÍø
* @author wanghe
*
*/
Ïà¹ØÎĵµ£º
/**
* ÓйØÈÕÆÚ¹¤¾ßÀà(extends TimeUtil)
*
* TimeUtilÖ÷Òª¹¦ÄÜÓУº
* 1.¸÷ÖÖÈÕÆÚÀàÐÍ£¨×Ö·û£¬util.Date£¬sql.Date£¬CalendarµÈ£©×ª»»
* 2.»ñÈ¡Ö¸¶¨ÈÕÆÚµÄÄê·Ý£¬Ô·ݣ¬ÈÕ·Ý£¬Ð¡Ê±£¬·Ö£¬Ã룬ºÁÃë
* 3.»ñÈ¡µ±Ç°/ϵͳÈÕÆÚ(Ö¸¶¨ÈÕÆÚ¸ñʽ)
* 4.»ñÈ¡×Ö·ûÈÕÆÚÒ»¸öÔµÄÌìÊý
* 5.»ñÈ¡Ö¸¶¨Ô·ݵĵÚÒ»Ìì,×îºóÒ»Ìì
*
* Date ......
javaÈëÃÅ
Ò»¡¢javaÊÇʲô
javaÊÇÒ»ÖÖ¼ÆËã»ú±à³ÌÓïÑÔ£¬Èí¼þ¿ª·¢Æ½Ì¨£¬Èí¼þÔËÐÐƽ̨£¬»¹ÊÇÒ»ÖÖÈí¼þ²¿Êð»·¾³¡£
¶þ¡¢javaÓÐʲô
java¼¼ÊõÓÐÈý¸ö·ÖÖ§£ºJava SE¡¢Java EEºÍJava ME¡£
Èý¡¢javaÄܸÉʲô
Ö÷ÒªÓÐÈý¸ö·½Ã棺×ÀÃæÓ¦ÓóÌÐòµÄ¿ª·¢¡¢ÆóÒµ¼¶µÄÓ¦ÓúÍǶÈëʽÉ豸¡£
ËÄ¡¢javaµÄÌصã
javaÊÇÒ»ÖÖ¼òµ¥µÄ¡¢ÃæÏò¶ÔÏóµÄ¡¢·Ö² ......
×î½üÏîÄ¿ÖÐÓÐÐèÒªÓõ½¹É¼Û£¬ÓÚÊÇÔÚÍøÉÏÕÒÁËÒ»·¬£¬Ã»ÓÐÒ»¸öÖ±½Ó¾ÍÄÜÓõġ£×Ô¼ºÃþË÷ÁËһϣ¬ÖÕÓڸ㶨һ¸ö¹Ë´ó¼Ò²Î¿¼¡£
package test;
import java.util.Arrays;
import javax.xml.namespace.QName;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
/**
*
* ¹¦ÄܸÅÊö£º<br>
* ......
package com.test.util;
import java.sql.*;
public class ConnectDB {
private Connection conn=null;
private PreparedStatement pt=null;
private ResultSet rs=null;
private String uname="sa";
private String upwd="sa";
private String url="jdbc:microsoft:sqlserv ......
ºËÐÄÌáʾ£º±¾ÎÄÃèÊöÁËÔÚJ2meÖпª·¢Ö÷ҪʹÓõÄÍøÂçÁ¬½Ó·½·¨£¬·Ö±ðÏêϸ½éÉÜÁËʹÓÃhttpºÍsocketÁ½ÖÖ·½·¨¡£ HttpConnection Ê×ÏÈÎÒÃÇÏÈÀ´¿´Ò»¸ö¼òµ¥µÄÀý×Ó°É£º Ö÷ÒªÓõ½µÄjava°ü£º javax.microedition.io.*; public String requestGET(String URLString,String URL) throws
±¾ÎÄÃèÊöÁËÔÚJ2meÖпª·¢Ö÷ҪʹÓõÄÍøÂçÁ¬½Ó·½·¨£¬ ......