java第9天代码(集合类)
/**********Customer .java begin***********/
import java.util.HashSet;
import java.util.Set;
/**
* 如果两个Customer对象nama属性和age属性相同,那么这两个Customer对象相等。
* @author Administrator
*
*/
public class Customer {
private String name;
private int age;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public void setName(String name) {
this.name = name;
}
public void setAge(int age) {
this.age = age;
}
public Customer(String name, int age) {
super();
this.name = name;
this.age = age;
}
public Customer(){}
/**
* 如果Customer类覆盖了Object类中的equals方法,但没有覆盖Object中的HashCode方法,
* 就会导致当Customer1.equals.(Customer2)为true时,而Customer1和Customer2的哈
* 希码不一定一样,就会使HashSet无法工作。
*/
@Override
public boolean equals(Object obj) {
if((obj instanceof Customer)){
Customer other=(Customer) obj;
if(this.name.equals(other.getName()) && this.age==other.getAge()) {
return true;
}
}
return false;
}
/**
* 为了保证HashSet的正常工作,如果Customer类覆盖了equals方法,同时也应该去覆盖hashCode
* 方法,并且保证两个相等对象的哈希码也是一样。
*/
// @Override
public int hashCode() {
int result;
result=(name==null?0:name.hashCode());
result=result+age;
return result;
}
public static void main(String args[]){
Set set=new HashSet();
&nb
相关文档:
面向Java应用的快速Web服务支持工具 - Netrifex
Proxisoft今天宣布Netrifex 1.0版。
Netrifex可以立即把Web Services添加到现有的Java SE和Java EE应用程序,从而实现把Web Services快速、低费用的部署到整个企业应用。
Netrifex增加Web Services到现有的Java应用中。该产品使用户能够:
* 快速创建Web Service ......
JAVA语言中的反射机制:
在Java 运行时 环境中,对于任意一个类,能否知道这个类有哪些属性和方法?
对于任意一个对象,能否调用他的方法?这些答案是肯定的,这种动态获取类的信息,以及动态调用类的方法的功能来源于JAVA的反射。从而使java具有动态语言的特性。
JA ......
Dojo 在基于Web 的应用程序中越来越受到欢迎。很多开发人员是 Java™ 编程方面的能手,但是在 JavaScript
方面却缺乏经验。从强类型、面向对象的编译语言转向动态的、弱类型脚本语言,开发人员需要经历概念跃迁带来的困难。这种混乱使开发人员很难正确地声明
Dojo 类。本文将帮助梳理这种混乱,解释为何必须 ......
oracle
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:orcl";
String user="scott";
String password="tiger";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_S ......