Java·´Éä»úÖÆ
·´Éä»úÖÆ:ËùνµÄ·´Éä»úÖƾÍÊÇjava
ÓïÑÔÔÚÔËÐÐʱӵ
ÓÐÒ»Ïî×Ô¹ÛµÄÄÜÁ¦¡£Í¨¹ýÕâÖÖÄÜÁ¦¿ÉÒÔ³¹µ×µÄÁ˽â×ÔÉíµÄÇé¿öΪÏÂÒ»²½µÄ¶¯×÷×ö×¼±¸¡£ÏÂÃæ¾ßÌå½éÉÜÒ»ÏÂjava
µÄ·´Éä»úÖÆ¡£ÕâÀïÄ㽫µß¸²ÔÀ´¶ÔjavaµÄÀí½â¡£
JavaµÄ·´Éä»úÖƵÄʵÏÖÒª½èÖúÓÚ4¸öÀࣺclass£¬Constructor£¬Field£¬Method£»ÆäÖÐclass´ú±íµÄʱÀà¶Ô
Ïó£¬Constructor£ÀàµÄ¹¹ÔìÆ÷¶ÔÏó£¬Field£ÀàµÄÊôÐÔ¶ÔÏó£¬Method£ÀàµÄ·½·¨¶ÔÏó¡£Í¨¹ýÕâËĸö¶ÔÏóÎÒÃÇ¿ÉÒÔ´ÖÂԵĿ´µ½Ò»¸öÀàµÄ¸÷¸ö×é
³É²¿·Ö¡£
Class£º³ÌÐòÔËÐÐʱ£¬javaÔËÐÐʱϵͳ»á¶ÔËùÓеĶÔÏó½øÐÐÔËÐÐʱÀàÐ͵Ĵ¦Àí¡£ÕâÏîÐÅÏ¢¼Ç¼ÁËÿ¸ö¶ÔÏóËùÊôµÄÀ࣬ÐéÄâ»úͨ³£Ê¹ÓÃÔËÐÐʱÀàÐÍÐÅÏ¢
Ñ¡ÔñÕý
È·µÄ·½·¨À´Ö´ÐУ¨Õª×Ô£º°×ƤÊ飩¡£µ«ÊÇÕâЩÐÅÏ¢ÎÒÃÇÔõôµÃµ½°¡£¬¾ÍÒª½èÖúÓÚclassÀà¶ÔÏóÁË°¡¡£ÔÚObjectÀàÖж¨ÒåÁËgetClass()·½·¨¡£ÎÒ
ÃÇ¿ÉÒÔͨ¹ýÕâ¸ö·½·¨»ñµÃÖ¸¶¨¶ÔÏóµÄÀà¶ÔÏó¡£È»ºóÎÒÃÇͨ¹ý·ÖÎöÕâ¸ö¶ÔÏó¾Í¿ÉÒԵõ½ÎÒÃÇÒªµÄÐÅÏ¢ÁË¡£
±ÈÈ磺ArrayList arrayList;
Class clazz = arrayList.getClass();
È»ºóÎÒÀ´´¦ÀíÕâ¸ö¶ÔÏóclazz¡£
µ±È»ÁËClassÀà¾ßÓкܶàµÄ·½·¨£¬ÕâÀïÖص㽫ºÍConstructor£¬Field£¬MethodÀàÓйØϵµÄ·½·¨¡£
Reflection ÊÇ Java ³ÌÐò¿ª·¢ÓïÑÔµÄÌØÕ÷Ö®Ò»£¬ËüÔÊÐíÔËÐÐÖÐµÄ Java
³ÌÐò¶Ô×ÔÉí½øÐмì²é£¬»òÕß˵“×ÔÉ󔣬²¢ÄÜÖ±½Ó²Ù×÷³ÌÐòµÄÄÚ²¿ÊôÐÔ¡£Java
µÄÕâÒ»ÄÜÁ¦ÔÚʵ¼ÊÓ¦ÓÃÖÐÒ²ÐíÓõò»ÊǺܶ࣬µ«ÊǸöÈËÈÏΪҪÏë¶ÔjavaÓиö¸ü¼ÓÉîÈëµÄÁ˽⻹ÊÇÓ¦¸ÃÕÆÎյġ£
1£®¼ì²âÀࣺ
reflectionµÄ¹¤×÷»úÖÆ
¿¼ÂÇÏÂÃæÕâ¸ö¼òµ¥µÄÀý×Ó£¬ÈÃÎÒÃÇ¿´¿´ reflection ÊÇÈçºÎ¹¤×÷µÄ¡£
import java.lang.reflect.*;
public class DumpMethods {
public static void main(String args[]) {
try {
Class c = Class.forName(args[0]);
Method m[] = c.getDeclaredMethods();
for (int i = 0; i < m.length; i++)
System.out.println(m[i].toString());
} catch (Throwable e) {
System.err.println(e);
}
}
}
°´ÈçÏÂÓï¾äÖ´ÐУº
java DumpMethods java.util.ArrayList
Õâ¸ö³ÌÐòʹÓà Class.forName ÔØÈëÖ¸¶¨µÄÀ࣬Ȼºóµ÷Óà getDeclaredMethods
À´»ñÈ¡Õâ¸öÀàÖж¨ÒåÁ˵ķ½·¨ÁÐ±í¡£java.lang.reflect.Methods ÊÇÓÃÀ´ÃèÊöij¸öÀàÖе¥¸ö·½·¨µÄÒ»¸öÀà¡£
JavaÀà·´ÉäÖеÄÖ÷Òª·½·¨
¶ÔÓÚÒÔÏÂÈýÀà×é¼þÖеÄÈκÎÒ»ÀàÀ´Ëµ -- ¹¹Ô캯Êý¡¢×ֶκͷ½·¨ -- java.lang.Class
ÌṩËÄÖÖ¶ÀÁ¢µÄ·´Éäµ÷Óã¬ÒÔ²»Í¬µÄ·½Ê½À´»ñµÃÐÅÏ¢¡£µ÷Óö¼×ñÑÒ»ÖÖ
Ïà¹ØÎĵµ£º
ÔÚÁ˽âJavaµÄͬ²½ÃØÃÜ֮ǰ£¬ÏÈÀ´¿´¿´JMM(Java Memory Model)¡£
Java±»Éè¼ÆΪ¿çƽ̨µÄÓïÑÔ£¬ÔÚÄÚ´æ¹ÜÀíÉÏ£¬ÏÔȻҲҪÓÐÒ»¸öͳһµÄÄ£ÐÍ¡£¶øÇÒJavaÓïÑÔ×î´óµÄÌصã¾ÍÊǷϳýÁËÖ¸Õ룬°Ñ³ÌÐòÔ±´ÓÍ´¿àÖнâÍѳöÀ´£¬²»ÓÃÔÙ¿¼ÂÇÄÚ´æʹÓú͹ÜÀí·½ÃæµÄÎÊÌâ¡£
¿ÉϧÊÀÊÂ×ܲ»¾¡ÈçÈËÒ⣬ËäÈ»JMMÉè¼ÆÉÏ·½±ãÁ˳ÌÐòÔ±£¬µ«ÊÇËüÔö¼ÓÁËÐéÄâ»úµÄ¸ ......
·½·¨Ò»£º
SimpleDateFormat formatter =
new
SimpleDateFormat(
"yyyyMMdd"
);
Date currentTime =
new
java.util.Date();
//
µÃµ½µ±Ç°ÏµÍ³Ê±¼ä
long
now = curr ......
private void postMethod(String url) throws IOException
{
url = "http://www.newsmth.net/bbslogin2.php";
PostMethod postMethod = new PostMethod(url);
// ÌîÈë¸÷¸ö±íµ¥ÓòµÄÖµ
NameValuePair[] data = { new NameValuePair("id ......
¹ØÓÚJavaÕ»Óë¶ÑµÄ˼¿¼
1. Õ»(stack)Óë¶Ñ(heap)¶¼ÊÇJavaÓÃÀ´ÔÚRamÖдæ·ÅÊý¾ÝµÄµØ·½¡£ÓëC++²»Í¬£¬Java×Ô¶¯¹ÜÀíÕ»ºÍ¶Ñ£¬³ÌÐòÔ±²»ÄÜÖ±½ÓµØÉèÖÃÕ»»ò¶Ñ¡£
2. Õ»µÄÓÅÊÆÊÇ£¬´æÈ¡ËٶȱȶÑÒª¿ì£¬½ö´ÎÓÚÖ±½ÓλÓÚCPUÖеļĴæÆ÷¡£µ«È±µãÊÇ£¬´æÔÚÕ»ÖеÄÊý¾Ý´óСÓëÉú´æÆÚ±ØÐëÊÇÈ·¶¨µÄ£¬È±·¦Áé»îÐÔ¡£ÁíÍ⣬ջÊý¾Ý¿ÉÒÔ¹²Ïí£¬Ïê¼ûµÚ3µã¡£¶ ......
JavaµÚÈý·½library ecosystemÊÇÒ»¸öºÜ¹ãÀ«µÄ·¶³ë¡£²»¾ÃÇ°ÓÐÈË׫ÎÄ£ºÃ¿¸öÏîÄ¿ÖУ¬Äã±ØÐëÖªµÀµÄ11¸öJavaµÚÈý·½Àà¿â¡£
µ¥Ôª²âÊÔ
1.DBUnit
DBunitÊÇÒ»¸ö»ùÓÚjunitÀ©Õ¹µÄÊý¾Ý¿â²âÊÔ¿ò¼Ü¡£ËüÌṩÁË´óÁ¿µÄÀà¶ÔÓëÊý¾Ý¿âÏà¹ØµÄ²Ù×÷½øÐÐÁ˳éÏóºÍ·â×°¡£
2.MOckito
MockitoÊÇÒ»¸öÕë¶ÔJavaµÄmocking¿ò¼Ü¡£Äã¿ÉÒÔʹÓüò½àµÄAPI±àд³ö ......