易截截图软件、单文件、免安装、纯绿色、仅160KB
热门标签: c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 最新文章 : java

java:Student类

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;
} ......

java:递归:上楼梯每次只能一步或者两步,有多少走法

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);
 }
} ......

java:递归:汉罗塔游戏计算出最少的步数

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);
 }
} ......

java:递归:10的阶乘

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);
 }
} ......

java:递归:10元钱按1,2,5元任意组合

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 快速入门实例

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.*;   
  
/ ......
总记录数:6386; 总页数:1065; 每页6 条; 首页 上一页 [93] [94] [95] [96] 97 [98] [99] [100] [101] [102]  下一页 尾页
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号