📄 factorialimpl.java
字号:
/////// 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -