¶ÁJAVAÍøÂç±à³Ì¾«½â ·þÎñÆ÷Óë¿Í»§¶ËͨÐÅÒ»
ÎÄÖÐÒýÓÃÁËËïÀÏʦµÄ´úÂ룬²¢×¢Ã÷¡£
import java.io.*;
import java.net.*;
public class EchoServer {
private int port=8888;
private ServerSocket serverSocket;
public EchoServer() throws IOException {
serverSocket = new ServerSocket(port);
System.out.println("·þÎñÆ÷Æô¶¯");
}
public String echo(String msg) {
return "echo:" + msg;
}
private PrintWriter getWriter(Socket socket)throws IOException{
OutputStream socketOut = socket.getOutputStream();
return new PrintWriter(socketOut,true);
}
private BufferedReader getReader(Socket socket)throws IOException{
InputStream socketIn = socket.getInputStream();
return new BufferedReader(new InputStreamReader(socketIn));
}
public void service() {
while (true) {
Socket socket=null;
try {
socket = serverSocket.accept(); //µÈ´ý¿Í»§Á¬½Ó
System.out.println("New connection accepted "
+socket.getInetAddress() + ":" +socket.getPort());
BufferedReader br =getReader(socket);
PrintWriter pw = getWriter(socket);
String msg = null;
while ((msg = br.readLine()) != null) {
System.out.println(msg);
pw.println(echo(msg));
if (msg.equals("bye")) //Èç¹û¿Í»§·¢Ë͵ÄÏûϢΪ“bye”£¬¾Í½áÊøͨÐÅ
break;
}
}catch (IOException e) {
e.printStackTrace();
}finally {
try{
if(socket!=null)socket.close(); //¶Ï¿ªÁ¬½Ó
}catch (IOException e) {e.printStackTrace();}
}
}
}
public static void main(String args[])throws IOException {
new EchoServer().service();
}
}
/****************************************************
* ×÷ÕߣºËïÎÀÇÙ *
* À´Ô´£º<<JavaÍøÂç±à³Ì¾«½â>> *
* ¼¼ÊõÖ§³ÖÍøÖ·£ºwww.javathinker.org *
**********************
Ïà¹ØÎĵµ£º
ÏÖÔÚ ËùÓÃJava°æ±¾,DateÀ๹Ôì·½·¨Date(0)µÄʱ¼ä²»ÊÇThu Jan 01 01:00:00 GMT 1970ÁË£¬¶øÊÇThu Jan 01 08:00:00 CST 1970¡££¨ 1970 Äê1 ÔÂ1 ÈÕ8ʱ0·Ö0Ãë ÐÇÆÚ4£©
Ϊʲô Date b1=new Date(623289600000); ²»¿ÉÒÔ£¬ÏÂÃæµÄÈ´¿ÉÒÔÄØ£¿
long a=623289600000L;
Date b1=new Date(a); Ò ......
import
java.util.Random;
/**
*
ÅÅÐò²âÊÔÀà
*
*
ÅÅÐòËã·¨µÄ·ÖÀàÈçÏ£º
*
1.
²åÈëÅÅÐò£¨Ö±½Ó²åÈëÅÅÐò¡¢ÕÛ°ë²åÈëÅÅÐò¡¢Ï£¶ûÅÅÐò£©£»
*
2.
½»»»ÅÅÐò£¨Ã°ÅÝÅÝÅÅÐò¡¢¿ìËÙÅÅÐò£©£»
*
3.
Ñ¡ÔñÅÅÐò£¨Ö±½ÓÑ¡ÔñÅÅÐò¡¢¶ÑÅÅÐò£©£»
  ......
/**
* ±£ÁôÁ½Î»Ð¡Êý
* @param d
* @return
*/
private static double remainTwoNumbers(double d){
java.math.BigDecimal f1 = new java.math.BigDecimal(d);//СÊýµãºó±£Áô2Î ......
import java.lang.reflect.*;
public class ReflectTester {
public Object copy(Object object) throws Exception{
//»ñµÃ¶ÔÏóµÄÀàÐÍ
Class classType=object.getClass();
System.out.println("Class:"+classType.getName());
//ͨ¹ýĬÈϹ¹Ôì·½·¨´´½¨Ò»¸öеĶÔÏó
Object objectCo ......
Java´«µÝ²ÎÊýÓÐÁ½ÖÖ £ºÖµ´«µÝ£¬ÒýÓô«µÝ
Ò»°ãÒýÓÃÀàÐÍ ÊÇÒýÓô«µÝ£¬ÖµÀàÐÍÊÇÖµ´«µÝ
ÖµÀàÐÍÊÇÔʼÊý¾ÝÀàÐÍ °üÀ¨ int,byte,char short long,boolean,float,double
ÒýÓÃÀàÐ;ÍÊÇÒ»°ãµÄclassÀà µ±È»Ò²°üÀ¨ÔʼÊý¾ÝµÄ·â×°ÀàÐÍ ±ÈÈçintµÄ
·â×°ÀàÐÍΪInteger
Ò»°ãÇé¿öÏ£º
Öµ´«µÝ£º
Àý×Ó 1 public void show1(int str ......