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

java UDP´«Êä

TCPͨ¹ý ServerSocket ºÍ Socket À´ÊµÏÖ´«Êä
UDPÖ÷Ҫͨ¹ý DatagramSocket ºÍ DatagramPacket À´Íê³É´«Êä
Ö±½ÓÉÏ´úÂë
·þÎñÆ÷¶Ë£º
public class UdpServer
{
private DatagramSocket server;
private DatagramPacket packet;
private byte[] b;
private String str;
public UdpServer()
{
Init();
}
private void Init()
{

b = new byte[1024];

receive();
}
private void receive()
{
try
{
server=new DatagramSocket(11111); //°ó¶¨11111¶Ë¿Ú
while(true)
{
packet = new DatagramPacket(b, b.length);
server.receive(packet); //½ÓÊÕÊý¾Ý°ü
int i = packet.getLength();
if(i>0) //Êý¾Ý°üÓÐÄÚÈÝ£¬¾Í´òÓ¡³ö½ÓÊÕµ½µÄÊý¾Ý
{
str = new String(b, 0, i);
System.out.println("½ÓÊÕµ½µÄ×Ö·û == " + str);
packet = null;
}
}
}catch(SocketException e)
{
e.printStackTrace();
}catch(IOException e)
{
e.printStackTrace();
}finally
{
server.close();
}
}
public static void main(String[] args)
{
new UdpServer();
}
}
¿Í»§¶Ë£º
public class UdpClient
{
private DatagramSocket client;
private DatagramPacket packet;
private byte b[];
public UdpClient()
{
Init();
}
private void Init()
{
b = new byte[1024];

send();
}
private void send()
{
try
{
client = new DatagramSocket();

b = "UDPÊý¾Ý·¢ËÍ".getBytes(); //·¢Ë͸ø·þÎñÆ÷¶ËµÄÊý¾Ý

packet = new DatagramPacket(b, b.length, new InetSocketAddress("127.0.0.1", 11111)); //°ó¶¨·þÎñÆ÷
client.send(packet); //·¢ËÍÊý¾Ý°ü
} catch (SocketException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
} finally
{
client.close();
}
}
public static void main(String[] args)
{
new UdpClient();
}
}


Ïà¹ØÎĵµ£º

JAVA»ñµÃµ±Ç°Ê±¼ä

import java.util.Date;
import java.text.SimpleDateFormat; //ΪÁËÏÔʾʱ¼ä¶ø¼Ó
Date date = new Date(); //»ñµÃϵͳʱ¼ä.
String nowTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
//½«Ê±¼ä¸ñʽת»»³É·ûºÏTimestampÒªÇóµÄ¸ ......

linuxϲ鿴java·¾¶

ÓÃÃüÁî whereis java¾Í¿ÉÒÔ¿´µ½ÁË
eg:
-bash-3.1$ whereis java
java: /usr/bin/java /etc/java /usr/lib/java /usr/share/java /opt/jdk1.6.0_01/bin/java

Èç¹û½ö½öÏëÖªµÀjavaÖ´Ðз¾¶ÔÚÄÇÀïµÄ»° ÓÃwhich java¾Í¿ÉÒÔÁË
eg:
-bash-3.1$ which java
/usr/bin/java ......

Java/jsp ºÃµÄÈëÃÅÎÄÕ¹²ÉÍ

ÓÃJSP¹¹½¨¶¯Ì¬ÍøÕ¾ ËïÒÔÒå ¶Å¾é
Ò»¡¢ ʲôÊÇJSP JSP(JavaServer Pages)ÊÇÓÉSun Microsystems¹«Ë¾³«µ¼¡¢Ðí¶à¹«Ë¾²ÎÓëÒ»Æð½¨Á¢µÄÒ»ÖÖ¶¯Ì¬ÍøÒ³¼¼Êõ±ê×¼£¬ÆäÍøַΪ
http://www.javasoft.com/products/jsp¡£ ÔÚ´«Í³µÄÍøÒ³HTMLÎļþ(*.htm,*.html)ÖмÓÈëJava³ÌÐòƬ¶Î(Scriptlet)ºÍJSP±ê¼Ç(tag)£¬¾Í¹¹
³ÉÁËJSPÍøÒ³(*.jsp)¡£Web· ......

Java¿ª·¢WebServiceʵÀý ¼ÆÊýÆ÷


Ò»¡¢Ç°ÑÔ
   ±¾Îļٶ¨ÄãÓÐÒ»¶¨µÄJ2EE¿ª·¢¾­Ñ飬Õâ¸ö½Ì³ÌûÓйý¶àµÄÉæ¼°»ù´¡ÖªÊ¶ºÍ¿ª·¢Ï¸½Ú¡£Èç¹ûÔÚÔĶÁ¹ý³Ì³öÓÐʲôÎÊÌ⣬»¹ÇëÓëÎÒÁªÏµ½»Á÷¡£
     Èç¹ûʹÓÃGOOGLE¡¢BAIDUµÈËÑË÷¹¤¾ß£¬ËÑË÷WebServiceµÄÏà¹Ø֪ʶ£¬¿ÉÒԲ鵽N¶àµÄÍøÒ³£¬ÎÒ¾ÍÊÇͨ¹ýÕâЩÍøÒ³µÄѧϰ£¬Öð½¥ÕÆÎÕÁËЩW ......

java Ï̺߳ǫ́ÔËÐÐʾÀý

import java.io.IOException;
public class ResponseUI extends Thread{
private static volatile double d = 1;

public ResponseUI(){
super.setDaemon(true); //ÉèÖúǫ́ÔËÐÐ
start();
}

public void run(){
while(true){
d = d + (Math.E + Math.PI) / d;
}
}
/**
* @param args ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ