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

JavaÖÐnewºÍnewInstanceµÄÇø±ð

    ÔÚJavaÖУ¬Ê¹ÓÃnew¹Ø¼ü×ÖºÍClass.forName("a.class.Name").newInstance¶¼¿ÉÒÔ´´½¨¶ÔÏó£¬ËüÃÇÓÖÓÐʲôÇø±ðÄØ£¿
    1¡¢ÀàµÄ¼ÓÔØ·½Ê½²»Í¬¡£
    ÔÚÖ´ÐÐClass.forName("a.class.Name")ʱ£¬JVM»áÔÚclassapthÖÐÈ¥ÕÒ¶ÔÓ¦µÄÀಢ¼ÓÔØ£¬ÕâʱJVM»áÖ´ÐиÃÀàµÄ¾²Ì¬´úÂë¶Î¡£ÔÚʹÓÃnewInstance()·½·¨µÄʱºò£¬±ØÐë±£Ö¤Õâ¸öÀàÒѾ­¼ÓÔز¢ÇÒÒѾ­Á¬½ÓÁË£¬¶øÕâ¿ÉÒÔͨ¹ýClassµÄ¾²Ì¬·½·¨forName()À´Íê³ÉµÄ¡£
    ʹÓùؼü×Önew´´½¨Ò»¸öÀàµÄʱºò£¬Õâ¸öÀà¿ÉÒÔûÓб»¼ÓÔØ£¬Ò»°ãÒ²²»ÐèÒª¸ÃÀàÔÚclasspathÖÐÉ趨£¬µ«¿ÉÄÜÐèҪͨ¹ýclasslaoderÀ´¼ÓÔØ¡£
    2¡¢Ëùµ÷ÓõĹ¹Ôì·½·¨²»¾¡Ïàͬ¡£
    new¹Ø¼ü×ÖÄܵ÷ÓÃÈκι¹Ôì·½·¨¡£
    newInstance()Ö»Äܵ÷ÓÃÎ޲ι¹Ôì·½·¨¡£
    3¡¢Ö´ÐÐЧÂʲ»Í¬¡£
    new¹Ø¼ü×ÖÊÇÇ¿ÀàÐ͵ģ¬Ð§ÂÊÏà¶Ô½Ï¸ß¡£
    newInstance()ÊÇÈõÀàÐ͵ģ¬Ð§ÂÊÏà¶Ô½ÏµÍ¡£
    ¼ÈȻʹÓÃnewInstance()¹¹Ôì¶ÔÏóµÄµØ·½Í¨¹ýnew¹Ø¼ü×ÖÒ²¿ÉÒÔ´´½¨¶ÔÏó£¬ÎªÊ²Ã´ÓÖ»áʹÓÃnewInstance()À´´´½¨¶ÔÏóÄØ£¿
    ¼ÙÉ趨ÒåÁËÒ»¸ö½Ó¿ÚDoor£¬¿ªÊ¼µÄʱºòÊÇÓÃľÃŵģ¬¶¨ÒåΪһ¸öÀàWoodenDoor£¬ÔÚ³ÌÐòÀï¾ÍÒªÕâÑùд Door door = new WoodenDoor() ¡£¼ÙÉèºóÀ´Éú»îÌõ¼þÌá¸ß£¬»»Îª×Ô¶¯ÃÅÁË£¬¶¨ÒåÒ»¸öÀàAutoDoor£¬Õâʱ³ÌÐò¾ÍÒª¸ÄдΪ Door door = new AutoDoor() ¡£ËäȻֻÊǸĸö±êʶ·û£¬Èç¹ûÕâÑùµÄÓï¾äÌرð¶à£¬¸Ä¶¯»¹ÊÇͦ´óµÄ¡£ÓÚÊdzöÏÖÁ˹¤³§Ä£Ê½£¬ËùÓÐDoorµÄʵÀý¶¼ÓÉDoorFactoryÌṩ£¬Õâʱ»»Ò»ÖÖÃŵÄʱºò£¬Ö»ÐèÒª°Ñ¹¤³§µÄÉú²úģʽ¸Äһϣ¬»¹ÊÇÒª¸ÄÒ»µã´úÂë¡£
    ¶øÈç¹ûʹÓÃnewInstance()£¬Ôò¿ÉÒÔÔÚ²»¸Ä±ä´úÂëµÄÇé¿öÏ£¬»»ÎªÁíÍâÒ»ÖÖDoor¡£¾ßÌå·½·¨ÊÇ°ÑDoorµÄ¾ßÌåʵÏÖÀàµÄÀàÃû·Åµ½ÅäÖÃÎļþÖУ¬Í¨¹ýnewInstance()Éú³ÉʵÀý¡£ÕâÑù£¬¸Ä±äÁíÍâÒ»ÖÖDoorµÄʱºò£¬Ö»¸ÄÅäÖÃÎļþ¾Í¿ÉÒÔÁË¡£Ê¾Àý´úÂëÈçÏ£º
String className = ´ÓÅäÖÃÎļþ¶ÁÈ¡DoorµÄ¾ßÌåʵÏÖÀàµÄÀàÃû;
Door door = (Door) Class.forName(className).newInstance();
    ÔÙÅäºÏÒÀÀµ×¢ÈëµÄ·½·¨£¬¾ÍÌá¸ßÁËÈí¼þµÄ¿ÉÉìËõÐÔ¡¢¿ÉÀ©Õ¹ÐÔ¡£


Ïà¹ØÎĵµ£º

Java NIO APIÏê½â

 
Java NIO APIÏê½â
ÔÚJDK
1.4ÒÔÇ°£¬JavaµÄIO²Ù×÷¼¯ÖÐÔÚjava.ioÕâ¸ö°üÖУ¬ÊÇ»ùÓÚÁ÷µÄ×èÈû£¨blocking£©API¡£¶ÔÓÚ´ó¶àÊýÓ¦ÓÃÀ´Ëµ£¬ÕâÑùµÄAPIʹÓúܷ½
±ã£¬È»¶ø£¬Ò»Ð©¶ÔÐÔÄÜÒªÇó½Ï¸ßµÄÓ¦Óã¬ÓÈÆäÊÇ·þÎñ¶ËÓ¦Óã¬ÍùÍùÐèÒªÒ»¸ö¸üΪÓÐЧµÄ·½Ê½À´´¦ÀíIO¡£´ÓJDK 1.4Æð£¬NIO
API×÷Ϊһ¸ö»ùÓÚ»º³åÇø£¬²¢ÄÜÌṩ·Ç×èÈû(non-blo ......

JAVA »ñµÃIPµØÖ·

1. java »ñÈ¡ipµØÖ·µÄ´úÂë
    String loacalIp = "";
    try
   {
       InetAddress localhost = InetAddress.getLocalHost();
        loacalIp  =localhost.getHostAddress();
   ......

this ÓësuperÔÚjavaÖÐÔËÓÃÕûºÏ


 A.ʹÓùؼü×ÖthisµÄ×¼Ôò£º
1.ÔÚ¹¹ÔìÆ÷ÖУ¬Èç¹ûҪʹÓùؼü×Öthis,ÄÇô£¬±ØÐë·ÅÔÚµÚÒ»ÐУ¬·ñÔò½«µ¼ÖÂÒ»¸ö±àÒë´íÎó¡£
2.¹¹Ôì·½·¨ÒýÓÃthisÖ¸ÏòÕýÔÚÖ´Ðз½·¨µÄÀàµÄʵÀý¡£¾²Ì¬·½·¨²»ÄÜʹÓÃthis¹Ø¼ü×Ö£¬ÒòΪ¾²Ì¬·½·¨²»ÊôÓÚÀàµÄʵÀý£¬ËùÒÔthisÒ²¾ÍûÓÐʲô¶«Î÷È¥Ö¸Ïò¡£¹¹ÔìÆ÷µÄthisÖ¸Ïòͬһ¸öÀàÖУ¬²»Í¬²ÎÊýÁбíµÄÁíÍâÒ» ......

[zhuangzai]javaÈÝÆ÷

JavaÈÝÆ÷ÀàѧϰÐĵÃ
ÓÉÓÚÎÒ¶ÔC++±È½ÏÊìϤ£¬ËùÒÔѧϰJavaÓ¦¸ÃÖصãÌå»áJava´øÀ´µÄиÅÄî¡£±¾ÎÄ»ù±¾ÉÏÊÇJava±ê×¼¿âÖм¯ºÏ¿ò¼ÜµÄ»ù±¾¸ÅÄûÓÐÀý×Ó¡£Ð´±¾ÎĵÄÄ¿µÄÔÚÓÚ·½±ãÎҺܳ¤Ê±¼äºóÈôÊÇÍüÁËÕâЩ¶«Î÷¿ÉÒÔͨ¹ýÕâƬÎÄÕÂѸËÙ»ØÒäÆðÀ´¡£
1. ½Ó¿Ú
Õû¸öJavaÈÝÆ÷ÀàµÄ»ù´¡ÊÇÈÝÆ÷½Ó¿Ú£¨ÀýÈçCollection£¬MapµÈ½Ó¿Ú£©£¬¶ø²»ÊÇÀà ......

JAVAÊÓƵ

 ÍƼöÒ»¸ö¾ø¶Ô¾­µäµÄÊÓƵ£¬²»ºÃµÄÄÃשÅÄÎÒ°¡
ÎÞÒâÖÐÔÚÍøÉÏÏÂÔص½Ò»Ì×ÊÓƵ£¬ÒѾ­È«³ÌÌýÍ꣬¸Ð¾õ·Ç³£²»´í¡£´ÓJava»ù´¡¿ªÊ¼Ñ­Ðò½¥½ø£¬ÓÉdzÈëÉÊÓƵÖв»½ö¾«
±ÙµÄ½²½âÁËJava¿ª·¢µÄ֪ʶ£¬¶øÇÒÈÚÈëÁ˺ܶàѧϰ·½·¨µÄ½²½âºÍ±à³Ì˼ÏëµÄÒýµ¼£¬×ÛºÏÀ´Ëµ¿ÉÒÔÈË¿°³ÆÈëÃŵľ­µäÖ®
×÷!
ÌرðÍƼö¸ø´ó¼Ò£¬´ó¼Ò¹²Í¬½ø²½¡£°ÑÍøÖ·¸ø´ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ