package collection;
public class Student {
public Student() {}
public Student(String name, String sex, int age) {
this.name = name;
this.sex = sex;
this.age = age;
}
@Override
public String toString() {
return "Student [toString()=" + this.name+"-->"+ this.sex +"-->"+ this.age + "]";
}
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
private String sex;
private int age;
} ......
package floatt;
public class Go {
public static int i = 0;
public static void main(String[] args){
calc("", 5);
System.out.println("总共有"+i+"种走法~");
}
//上楼梯每次只需一步或者两步,有多少走法
public static void calc(String log, int num){
if (num == 0) {
i++;
System.out.println(log.substring(0,log.length()-1));
return;
}else if(num == 1) {
i++;
System.out.println(log+"1");
return;
}
calc(log+"1,", num - 1);
calc(log+"2,", num - 2);
}
} ......
package game;
public class HanTa {
public static int i = 0;
public static void main(String[] args){
calc('A', 'B', 'C', 2);
System.out.println("最少需要"+i+"步。");
}
//汉罗塔游戏计算
public static void calc(char src, char ilde, char dest, int num){
if(num == 1){
i++;
System.out.println(src+"-->"+dest);
return;
}
calc(src, dest, ilde, num - 1);
i++;
System.out.println(src+"-->"+dest);
calc(ilde, src, dest, num - 1);
}
} ......
package game;
public class JieCeng {
public static void main(String[] args){
System.out.println(fun(10));
}
public static int fun(int n){
if(1==n)
return 1;
System.out.println( n * fun(n-1));
return n * fun(n-1);
}
} ......
package game;
public class Money {
public static void main(String[] args) {
fun("", 10);
System.out.println("总共算法:" + i);
}
// 10元钱的组成,1,2,5任意组合
public static int i = 1;
public static void fun(String log, int n) {
// int num = n;
if (0 == n) {
System.out.println(log.substring(0, log.length() - 1) + "=");
return;
} else if (1 == n) {
System.out.println(log + "1" + "=");
return;
}
if (n >= 1)
fun(log + "1+", n - 1);
if (n >= 2)
fun(log + "2+", n - 2);
if (n >= 5)
fun(log + "5+", n - 5);
i++;
}
} ......
JAVA RMI 快速入门实例
本实例为参考多篇文章写就而成,网上及书上各类文章介绍如何使用RMI有多种实例可参考,譬如有:
1. 用命令rmiregistry启动RMI注册服务的
2. 同时创建存根(stub)和骨架(skeleton)的
3. 只创建存根类的的(jdk1.2以后版本)
4. 通过RemoteRef和rmi://协议字串方式的
5. 比较少讲到的用LocateRegistry直接在代码上启动RMI注册服务的。
以上描述并非明显分类,比如,你总是可以选择用rmiregistry或者代码LocateRegistry启动RMI注册服务
下面我将介绍一个完整的实例,让初学者能快速体验RMI的功用。
分为以下四个步骤
1. 创建远程接口及声明远程方法(HelloInterface.java)
2. 实现远程接口及远程方法(继承UnicastRemoteObject)(Hello.java)
3. 启动RMI注册服务,并注册远程对象(HelloServer.java)
4. 客户端查找远程对象,并调用远程方法(HelloClient)
5. 执行程序:启动服务HelloServer;运行客户端HelloClient进行调用
具体代码及对应步骤如下:
1. 创建远程接口及声明远程方法(HelloInterface.java)
java 代码
package com.unmi;
import java.rmi.*;
/ ......