java socket±à³Ì
Ç°Ò»¶Îʱ¼ä¸Õ×öÁ˸öjava³ÌÐòºÍÍøÂçÉ϶ą̀»úÆ÷µÄc³ÌÐòͨѶµÄÏîÄ¿£¬×ñѵÄÊÇTCP/IPÐÒ飬Óõ½ÁËjavaµÄSocket±à³Ì¡£ÍøÂçͨѶÊÇjavaµÄÇ¿ÏÓÃTCP/IPÐÒé¿ÉÒÔ·½±ãµÄºÍÍøÂçÉϵÄÆäËû³ÌÐò»¥Í¨ÏûÏ¢¡£
ÏÈÀ´½éÉÜÏÂÍøÂçÐÒ飺
TCP/IP
Transmission Control Protocol ´«Êä¿ØÖÆÐÒé
Internet Protocol »¥ÁªÍøÐÒé
UDP
User Datagram Protocol Óû§Êý¾ÝÐÒé
Á¬½ÓÐÒ飺
·ÖΪ£º
ÃæÏòÁ¬½ÓÐÒé: Connection Oriented Protocol
·ÇÁ¬½ÓÐÒé: Connectionless Protocol
1).ÃæÏòÁ¬½ÓÐÒéÊÇÖ¸Á½Ì¨µçÄÔÔÚ´«ÊäÊý¾ÝÇ°£¬ÏȻὨÁ¢Ò»¸öרÊôµÄÁ¬½Ó¡£¾ÍÈçµçОֵĽ»»»»ú»áΪ´òµç»°Ë«·½ÌṩרÊôÁ¬½ÓÒ»Ñù¡£
InternetÉϵÄÃæÏòÁ¬½ÓÐÒé¾ÍÊÇTCP/IP
Ìص㣺ȷÈÏ»ØÓ¦£»·Ö×éÐòºÅ£»Á÷Á¿¿ØÖÆ¡£
TCP/IPÊôÓÚ¿É¿¿ÐÔ´«Ê䣬Êʺϲ»ÈÝÐíÓд«Êä´íÎóµÄÍøÂç³ÌÐòÉè¼ÆʹÓÃ
2).·ÇÁ¬½ÓÐÒ飺ÎÞרÊôÁ¬½Ó£¬ÎÞ·Ö×飬ÈÝ´í£¬¾àÀë¶Ì£¬¿Éͬʱ¶Ô¶ą̀µçÄÔ½øÐÐÊý¾Ý´«Êä
InternetÉϵķÇÁ¬½ÓÐÒé¾ÍÊÇUDP
TCPÔÚÍøÂçͨÐÅÉÏÓм«Ç¿µÄÉúÃüÁ¦£¬ÀýÈçÔ¶³ÌÁ¬½Ó£¨Telnet£©ºÍÎļþ´«Ê䣨FTP£©¶¼ÐèÒª²»¶¨³¤¶ÈµÄÊý¾Ý±»¿É¿¿µØ´«Êä¡£Ïà±ÈÖ®ÏÂUDP²Ù×÷¼òµ¥£¬¶øÇÒ½öÐèÒª½ÏÉٵļ໤£¬Òò´Ëͨ³£ÓÃÓÚ¾ÖÓòÍø¸ß¿É¿¿ÐԵķÖɢϵͳÖÐclient/serverÓ¦ÓóÌÐò¡£
Socket ÊdzÌÐòÓëÍøÂç¼äµÄÒ»ÖÖ½Ó¿Ú£¬´ó²¿·ÖÍøÂçÓ¦ÓóÌÐò¶¼Êǵã¶ÔµãµÄ£¬Ëùνµã¾ÍÊÇ·þÎñÆ÷¶ËºÍ¿Í»§¶ËËùÖ´ÐеijÌÐò¡£SocketÊÇÓÃÀ´½ÓÊպʹ«ËÍ·Ö×éµÄÒ»¸ö¶Ëµã¡£
javaµÄSocket±à³ÌÒªÓõ½java.net°ü£¬×î³£ÓõÄÊÇnet°üϵÄ6¸öÀࣺInetAddress(»¥ÁªÍøÐÒé (IP) µØÖ·)À࣬Socket(Ì×½Ó×Ö)À࣬ServerSocket(Ì×½Ó×Ö·þÎñÆ÷)À࣬DatagramSocket(·¢ËͺͽÓÊÕÊý¾Ý±¨°üµÄÌ×½Ó×Ö)À࣬DatagramPacket(Êý¾Ý±¨°ü)À࣬MulticastSocket(¶à²¥Êý¾Ý±¨Ì×½Ó×ÖÀàÓÃÓÚ·¢ËͺͽÓÊÕ IP ¶à²¥°ü)À࣬ÆäÖÐInetAddress¡¢Socket¡¢ServerSocketÀàÊÇÊôÓÚTCPÃæÏòÁ¬½ÓÐÒ飬DatagramSocket¡¢DatagramPacketºÍMulticastSocketÀàÔòÊôÓÚUDP·ÇÁ¬½ÓÐÒéµÄ´«ËÍÀà¡£
±¾ÏîÄ¿ÒòΪʹÓÃTCP/IPÐÒ飬Ö÷ÒªÓõ½SocketºÍServerSocketÀ
Ïà¹ØÎĵµ£º
public class MultiThread {
public static void main(String[] args) {
ProductStack box = new ProductStack("box");
Producer p1 = new Producer(box, "p1");
Producer p2 = new Producer(box, "p2");
Producer p3 = new Producer(box, "p3");
&nb ......
ÔÚJavaÖУ¬µ±Ò»¸ö¶ÔÏó±»´´½¨Ê±£¬³ÉÔ±±äÁ¿µÄ³õʼ»¯¼°¹¹Ôì·½·¨µÄµ÷ÓÃ×ñÑÒÔÏÂ˳Ðò£º
1. ½«·ÖÅä¸ø¶ÔÏóµÄ´æ´¢¿Õ¼ä³õʼ»¯³É¶þ½øÖƵÄÁã¡£
2. µ÷ÓÃËùÓлùÀàµÄ¹¹Ôì·½·¨¡£Õâ¸ö²½Öè»á²»¶ÏµØ·´¸´µÝ¹éÏÂÈ¥£¬Ê×ÏÈÊǹ¹ÔìÕâÖÖ²ã´Î½á¹¹µÄ¸ù£¬È»ºóÊÇÏÂÒ»²ã×ÓÀ࣬µÈµÈ£¬Ö±µ½×îµ×²ãµÄ×ÓÀà¡£
3. °´ÕÕÉùÃ÷µÄ˳Ðòµ÷ÓóÉÔ±µÄ³õʼ»¯·½·¨¡£
4. µ÷ ......
1 SimpleDateFormatµ£µ±ÖØÈÎ,ÔõÑù¸ñʽ»¯¶¼ÐÐ
import java.util.Date;
import java.text.SimpleDateFormat;
public class Demo
{
public static void main(String[] args)
{
Date now=new Date();
SimpleDateFormat f=newSimpleDateFormat("½ñÌìÊÇ"+"yyyyÄêMMÔÂddÈÕ E kkµãmm·Ö");
System.out.println(f.fo ......
JavaΪÊý¾Ý½á¹¹µÄÓ³É䶨ÒåÁËÒ»¸ö½Ó¿Újava.util.Map.ËüÓÐËĸöʵÏÖÀ࣬·Ö±ðÊÇHashMap, Hashtable,LinkedHashMapºÍTreeMapÖ÷ÒªÓÃÓÚ´æ´¢¼üÖµ¶Ô£¬¸ù¾Ý¼üµÃµ½Öµ£¬Òò´Ë²»ÔÊÐí¼üÖظ´£¬µ«ÔÊÐíÖµÖظ´¡£
HashMapÊÇÒ»¸ö×î³£ÓõÄMap£¬Ëü¸ù¾Ý¼üµÄHashCodeÖµ´æ´¢Êý¾Ý£¬¸ù¾Ý¼ü¿ÉÒÔÖ±½Ó»ñÈ¡ËüµÄÖµ£¬¾ßÓкܿìµÄ·ÃÎÊËٶȣ¬± ......
8ÖÖ»ù±¾Êý¾ÝÀàÐÍÓÐÏàÓ¦µÄ8ÖÖ°ü×°Àà(Wrapper)¶ÔÓ¦,·Ö±ðÊÇ:Character,Byte,Short,Integer,Long,Float,Double,Boolean.
Ìصã:
1.ÌṩÁËvalueOf(String)ÓÃÓÚ´Ó×Ö·û´®×ª»»¼°toString()ת»»³É×Ö·û´®
2.ͨ¹ýxxxxValue()·½·¨¿ÉÒԵõ½Ëù°ü×°µÄÖµ,ÈçInteger¶ÔÏóµÄintValue()·½·¨.
ʾÀý´úÂë:
public class DoubleAndString {
pu ......