studentclient.java

来自「程序练习中包括书中实例程序代码和练习中要用到的代码,是压缩文件」· Java 代码 · 共 32 行

JAVA
32
字号
package examples.network;
import java.rmi.Naming;
import java.rmi.RMISecurityManager;
/** A client program that accesses and updates Student
  * objects on the server
  */
public class StudentClient {
   private static final String HOST_NAME = "localhost";
   public static void main( String[] args ) {
      if ( System.getSecurityManager() == null ) {
         System.setSecurityManager(
            new RMISecurityManager() );
      }
      try {
         Student s1001
            = (Student) Naming.lookup( "//" + HOST_NAME
                                       + "/Student1001" );
         Student s1005
            = (Student) Naming.lookup( "//" + HOST_NAME
                                       + "/Student1005" );
         System.out.println( s1001.getName() );
         System.out.println( s1005.getName() );
         System.out.println( s1001.getCredits() );         
         s1001.addCredits( 3 );
         s1001.setName( "Elaine Goldman" );
         System.out.println( s1001.getName() );
         System.out.println( s1001.getCredits() );         
      } catch ( Exception x ) {
         x.printStackTrace();
      }
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?