factorialimpl.java
来自「书籍《JAVA面向对象程序设计》书籍的课后源代码。相信对很多人都有帮助」· Java 代码 · 共 45 行
JAVA
45 行
/////// FactorialImpl.java ///////
package myrmi.example;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;
import java.rmi.server.UnicastRemoteObject;
public class FactorialImpl extends UnicastRemoteObject
implements Factorial
{
public FactorialImpl() throws RemoteException
{
super();
}
public int factorial(int n)
throws RemoteException
{
if ( n < 0 )
throw( new RemoteException(
"Arg to factorial cannot be negative."));
return ( n == 0 ) ? 1
: n*factorial(n-1);
}
public static void main(String args[])
{ // Create and install a security manager
if (System.getSecurityManager() == null)
{
System.setSecurityManager(new RMISecurityManager());
}
try
{
FactorialImpl obj = new FactorialImpl();
// Bind this object instance to the name "FactorialServer"
Naming.rebind("FactorialServer", obj);
System.out.println("FactorialServer bound in registry");
} catch (Exception e) {
System.out.println("FactorialImpl err: " + e.getMessage());
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?