星期五, 五月 25, 2007

去除list中的重复元素

用HashSet
 
Iterator it =list.iterator();
HashSet set = new HashSet();

while(it.hasNext()){
set.add(it.next());
}
it = set.iterator();
list.clear();
while(it.hasNext()){
list.add(it.next());
}

或者是
 
list = new ArrayList(new HashSet(oldList));
 

星期四, 五月 24, 2007

java 读 properties格式文件


package hddqcs.datamining.venus.venusfile;

import hddqcs.datamining.venus.common.DMLogger;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

/**
 *
 * COPYRIGHT(C) Hitachi Global Storage Technologies, Inc.
 * All Rights Reserved.
 *
 * This Class is to reading the process config file
 *
 *  eg. etl_venusProcess.properties
 *
 * @author liuqact
 */
public class ReadingProcessProsFile {
 Logger logger = Logger.getLogger(ReadingProcessProsFile.class.getName());
 public Properties getProperties(String dir,String fileName)throws FileNotFoundException,IOException,Exception {
  // TODO Auto-generated method stub
  try{
   Properties pros = new Properties();
   InputStream prosFile = new FileInputStream("Log4j.properties");
   pros.load(prosFile);
  return pros;
  }catch(FileNotFoundException e){
   logger.error("Properties file inputted is not exist");
   throw e;
  }catch(IOException e){
   logger.error("Reading Properties file inputted failed");
   throw e;
  }catch(Exception e){
   logger.error("get values from Properties file inputted failed");
   throw e;
  }
 }
}

关于serialVersionUID


在定义一个实现接口java.io.Serializable 的类时
如果用EC IDE 会有缺少 UID的警告
 
加一个吧,可以减少程序运行时的资源消耗
 
在EC中,假如类出现这样的警告,那么你可以把鼠标放到类名上,然后
CTRL+1
看看出现在什么
中间有一个是生成serialVersionUID的
 

星期三, 五月 23, 2007

Java操作Excel的一些可以参考的资源

http://sourceforge.net/projects/jexcelapi
JExcelApi is a java library which provides the ability to read, write, and modify
Microsoft Excel spreadsheets. This project mirrors the files on http://www.jexcelapi.org,
which has been known to go down on occasion.

 http://sourceforge.net/projects/excelutils
ExcelUtils, easy export report in excel by excelutils.It like velocity or freemarker, but
it's script is written in excel to control excel format and data.

http://sourceforge.net/projects/exceltemplate
Templating system for Microsoft Excel files in Java.
 
http://sourceforge.net/projects/jaoff
JavaOffice is a pure Java library to read and write MS Word files in the new WordML (format) and
MS Excel files in the new SpreadsheetML format. WordML and SpreadsheetML are xml formats for word
and excel files supported from Office 2003 and above.
 
Simple library written in Java to allow the creation of Excel files based on a Java Collection.
Each element of the collection goes in a row and the columns are based on the properties you define
through an XML config file.
 
http://sourceforge.net/projects/caxton
Caxton is a general purpose package written in Java that is used to render HTML, PDF (using FOP),
 RTF (using JFOR), and Excel (using POI) using stylesheets. There are some additional tools for
 providing easy access to XML, merging XSL stylesheets

Eclipse插件-- Bytecode Outline,Implementors, FindBugs 等

1. Eclipse插件之Bytecode Outline

本文介绍如何利用Eclipse插件Bytecode Outline在Eclipse中的操作使用。

  Eclipse是目前非常流行的开发平台,开放扩展的架构让很多程序员找到了自己个性化的工作环境。

  Bytecode Outline 插件可以把当前的正在编辑Java的文件或者class文件直接显示出其相应的字节码出来,而且可以进行两个Java文件的字节码比较或者两个class文件的字节码比较或一个Java文件与一个class文件进行字节码的比较。
 

原文出处: http://dev2dev.bea.com.cn/bbsdoc/20060123182.html

2 Eclipse插件之Implementors

本文介绍如何利用Eclipse插件Implementors在Eclipse中的使用。

  Eclipse是目前非常流行的开发平台,开放扩展的架构让很多程序员找到了自己个性化的工作环境。

问题提出:
  如果你想看看某个类或者方法的实现,一般是Ctrl + 鼠标左键,单击即可以打开这个类或者方法的具体实现代码。但是如果碰到接口时,只是到达接口而已,不能到达具体的实现类里。

解决方法:利用Eclipse的Implementors插件。
  当追踪方法代码时,Eclipse默认是转到方法的接口类,而接口中是只有方法名称没有具体的实现代码,此插件提供了追踪到具体实现类的实现代码的功能。

  另外还有Call Hierarchy插件: 显示一个方法的调用层次,可以从中看到它被哪些方法调用了,以及它调用了哪些方法,是代码追踪比较实用的工具。Eclipse 3.1中已经自带有这个功能了。这个插件就不用另加介绍了。

详细信息参考: http://dev2dev.bea.com.cn/bbsdoc/20060124188.html 

3 利用Eclipse开发Hibernate应用程序 --Hibernate Synchronizer插件

介绍如何利用Hibernate Synchronizer插件在Eclipse 3.0.1中快速的开发Hibernate应用程序,提高我们的工作效率。
本文介绍如何利用Eclipse插件EasyExplorer在Eclipse中的使用。

  Eclipse是目前非常流行的开发平台,开放扩展的架构让很多程序员找到了自己个性化的工作环境,Hibernate也是目前很流行的O/R Mapping框架,至少在EJB 3.0大行其道之前,它是我们在考虑O/R Mapping时非常好的选择。

  关于Hibernate框架的细节,请参考《Hibernate in Action》一书。

详细内容点击这里: http://dev2dev.bea.com.cn/bbsdoc/20060124187.html

4 Eclipse插件之EasyExplorer

  Eclipse是目前非常流行的开发平台,开放扩展的架构让很多程序员找到了自己个性化的工作环境。

问题提出:
  如果你经常需要在Eclipse里打开相关资源文件所在的文件夹,比较麻烦,要右键,属性,在Location一栏中把所在的文件夹拷贝一下,然后再去资源管理器里输入这个路径,回车,打开它。

解决方法:
  用EasyExplorer插件,有了这个插件就可以很方便地打开资源文件所在的文件夹了。
 

详细内容点击这里 ; http://dev2dev.bea.com.cn/bbsdoc/20060124184.html 

5 Eclipse插件之SQLExplorer

本文介绍如何利用Eclipse插件SQLExplorer在Eclipse中连接各种数据库进行操作使用。

  Eclipse是目前非常流行的开发平台,开放扩展的架构让很多程序员找到了自己个性化的工作环境。
 

详细内容点击这里 http://dev2dev.bea.com.cn/bbsdoc/20060126189.html 

6 Eclipse插件之FindBugs

本文介绍如何利用Eclipse插件FindBugs在Eclipse中的使用。

  Eclipse是目前非常流行的开发平台,开放扩展的架构让很多程序员找到了自己个性化的工作环境。

问题提出:
  当我们编写完代码,做完单元测试等各种测试后就提交正式运行,只能由运行的系统来检测我们代码是否有问题了,代码中隐藏的错误在系统运行的过程中被发现后,然后再来进行相应的修改,那么后期修改的代价就相当高了。

解决方法:
  现在有很多Java代码分析工具,FindBugs中开源项目当中的一个,它可以帮你找到代码中隐藏的一些错误,提升你的代码能力与系统安全可靠性。
 
FindBugs:0.9.4 从http://findbugs.sourceforge.net/
官方的文档 http://findbugs.sourceforge.net/manual/
Eclipse plugin for FindBugs version 0.0.17
从 http://findbugs.sourceforge.net/downloads.html 下载

详细内容点击这里: http://dev2dev.bea.com.cn/bbsdoc/20060124186.html