java rmi¼òµ¥Àý×Ó
----------½Ó¿Ú------------
import java.rmi.*;
public interface HelloIn extends java.rmi.Remote{
String sayHello() throws RemoteException;
}
--------ʵÏÖÀà-------------
import java.rmi.*;
import java.net.*;
import java.rmi.registry.*;
import java.rmi.server.*;
public class Hello extends java.rmi.server.UnicastRemoteObject implements HelloIn{
public Hello() throws RemoteException{
super();
}
public String sayHello() throws RemoteException{
return "Hello,World!";
}
public static void main(String[] args){
if(System.getSecurityManager()==null)
{
System.setProperty( "java.security.policy", "java.policy" );
System.setSecurityManager(new java.rmi.RMISecurityManager());
}
try{
HelloIn h=new Hello();
java.rmi.Naming.rebind("hello",h);
System.out.print("Ready......");
}
catch(Exception e){
e.printStackTrace();
}
}
}
-------------²âÊÔÀà----------------
import java.rmi.*;
import java.rmi.registry.*;
public class Helloworld{
public static void main(String[] args){
if(System.getSecurityManager()==null)
{
System.setProperty( "java.security.policy", "java.policy" );
System.setSecurityManager(new java.rmi.RMISecurityManager());
}
try{
HelloIn hi=(HelloIn)Naming.lookup("rmi://192.168.1.200/hello");
System.out.println(hi.sayHello());
}
catch(Exception e){
e.printStackTrace();
}
}
}
ÔËÐв½Öè
µÚÒ»²½:Éú³ÉclassÎļþ javac -d . *.java
µÚ¶þ²½:Éú³É¹æÔòÎļþ java.policy
java.policyÄÚÈÝ
/* AUTOMATICALLY GENERATED ON Wed Jan 20 15:03:35 CST 2010*/
/
Ïà¹ØÎĵµ£º
Ò»¡¢BorderLayoutTest.java
package com.briup.md08;
import java.awt.*;
import javax.swing.*;
/*BorderLayoutÌصã
1¡¢×é¼þµÄ´óСÓÉÈÝÆ÷¾ö¶¨
2¡¢ÈÝÆ÷±»»®·ÖΪ5¸öÇøÓò£¬Ã¿¸öÇøÓòÖ»ÄÜÖ±½Ó¼ÓÈë3¸ö×é¼þ
3¡¢×é¼þ¼ÓÈëµÄλÖÃÐèÒªÖ¸¶¨£¬Ä¬ÈÏΪCENTER
4¡¢×é¼þÖ®¼äĬÈÏûÓмä϶
5¡¢Èç¹û³ýCENTER ÒÔÍâµÄÇøÓòûÓмÓÈë×é¼þ£¬Æ ......
1¡¢ÖØÔØ(Overloading)
£¨1£©·½·¨ÖØÔØÊÇÈÃÀàÒÔͳһµÄ·½Ê½´¦Àí²»Í¬ÀàÐÍÊý¾ÝµÄÒ»ÖÖÊֶΡ£¶à¸öͬÃûº¯Êýͬʱ
´æÔÚ£¬¾ßÓв»Í¬µÄ²ÎÊý¸öÊý/ÀàÐÍ¡£ÖØÔØOverloadingÊÇÒ»¸öÀàÖжà̬ÐÔµÄÒ»ÖÖ±íÏÖ¡£
£¨2£©JavaµÄ·½·¨ÖØÔØ£¬¾ÍÊÇÔÚÀàÖпÉÒÔ´´½¨¶à¸ö·½·¨£¬ËüÃǾßÓÐÏàͬµÄÃû×Ö£¬µ«¾ß
Óв»Í¬µÄ²ÎÊýºÍ²»Í¬µÄ¶¨Òå¡£µ÷Ó÷½·¨Ê±Í¨¹ý´«µÝ¸øËüà ......
Java³£¼ûÎÊÌ⼯½õ:
ÎÊ:ÈçºÎÉèÖÃJava 2(JDK1.2)µÄ»·¾³±äÁ¿?
´ð:Java 2°²×°ºó,ÐèÒªÉèÖÃPATHºÍJAVA_HOME»·¾³±äÁ¿.ÓëJDK1.1²»Í¬µÄÊÇ:ÉèÖúÃJAVA_HOME»·¾³±äÁ¿ºó,JVM½«×Ô¶¯ËÑË÷ϵͳÀà¿âÒÔ¼°Óû§µÄµ±Ç°Â·¾¶.
Java 2»·¾³±äÁ¿µÄÉèÖÃÈçÏÂÀýËùʾ:
Solarisƽ̨: setenv JAVA_HOME Java2µÄ°²×°Â·¾¶
setenv PATH /bin:/p/2002-11-14 ......
ÏëÔÚ¿ª·¢ÖÐÌá¸ßËٶȺÍЧÂÊ£¡²»ÄÜÍü¼ÇµÄEclipse¿ì½Ý¼ü
Eclipse¿ì½Ý¼ü´óÈ«
ÍƼöCtrl+1 ¿ìËÙÐÞ¸´(×î¾µäµÄ¿ì½Ý¼ü,¾Í²»Óöà˵ÁË)
Ctrl+D: ɾ³ýµ±Ç°ÐÐ
Ctrl+Alt+↓ ¸´ÖƵ±Ç°Ðе½ÏÂÒ»ÐÐ(¸´ÖÆÔö¼Ó)
Ctrl+Alt+↑ ¸´ÖƵ±Ç°Ðе½ÉÏÒ»ÐÐ(¸´ÖÆÔö¼Ó)
Alt+↓ µ±Ç°ÐкÍÏÂÃæÒ»Ðн»»¥Î»ÖÃ(ÌرðʵÓÃ,¿ÉÒÔÊ¡È¥ÏȼôÇÐ,ÔÙÕ³Ìù ......
ÒªÏë½â¾ö“ÔàÊý¾Ý”µÄÎÊÌ⣬×î¼òµ¥µÄ·½·¨¾ÍÊÇʹÓÃsynchronized¹Ø¼ü×ÖÀ´Ê¹run·½·¨Í¬²½£¬´úÂëÈçÏ£º
public synchronized void run()
{
}
´ÓÉÏÃæµÄ´úÂë¿ÉÒÔ¿´³ö£¬Ö»ÒªÔÚvoidºÍpublicÖ®¼ä¼ÓÉÏsynchronized¹Ø¼ü×Ö£¬¾Í¿ÉÒÔʹrun·½·¨Í¬²½£¬Ò²¾ÍÊÇ˵£¬¶ÔÓÚͬһ¸öJavaÀàµÄ¶ÔÏóʵÀý£¬run·½·¨Í¬ ......