JavaÖг£ÓÃÉè¼Æģʽ×ܽá
ÔÚJavaÖÐÓÐ23ÖÐÉè¼Æģʽ£¬ÏÂÃæÖ»¶Ô²¿·Ö³£ÓõÄÉè¼Æģʽ½éÉÜһϣº
1.µ¥Àýģʽ£¨ÓеÄÊéÉÏ˵½Ðµ¥Ì¬Ä£Ê½Æäʵ¶¼Ò»Ñù£©
¸ÃģʽÖ÷ҪĿµÄÊÇʹÄÚ´æÖб£³Ö1¸ö¶ÔÏ󡣿´ÏÂÃæµÄÀý×Ó£º
package org.sp.singleton;
//·½·¨Ò»
public class Singleton {
//½«×ÔÉíµÄʵÀý¶ÔÏóÉèÖÃΪһ¸öÊôÐÔ,²¢¼ÓÉÏStaticºÍfinalÐÞÊηû
private static final Singleton instance = new Singleton();
//½«¹¹Ôì·½·¨ÉèÖóÉ˽ÓÐÐÎʽ
private Singleton() {
}
//ͨ¹ýÒ»¸ö¾²Ì¬·½·¨ÏòÍâ½çÌṩÕâ¸öÀàµÄʵÀý
public static Singleton getInstance() {
return instance;
}
}
//·½·¨¶þ
class Singleton2 {
private static Singleton2 instance2 = null;
public static synchronized Singleton2 getInstance() {
if (instance2 == null)
instance2 = new Singleton2();
return instance2;
}
}
×¢£ºÕâ¶þ¸ö·½·¨ÊµÏÖÁËÒ»ÑùµÄ¹¦ÄÜ£¬µ«¸öÈËÍƼö²ÉÓõÚÒ»ÖÖ·½·¨¡£
2.¹¤³§Ä£Ê½
¸ÃģʽÖ÷Òª¹¦ÄÜÊÇͳһÌṩʵÀý¶ÔÏóµÄÒýÓ᣿´ÏÂÃæµÄÀý×Ó£º
public class Factory{
public ClassesDao getClassesDao(){
ClassesDao cd = new ClassesDaoImpl();
return cd;
}
}
interface ClassesDao{
public String getClassesName();
}
class ClassesDaoImpl implements ClassesDao {
public String getClassesName(){
System.out.println("A°à");
}
}
class test
{
public static void main(String[] args){
Factory f = new Factory();
f.getClassesDao().getClassesName();
}
}
Õâ¸öÊÇ×î¼òµ¥µÄÀý×ÓÁË£¬¾ÍÊÇͨ¹ý¹¤³§·½·¨Í¨¹ý½Ó¿Ú»ñÈ¡¶ÔÏóµÄÒýÓÃ
3.½¨Ôìģʽ
¸ÃģʽÆäʵ¾ÍÊÇ˵£¬Ò»¸ö¶ÔÏóµÄ×é³É¿ÉÄÜÓкܶàÆäËûµÄ¶ÔÏóÒ»Æð×é³ÉµÄ£¬±ÈÈç˵£¬Ò»¸ö¶ÔÏóµÄʵÏַdz£¸´ÔÓ£¬ÓкܶàµÄÊôÐÔ£¬¶øÕâЩÊôÐÔÓÖÊÇÆäËû¶ÔÏóµÄÒýÓ㬿ÉÄÜÕâЩ¶ÔÏóµÄÒýÓÃÓÖ°üÀ¨ºÜ¶àµÄ¶ÔÏóÒýÓ᣷â×°ÕâЩ¸´ÔÓÐÔ£¬¾Í¿ÉÒÔʹÓý¨Ôìģʽ¡£
¾ßÌå¿´¿´ÏÂÃæµÄÀý×Ó£º
4.ÃÅÃæģʽ
Õâ¸öģʽ¸öÈ˸оõÏñÊÇService²ãµÄÒ»¸ö·°æ¡£±ÈÈçDaoÎÒÃǶ¨ÒåÁ˺ܶà³Ö¾Ã»¯·½·¨£¬ÎÒÃÇͨ¹ýService²ã½«DaoµÄÔ×Ó·½·¨×é³ÉÒµÎñÂß¼£¬ÔÙͨ¹ý·½·¨ÏòÉϲãÌṩ·þÎñ¡£ÃÅÃæģʽµÀÀíÆäʵÊÇÒ»ÑùµÄ¡£
¾ßÌå¿´¿´Õâ¸öÀý×Ó£º
interface ClassesDao{
public String getClassesName();
}
class ClassesDaoImpl implements Classe
Ïà¹ØÎĵµ£º
java»Øµ÷»úÖÆ£º
Èí¼þÄ£¿éÖ®¼ä×ÜÊÇ´æÔÚ×ÅÒ»¶¨µÄ½Ó¿Ú£¬´Óµ÷Ó÷½Ê½ÉÏ£¬¿ÉÒÔ°ÑËûÃÇ·ÖΪÈýÀࣺͬ²½µ÷Óᢻص÷ºÍÒì²½µ÷Óá£
ͬ²½µ÷ÓÃÊÇÒ»ÖÖ×èÈûʽµ÷Ó㬵÷Óà ·½ÒªµÈ´ý¶Ô·½Ö´ÐÐÍê±Ï²Å·µ»Ø£¬ËüÊÇÒ»ÖÖµ¥Ïòµ÷Óã»
»Øµ÷ÊÇÒ»ÖÖË«Ïòµ÷ÓÃģʽ£¬Ò²¾ÍÊÇ˵£¬±»µ÷Ó÷½ÔÚ½Ó¿Ú±»µ÷ÓÃʱҲ»áµ÷ÓöԷ½µÄ½Ó¿Ú£»
Òì²½µ÷ÓÃÊÇÒ»ÖÖÀàËÆÏûÏ¢»òʼþµÄ» ......
Java EE ¸ÅÊö
Javaa EE:·Ö²¼Ê½ ÆóÒµ¼¶Ó¦Óù淶ºÍ±ê×¼
ÍÆģʽ£º²»ÓÃÇëÇó£¬Ç¿ÖÆÈÿͻ§½ÓÊÜ
Àģʽ£ºÈÿͻ§ÇëÇóºÍÏìÓ¦¡£
¼Ü¹¹£º
ÇáÁ¿¼¶£ºstruct2 /spring /hibernate
Modle1:jsp+JavaBean+DB
Model2(MVC):jsp+servlet+JavaBean+DB
ÖØÁ¿¼¶£ºJsp+servlet+EJB+DB
±íʾ²ã£ºÒµÎñ²ã£º³Ö¾Ã²ã£ºÊý¾Ý¿â£º
JNDI£º²éÕÒ·Ö²¼¶ÔÏóµ ......
String ¶ÔÏóÊDz»¿É¸Ä±äµÄ¡£Ã¿´ÎʹÓà System.String ÀàÖеķ½·¨Ö®Ò»Ê±£¬¶¼ÒªÔÚÄÚ´æÖд´½¨Ò»¸öеÄ×Ö·û´®¶ÔÏó£¬Õâ¾ÍÐèҪΪ¸ÃжÔÏó·ÖÅäеĿռ䡣ÔÚÐèÒª¶Ô×Ö·û´®Ö´ÐÐÖظ´Ð޸ĵÄÇé¿öÏ£¬Óë´´½¨Ð嵀 String ¶ÔÏóÏà¹ØµÄϵͳ¿ªÏú¿ÉÄÜ»á·Ç³£°º¹ó¡£Èç¹ûÒªÐÞ¸Ä×Ö·û´®¶ø²»´´½¨ÐµĶÔÏó£¬Ôò¿ÉÒÔʹÓà System.Text.StringBuilder Àà¡£ÀýÈ ......
ÄãµÄSQL Server 2000±ØÐë´òÉÏSP3µÄ²¹,È»ºó°²×°MicrosoftµÄJDBCÇý¶¯,½«ÒÔÏÂÈý¸öjar°ü¸´ÖƵ½WebContent\WEB-INF\lib
msbase.jar
mssqlserver.jar
msutil.jar
ÏÂÃæÊDzâÊÔ´úÂ룬ûÓб¨´íÊý¾Ý¿â¾ÍÄÜÕý³£Á¬½Ó
public class DbcTest {
/**
* @param args
*/
public static void main(String[] args) {
Str ......