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

ÓÃjava»ñÈ¡±¾»úIPµØÖ·

ÔÚÍøÉÏÕÒÁ˼¸¸öÓÃjava»ñÈ¡±¾»úIPµØÖ·µÄ´úÂ룬·¢ÏÖ¶¼ÉÙ¶¼ÓÐЩ²»ÍêÃÀ£¬×Ô¼ºÕûÀíÁËÒ»ÏÂ.ͻȻ֮¼äºÜÏë°Ñ×Ô¼ºµÄIPµØÖ·¸ø»ñÈ¡ÁË£¬ËäÈ»ÓÃϵͳ×Ô´øÃüÁî¿ÉÒԵõ½£¬µ«×Ô¼ºÏëдһ¸ö³ÌÐò»ñȡһϣ¬µ½ÍøÉÏËÑË÷ÁËÒ»ÏÂjava»ñÈ¡±¾»úIPµØÖ·µÄ·½·¨£¬½á¹û¾ÓÈ»·¢ÏÖûÓÐÒ»¸öÊÇ¿ÉÒÔÓõģ¬ÆøµÄÎÒÀÏÈ˼ÒÍÂѪ£¬
ÕâЩÈ˱Õ×ÅÑÛ¾¦Ð´³ÌÐò£¬Ð´ÍêÁ˾ÍÍùÍøÉÏ·¢£¬Ò²²»²âÊÔһϣ¬º¦µÄÎÒÒÔΪ×Ô¼ºRPÎÊÌ⣬ÀÏÊÇ»ñÈ¡²»µ½ÕýÈ·µÄIPµØÖ·£¬Ç¿ÁÒÇ´Ô𣡣¡£¡
ΪÁ˱íʾ±ÉÊÓ£¬ÏÖ°ÑÍøÉÏÕÒµ½µÄÖ÷ÒªµÄÁ½ÖÖ·½·¨µÄ²»×ã¸øÖ¸³öÒ»ÏÂ
·½·¨Ò»£¨Ö»ÄÜÔÚWindowsÉÏʹÓã¬Linuxƽ̨¾ÍgeiƨÁË£©£º
try
{
System.out.println("±¾»úµÄIP = " + InetAddress.getLocalHost());
} catch (UnknownHostException e)
{
e.printStackTrace();
}
ÔÚLinuxϵÄÖ´Ðнá¹ûÊÇ£º±¾»úµÄIP = xxx/127.0.1.1 (ÆäÖÐxxxÊÇÄãµÄ¼ÆËã»úÃû£¬Å¼ÕâÀïÂíÈü¿ËÁË)
·½·¨¶þ(Ðû³Æ¿ÉÒÔÔÚLinuxÏÂÖ´ÐÐ)
Enumeration netInterfaces=NetworkInterface.getNetworkInterfaces();
InetAddress ip = null;
while(netInterfaces.hasMoreElements())
{
NetworkInterface ni=(NetworkInterface)netInterfaces.nextElement();
System.out.println(ni.getName());
ip=(InetAddress) ni.getInetAddresses().nextElement();
if( !ip.isSiteLocalAddress()
&& !ip.isLoopbackAddress()
&& ip.getHostAddress().indexOf(":")==-1)
{
System.out.println ("±¾»úµÄip=" + ip.getHostAddress());
break;
}
else
{
ip=null;
}
}
´ÓºìÉ«²¿·ÖµÄ´úÂë¿ÉÒÔ¿´µ½£¬¸Ã´úÂë¶ÔÓÚ»ñÈ¡µ½µÄµÚÒ»¸öNetworkInterfaceµÄIPµØÖ·µÄ»ñÈ¡£¬Ã»ÓÐÑ­»·µÄ»ñÈ¡£¬Ö»ÊǶԵÚÒ»¸öIPµØÖ·½øÐÐÁË´¦Àí£¬ÕâÑù¾Íµ¼ÖÂÁËÈç¹ûµÚÒ»¸öIPµØÖ·²»ÊÇÒ»¸ö
Inet4AddressµÄµØÖ·¶øÊÇÒ»¸ö< span
id="ArticleContent1_ArticleContent1_lblContent">Inet6Address£¬Õâ¸öÅÐ¶Ï ip.getHostAddress().indexOf(":")==-1½«ÓÀÔ¶ÊÇfalse,Õâ¸öifÌõ¼þ½ø²»È¥Ñ½£¬¶àº¦ÈË£¬Ç¿ÁÒ±ÉÊÓ£¡
²»¹ý·½·¨¶þ˼·ÊǶÔÁË£¬¾ÍÊÇÓÐЩС벡£¬ÈÃżÐÞ¸ÄÁËһϣ¬×îÖÕ°æµÄ¿ÉÒÔÔÚ LinuxÏÂÕýÈ·Ö´ÐеĴúÂëÈçÏ£º
Enumeration allNetInterfaces = NetworkInterface.getNetworkInterfaces();
InetAddress ip = null;
while (allNetInterfaces.hasMoreElements())
{
NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement();
System.out.println(netInterface.getName());
En


Ïà¹ØÎĵµ£º

JavaỊ̈߳ºÏß³Ì״̬µÄת»»

JavaỊ̈߳ºÏß³Ì״̬µÄת»»
 
SCJP5ѧϰ±Ê¼Ç
 
Ò»¡¢Ïß³Ì״̬
 
Ï̵߳Ä״̬ת»»ÊÇÏ߳̿ØÖƵĻù´¡¡£Ïß³Ì״̬×ܵĿɷÖΪÎå´ó״̬£º·Ö±ðÊÇÉú¡¢ËÀ¡¢¿ÉÔËÐС¢ÔËÐС¢µÈ´ý/×èÈû¡£ÓÃÒ»¸öͼÀ´ÃèÊöÈçÏ£º
 
1¡¢ÐÂ״̬£ºÏ̶߳ÔÏóÒѾ­´´½¨£¬»¹Ã»ÓÐÔÚÆäÉϵ÷ÓÃstart()·½·¨¡£
 
2¡¢¿ÉÔËÐÐ״̬£ºµ±Ïß³ÌÓÐ× ......

JavaỊ̈߳ºÏ̵߳Äͬ²½ÓëËø

JavaỊ̈߳ºÏ̵߳Äͬ²½ÓëËø
 
 
 
Ò»¡¢Í¬²½ÎÊÌâÌá³ö
 
Ï̵߳Äͬ²½ÊÇΪÁË·ÀÖ¹¶à¸öÏ̷߳ÃÎÊÒ»¸öÊý¾Ý¶ÔÏóʱ£¬¶ÔÊý¾ÝÔì³ÉµÄÆÆ»µ¡£
ÀýÈ磺Á½¸öÏß³ÌThreadA¡¢ThreadB¶¼²Ù×÷ͬһ¸ö¶ÔÏóFoo¶ÔÏ󣬲¢ÐÞ¸ÄFoo¶ÔÏóÉϵÄÊý¾Ý¡£
 
public class Foo {
    private int x = 100;
......

JavaỊ̈߳ºÏ̵߳ĵ÷¶È ÊØ»¤Ïß³Ì

JavaỊ̈߳ºÏ̵߳ĵ÷¶È-ÊØ»¤Ïß³Ì
 
ÊØ»¤Ïß³ÌÓëÆÕͨÏß³Ìд·¨ÉÏ»ù±¾Ã´É¶Çø±ð£¬µ÷ÓÃÏ̶߳ÔÏóµÄ·½·¨setDaemon(true)£¬Ôò¿ÉÒÔ½«ÆäÉèÖÃΪÊØ»¤Ï̡߳£
 
ÊØ»¤Ïß³ÌʹÓõÄÇé¿ö½ÏÉÙ£¬µ«²¢·ÇÎÞÓ㬾ÙÀýÀ´Ëµ£¬JVMµÄÀ¬»ø»ØÊÕ¡¢ÄÚ´æ¹ÜÀíµÈÏ̶߳¼ÊÇÊØ»¤Ï̡߳£»¹ÓоÍÊÇÔÚ×öÊý¾Ý¿âÓ¦ÓÃʱºò£¬Ê¹ÓõÄÊý¾Ý¿âÁ¬½Ó³Ø£¬Á¬½Ó³Ø±¾ÉíÒ²°üº ......

ѧϰjavaµÄ30¸öÄ¿±ê

1.ÄãÐèÒª¾«Í¨ÃæÏò¶ÔÏó·ÖÎöÓëÉè¼Æ(OOA/OOD)¡¢É漰ģʽ(GOF£¬J2EEDP)ÒÔ¼°×ÛºÏģʽ¡£ÄãÓ¦¸ÃÊ®·ÖÁ˽âUML£¬ÓÈÆäÊÇ
class£¬object£¬interactionÒÔ¼°statediagrams¡£

¡¡¡¡2.ÄãÐèҪѧϰJAVAÓïÑԵĻù´¡ÖªÊ¶ÒÔ¼°ËüµÄºËÐÄÀà¿â
(collections£¬serialization£¬streams£¬networking£¬  
multithreading£¬reflection£¬event£ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ