Java»ñµÃÖ¸¶¨ClassLoaderËù¼ÓÔØµÄÀàÁбí
Ò»Ö±ÏëʵÏÖÏñDriverManagerÄÇÑùµÄgetConnection·½·¨£¬Í¨¹ý´Ë·½·¨¾Í¿ÉÒÔ»ñµÃÁ¬½Ó£¬¶øÇÒ»¹²»ÓÃÖ¸¶¨Driver£¬µ«Ç°ÌáÊÇDriverÒѾͨ¹ýClass.forName()»ònew Driver()½øÐÐÁ˼ÓÔØ¡£½ñÌìÖÕÓÚµÃÒÔʵÏÖ¡£
package quiz;
import java.lang.reflect.Field;
public class ClassLoaderDriver {
/**
* @param args
* @throws NoSuchFieldException
* @throws SecurityException
* @throws IllegalAccessException
* @throws IllegalArgumentException
* @throws ClassNotFoundException
*/
public static void main(String[] args) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, ClassNotFoundException {
Class.forName("com.mysql.jdbc.Driver");
Field field = ClassLoader.class.getDeclaredField("classes");
field.setAccessible(true);//ÉèÖøóÉÔ±±äÁ¿Îª¿É·ÃÎÊ
System.out.println(field.get(ClassLoader.getSystemClassLoader()));
}
}
ÕâÑùÒ»À´£¬ÎÒÃǾͿÉÒÔʵÏÖºÍDriverManagerÀàËÆµÄ¹¦ÄÜÁË¡£
Ïà¹ØÎĵµ£º
Ê×ÏȽéÉÜһϻ·¾³±äÁ¿µÄÉèÖ÷½·¨£º
£¨ÕâÀïÒÔjdk1.6À´°²×°£¬ÆäËû°æ±¾Ò»Ñù£©
ÔÚ°Ñjdk°²×°µ½¼ÆËã»úÖÐÖ®ºó£¬ÎÒÃÇÀ´½øÐÐÉèÖÃʹjava»·¾³Äܹ»Ê¹Óá£
Ê×ÏÈÓÒ¼üµãÎҵĵçÄÔ¡£´ò¿ªÊôÐÔ¡£È»ºóÑ¡Ôñ“¸ß¼¶”ÀïÃæµÄ“»·¾³±äÁ¿”£¬ÔÚеĴò¿ª½çÃæÖеÄϵͳ±äÁ¿Ðè ......
package com.test;
import java.text.DateFormat;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class TimeTest {
//ÓÃÀ´ ......
1 ¡¢ÃæÏò¶ÔÏóµÄÌØÕ÷ÓÐÄÄЩ·½Ãæ
1.³éÏó£º
³éÏó¾ÍÊǺöÂÔÒ»¸öÖ÷ÌâÖÐÓ뵱ǰĿ±êÎ޹صÄÄÇЩ·½Ã棬ÒÔ±ã¸ü³ä·ÖµØ×¢ÒâÓ뵱ǰĿ±êÓйصķ½Ãæ¡£³éÏó²¢²»´òËãÁ˽âÈ«²¿ÎÊÌ⣬¶øÖ»ÊÇÑ¡ÔñÆäÖеÄÒ»²¿·Ö£¬ÔÝʱ²»Óò¿·Öϸ½Ú¡£³éÏó°üÀ¨Á½¸ö·½Ã棬һÊǹý³Ì³éÏ󣬶þÊÇÊý¾Ý³éÏó¡£
2.¼Ì³Ð£º
¼Ì³ÐÊÇÒ»ÖÖÁª½áÀàµÄ²ã´ÎÄ£ÐÍ£¬²¢ÇÒÔÊÐíºÍ¹ÄÀøÀൠ......
ÔÚJavaÖÐÓÐÁ½ÖÖ²»Í¬µÄ¶Ô±äÁ¿¸³Öµ·½Ê½£¬Ò»ÖÖÊÇÖ±½Ó½«Ò»¸öÖµ¸³¸ø±äÁ¿¡£ÀýÈ磺
int a = 1;
String s = "abc";
Integer in = 125;
ÁíÍâÒ»ÖÖÊÇ´´½¨Ò»¸ö¶ÔÏ󣬲¢½«Æä¸³¸øÒ»¸ö±äÁ¿¡£ÀýÈ磺
String s = new String("abc")
Integer in = new Integer(125);
Á½ÖÖ·½Ê½µÄ²»Í¬Ö®´¦ÔÚÓÚ£º
µÚÒ»ÖÖ·½Ê½±äÁ¿µÄÖµ´æ´¢ÔÚ¶ÑÕ»ÖУ¬µ±ÏÂÒ» ......