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

javaÓëÍøÂç


1 ÍøÂçͨÐŵı¾ÖÊÊǽø³Ì¼äͨÐÅ¡£   
2 TcpЭÒéºÍUDPЭÒé
TCP£º¿ªÏú´ó£¬ÓÃÓÚ¿É¿¿ÐÔÒªÇó¸ßµÄ³¡ºÏ¡£
TCPµÄ¹ý³ÌÏ൱ÓÚ´òµç»°µÄ¹ý³Ì
UDP£ºÓÃÔÚ¶ÔʵʱÐÔÒªÇó±È½Ï¸ßµÄ³¡ºÏ¡£
UDPµÄ¹ý³ÌÏ൱ÓÚдÐŵĹý³Ì¡£
×¢Ò⣺socketÊÇÌ×½Ó×Ö£¬ipºÍport£¨¶Ë¿ÚºÅ 0~65535¸ö¶Ë¿Ú£¬Ò»¸ö¶Ë¿ÚÖ»ÄÜÓÐÒ»¸ö½ø³Ì£©
3£¬    TCPͨÐÅ»úÖÆ£¬tcpÊÇÃæÏòÁ¬½ÓµÄ£¬ÊµÏÖ¶àÏ̵߳ķ½·¨ÓÐÈý¸ö
¢Ù Ϊÿ¸ö¿Í»§·ÖÅäÒ»¸ö¹¤×÷Ï̡߳£
¢Ú  ´´½¨Ò»¸öÏ̳߳أ¬ÓÉÆäÖеŤ×÷Ïß³ÌÀ´Îª¿Í»§·þÎñ¡£
¢Û  ÀûÓÃJDKµÄJavaÀà¿âÖÐÏֳɵÄÏ̳߳أ¬ÓÉËüµÄ¹¤×÷Ïß³ÌÀ´Îª¿Í»§·þÎñ¡£
ÏÂÃæÒÔΪÿ¸ö¿Í»§·ÖÅäÒ»¸ö¹¤×÷Ïß³ÌÀ´ÊµÏÖ¶àÏß³Ì
ÔÚ·þÎñ¶Ë
import java.net.*;
import java.io.*;
public class TCPServer2 {
   public static void main(String[] args) throws Exception{
      ServerSocket ss=new ServerSocket(9000);//¶Ë¿ÚºÅ
      while(true){
           Socket s=ss.accept();//Á¬½Ó¼àÌý¿Í»§¶Ë
           System.out.println(s.getInetAddress());
           Thread t=new ServerThread(s);//ʵÏÖ¶àÏß³ÌÁ¬½Ó
           t.start();
      }
   }
}
class ServerThread extends Thread{//·ÖÅäÏß³Ì
   Socket s;
   public ServerThread(Socket s){
      this.s=s;
   }
public void run(){
   try {
      OutputStream os=s.getOutputStream();//ÔÚÍøÂçÖлñÈ¡Êä³öÁ÷
      PrintWriter out=new PrintWriter(os);
      for(int i=1;i<=30;i++){
      out.println("Hello "+i);//ͨ¹ýÍøÂç·¢ÏûÏ¢¸ø¿Í»§¶Ë
      out.flush();
      Thread.sleep(1000);
           }
      } catch (Exception


Ïà¹ØÎĵµ£º

javaÊý¾ÝÀàÐÍÖ®¼äµÄת»»

 1£®JavaµÄ¼òµ¥ÀàÐͼ°Æä·â×°Æ÷Àà
¢ÅJava¼òµ¥ÀàÐÍÓë·â×°Àà
ÎÒÃÇÖªµÀ,JavaÓïÑÔÊǵäÐ͵ÄÖ§³ÖÃæÏò¶ÔÏóµÄ³ÌÐòÓïÑÔ,µ«¿¼Âǵ½ÓÐЩ»ù±¾Êý¾ÝÀàÐ͵Ľṹ¼òµ¥,Õ¼ÄÚ´æÐ¡ÇÒ´æÈ¡ËÙ¶È¿ìµÈÓŵã,JavaÒÀÈ»ÌṩÁ˶ÔÕâЩ·ÇÃæÏò¶ÔÏóµÄ¼òµ¥Êý¾ÝÀàÐ͵ÄÖ§³Ö¡£µ±È»,JavaÔÚÌṩ´óÁ¿µÄÆäËüÀàʱ,Ò²ÌṩÁËÓë¼òµ¥Êý¾ÝÀàÐͶÔÓ¦µÄ·â×°Àà,ÓÚÊÇ,JavaÖ ......

javaʱ¼ä¶¯Ì¬ÏÔʾ Á½ÖÖ·½·¨

ʱ¼ä¶¯Ì¬ÏÔʾ
1.·½·¨Ò» ÓÃTimerTask
ÀûÓÃjava.util.TimerºÍjava.util.TimerTaskÀ´×ö¶¯Ì¬¸üУ¬±Ï¾¹Ã¿´Î¸üпÉÒÔ¿´×÷ÊǼÆÊ±1Ãë·¢ÉúÒ»´Î¡£
´úÂëÈçÏ£º
import java.awt.Dimension;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util ......

Java֮staticѧϰ

¶ÔÓÚѧϰstaticÎÒÃÇÏÈÀ´¿´Á½¸öÀý×Ó£º
//Example 1 Tst.java£¬no main() method
package com.blogchina.qb2049;
public class Tst
{
static { System.out.println("111111"); }
}
ÔËÐнá¹ûΪ: 111111
Exception in thread "main" java.lang.NoSuchMethodError: main
ͬÑùµÄµÀÀí¿´µÚ¶þ ......

Serializable javaÐòÁл¯

Bean Serializable Interface µÄ½Ó¿ÚÈÃBEAN¿ÉÒÔ´®Ðл¯£¬½«Æä±ä³ÉÒ»¸ö¿É±£´æÎªÒÔºóʹÓõĶþ½øÖÆÁ÷¡£µ±Ò»¸öBEAN±»ÏµÁл¯µ½´ÅÅÌÉÏ»òÕ߯äËûÈκεط½£¬Æä״̬±»±£´æÆðÀ´£¬ÆäÖеÄÊôÐÔÖµÒ²²»»á¸Ä±ä¡£ÔÚBEANµÄ¹æ·¶ÖУ¬JSP²¢Ã»ÓÐÒªÇóBEANʵÏÖSerializable½Ó¿Ú¡£µ«ÊÇ£¬Èç¹ûÄúÏ£Íû×Ô¼º¿ØÖÆÄúËù´´½¨µÄ×é¼þµÄserialization½ø³Ì£¬»òÕßÄúÏë ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ