Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

javaÏÂClass.forNameµÄ×÷ÓÃÊÇʲô£¬ÎªÊ²Ã´ÒªÊ¹ÓÃËü

Class.forName(xxx.xx.xx) ·µ»ØµÄÊÇÒ»¸öÀà
Ê×ÏÈÄãÒªÃ÷°×ÔÚjavaÀïÃæÈκÎclass¶¼Òª×°ÔØÔÚÐéÄâ»úÉϲÅÄÜÔËÐС£Õâ¾ä»°¾ÍÊÇ×°ÔØÀàÓõÄ(ºÍnew ²»Ò»Ñù£¬Òª·ÖÇå³þ)¡£
ÖÁÓÚʲôʱºòÓã¬Äã¿ÉÒÔ¿¼ÂÇÒ»ÏÂÕâ¸öÎÊÌ⣬¸øÄãÒ»¸ö×Ö·û´®±äÁ¿£¬Ëü´ú±íÒ»¸öÀàµÄ°üÃûºÍÀàÃû£¬ÄãÔõôʵÀý»¯Ëü£¿Ö»ÓÐÄãÌáµ½µÄÕâ¸ö·½·¨ÁË£¬²»¹ýÒªÔÙ¼ÓÒ»µã¡£
A a = (A)Class.forName("pacage.A").newInstance();
ÕâºÍÄã
A a = new A()£»
ÊÇÒ»ÑùµÄЧ¹û¡£
¹ØÓÚ²¹³äµÄÎÊÌâ
´ð°¸Êǿ϶¨µÄ£¬jvm»áÖ´Ðо²Ì¬´úÂë¶Î£¬ÄãÒª¼Çסһ¸ö¸ÅÄ¾²Ì¬´úÂëÊǺÍclass°ó¶¨µÄ£¬class×°Ôسɹ¦¾Í±íʾִÐÐÁËÄãµÄ¾²Ì¬´úÂëÁË¡£¶øÇÒÒÔºó²»»áÔÙ×ßÕâ¶Î¾²Ì¬´úÂëÁË¡£
Class.forName(xxx.xx.xx) ·µ»ØµÄÊÇÒ»¸öÀà
Class.forName(xxx.xx.xx);µÄ×÷ÓÃÊÇÒªÇóJVM²éÕÒ²¢¼ÓÔØÖ¸¶¨µÄÀ࣬Ҳ¾ÍÊÇ˵JVM»áÖ´ÐиÃÀàµÄ¾²Ì¬´úÂë¶Î
¶¯Ì¬¼ÓÔغʹ´½¨Class ¶ÔÏ󣬱ÈÈçÏë¸ù¾ÝÓû§ÊäÈëµÄ×Ö·û´®À´´´½¨¶ÔÏó
String str = Óû§ÊäÈëµÄ×Ö·û´®
Class t = Class.forName(str);
t.newInstance();
 ÔÚ³õʼ»¯Ò»¸öÀ࣬Éú³ÉÒ»¸öʵÀýµÄʱºò£¬newInstance()·½·¨ºÍnew¹Ø¼ü×Ö³ýÁËÒ»¸öÊÇ·½·¨£¬Ò»¸öÊǹؼü×ÖÍ⣬×îÖ÷ÒªÓÐʲôÇø±ð£¿ËüÃǵÄÇø±ðÔÚÓÚ´´½¨¶ÔÏóµÄ·½Ê½²»Ò»Ñù£¬Ç°ÕßÊÇʹÓÃÀà¼ÓÔØ»úÖÆ£¬ºóÕßÊÇ´´½¨Ò»¸öÐÂÀà¡£ÄÇôΪʲô»áÓÐÁ½ÖÖ´´½¨¶ÔÏó·½Ê½£¿ÕâÖ÷Òª¿¼Âǵ½Èí¼þµÄ¿ÉÉìËõ¡¢¿ÉÀ©Õ¹ºÍ¿ÉÖØÓõÈÈí¼þÉè¼Æ˼Ïë¡£
JavaÖй¤³§Ä£Ê½¾­³£Ê¹ÓÃnewInstance()·½·¨À´´´½¨¶ÔÏó£¬Òò´Ë´ÓΪʲôҪʹÓù¤³§Ä£Ê½ÉÏ¿ÉÒÔÕÒµ½¾ßÌå´ð°¸¡£ ÀýÈ磺
class c = Class.forName(“Example”);
factory = (ExampleInterface)c.newInstance();
ÆäÖÐExampleInterfaceÊÇExampleµÄ½Ó¿Ú£¬¿ÉÒÔд³ÉÈçÏÂÐÎʽ£º
String className = "Example";
class c = Class.forName(className);
factory = (ExampleInterface)c.newInstance();
½øÒ»²½¿ÉÒÔд³ÉÈçÏÂÐÎʽ£º
String className = readfromXMlConfig;//´Óxml ÅäÖÃÎļþÖлñµÃ×Ö·û´®
class c = Class.forName(className);
factory = (ExampleInterface)c.newInstance();
ÉÏÃæ´úÂëÒѾ­²»´æÔÚExampleµÄÀàÃû³Æ£¬ËüµÄÓŵãÊÇ£¬ÎÞÂÛExampleÀàÔõô±ä»¯£¬ÉÏÊö´úÂë²»±ä£¬ÉõÖÁ¿ÉÒÔ¸ü»»ExampleµÄÐÖµÜÀàExample2 , Example3 , Example4……£¬Ö»ÒªËûÃǼ̳ÐExampleInterface¾Í¿ÉÒÔ¡£
´ÓJVMµÄ½Ç¶È¿´£¬ÎÒÃÇʹÓùؼü×Önew´´½¨Ò»¸öÀàµÄʱºò£¬Õâ¸öÀà¿ÉÒÔûÓб»¼ÓÔØ¡£µ«ÊÇʹÓÃnewInstance()·½·¨µÄʱºò£¬¾Í±ØÐ


Ïà¹ØÎĵµ£º

java½â»ó±Ê¼Ç

½ñÌì³é¿ÕÏÂÁË¡¶java½â»ó¡·Õâ±¾Êé¿´ÁËһϣ¬È·Êµ²»´í£¬Ìá³öÁ˺ܶàÎÒÃÇƽʱ²»»á×¢ÒâµÄСÎÊÌâ¡£ÏëÏëÈç¹û²»×¢Òâ˵²»¶¨»áÒòΪһ¸öBUGÓôÃƸöÒ»Á½ÌìÒ²ÕÒ²»µ½¡£ÒÔÏÂÊÇ×ܽáµÄ±Ê¼Ç£¬±¸Íü~~
1.ÅжÏÆæÊý
i % 2 == 1 ÔÚi Ϊ¸ºÊýʱ½á¹ûΪ-1£¬ËùÒÔʹÓÃi % 2 != 0À´Åжϣ»µ±ÓÐÐÔÄÜÒªÇóʱʹÓà (i & 1) != 0¡£
*ÔÚʹÓÃ%ʱһ¶¨Òª¿¼Âǵ½² ......

javaÄÚ´æ·Ö²¼


ÔÚJAVAÖУ¬ÓÐÁù¸ö²»Í¬µÄµØ·½¿ÉÒÔ´æ´¢Êý¾Ý£º
1. ¼Ä´æÆ÷£¨register£©¡£ÕâÊÇ×î¿ìµÄ´æ´¢Çø£¬ÒòΪËüλÓÚ²»Í¬ÓÚÆäËû´æ´¢ÇøµÄµØ·½——´¦ÀíÆ÷ÄÚ²¿¡£µ«ÊǼĴæÆ÷µÄÊýÁ¿¼«ÆäÓÐÏÞ£¬ËùÒԼĴæÆ÷ÓɱàÒëÆ÷¸ù¾ÝÐèÇó½øÐзÖÅä¡£Äã²»ÄÜÖ±½Ó¿ØÖÆ £¬Ò²²»ÄÜÔÚ³ÌÐòÖиоõµ½¼Ä´æÆ÷´æÔÚµÄÈκμ£Ïó¡£
2. ¶ÑÕ»£¨stack£©¡£Î»ÓÚͨÓÃRAMÖУ¬µ ......

Çë´ó¼ÒÖ¸½Ì£¬ÓйØJavaÖÐmain·½·¨¼°²ÎÊýÎÊÌâ

½ñÌìûʸɡ££¬ÄÃJavaÖеÄmainº¯ÊýÀ´Ịֽ̀¬¡£¡£»¹ÇëÖîλָµã°¡£¬£¬
public static void main(String args [])
{
 .....
}
ÕâÊÇ´ó¼ÒÒ»°ãµÄд·¨°É£¬ÕâÀïÎÒÏëÌ̵ֽÄÖ÷ÒªÓÐÒÔϼ¸µã£º
1.ËüµÄ²ÎÊýÎÊÌ⣬ÄǸö²ÎÊýµ¹µ×ÓкÎÓÃÄØ£¬£¬ÕâÊǺÜÁîÈËÃÔ»óµÄ£¬ÕâÀï×Ô¼ºÐ´Á˸öÀý×ÓÊÔÁËһϣ¬µ«ÊdzöÏÖÁËÒì³££º
 class A
{ ......

JavaÐéÄâ»ú£¨JVM£©ÖеÄÄÚ´æÉèÖÃÏê½â

ÔÚһЩ¹æÄ£ÉÔ´óµÄÓ¦ÓÃÖУ¬JavaÐéÄâ»ú£¨JVM£©µÄÄÚ´æÉèÖÃÓÈΪÖØÒª£¬ÏëÔÚÏîÄ¿ÖÐÈ¡µÃºÃµÄЧÂÊ£¬GC£¨À¬»ø»ØÊÕ£©µÄÉèÖÃÊǵÚÒ»²½¡£
PermGen space£ºÈ«³ÆÊÇPermanent Generation space.¾ÍÊÇ˵ÊÇÓÀ¾Ã±£´æµÄÇøÓò,ÓÃÓÚ´æ·ÅClassºÍMetaÐÅÏ¢,ClassÔÚ±»LoadµÄʱºò±»·ÅÈë¸ÃÇøÓòHeap space£º´æ·ÅInstance¡£
GC(Garbage Collection)Ó¦¸Ã²»» ......

JavaÖеĻص÷·½·¨

      ÔÚJavaÖУ¬¾ÍÊÇÀàAµ÷ÓÃÀàBÖеÄij¸ö·½·¨b£¬È»ºóÀàBÓÖÔÚij¸öʱºò·´¹ýÀ´µ÷ÓÃÀàAÖеÄij¸ö·½·¨a£¬¶ÔÓÚAÀ´Ëµ£¬Õâ¸öa·½·¨±ã½Ð×ö»Øµ÷·½·¨,µ±È»£¬AÀàºÍBÀà¿ÉÒԺϲ¢ÎªÒ»¸ö¡£
pubilc interface CallBack{

public void callbackMethod();
}
public class A implements CallBa ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ