??xml version="1.0" encoding="utf-8" standalone="yes"?>国产精品国产亚洲伊人久久,亚洲一区二区三区四区在线观看,国产精品麻豆久久http://www.aygfsteel.com/merek/category/21049.htmlzh-cnSun, 11 Oct 2009 20:08:26 GMTSun, 11 Oct 2009 20:08:26 GMT60java中的transient(转蝲)http://www.aygfsteel.com/merek/articles/297633.html肖麦肖麦Sat, 10 Oct 2009 02:03:00 GMThttp://www.aygfsteel.com/merek/articles/297633.htmlhttp://www.aygfsteel.com/merek/comments/297633.htmlhttp://www.aygfsteel.com/merek/articles/297633.html#Feedback0http://www.aygfsteel.com/merek/comments/commentRss/297633.htmlhttp://www.aygfsteel.com/merek/services/trackbacks/297633.htmlJava语言的关键字Q用来表CZ个域不是该对象串行化的一部分。当一个对象被串行化的时候,transient型变量的g包括在串行化的表CZQ然而非transient型的变量是被包括q去的。还是不大明白?br />     后来Q终于搜到这文章,写得很详l。Be Careful With Transient Data
    怕万一q篇文章链接失效Q收藏v来。Be Careful With Transient Data
  
    l于明白了?br />     当串行化某个对象Ӟ如果该对象的某个变量是transientQ那么这个变量不会被串行化进厅R也是_假设某个cȝ成员变量是transientQ那么当通过ObjectOutputStream把这个类的某个实例保存到盘上时Q实际上transient变量的值是不会保存的。因为当从磁盘中dq个对象的时候,对象的该变量会没有被赋倹{?br />     另外q篇文章q提刎ͼ当从盘中读出某个类的实例时Q实际上q不会执行这个类的构造函敎ͼ而是dq个cȝ实例的状态,q且把这个状态付l这个类的对象。这Ҏ(gu)以前g不知道?br />
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1064847

 

 

 Be Careful With Transient Data



(原文来自http://www.devx.com/tips/Tip/13726)

Expertise: Intermediate
Language: Java
January 28, 2000
Be Careful With Transient Data
Java's serialization provides an elegant, and easy to use mechanism for making an object's state persistent. While controlling object serialization, we might have a particular object data member that we do not want the serialization mechanism to save.

To turn off serialization on a certain field of an object, we tag that field of the class of our object with the Java's "transient" keyword. This, to low-level parts of the Java virtual machine, is an indication that the transient variable is not part of the persistent state of an object.

First, let's have some backgrounder code with Java's serialization.
Suppose we define a class as:

public class LoggingInfo implements java.io.Serializable
{
private Date loggingDate = new Date();
private String uid;
private transient String pwd;

LoggingInfo(String user, String password)
{
uid = user;
pwd = password;
}
public String toString()
{
String password=null;
if(pwd == null)
{
password = "NOT SET";
}
else
{
password = pwd;
}
return "logon info: "n " + "user: " + uid +
""n logging date : " + loggingDate.toString() +
""n password: " + password;
}
}
Now we can create an instance of this class and serialize it, and write the serialized object to disk as in:
LoggingInfo logInfo = new LoggingInfo("MIKE", "MECHANICS");
System.out.println(logInfo.toString());
try
{
ObjectOutputStream o = new ObjectOutputStream(
new FileOutputStream("logInfo.out"));
o.writeObject(logInfo);
o.close();
}
catch(Exception e) {//deal with exception}
To read the object back, we can write
try
{
ObjectInputStream in =new ObjectInputStream(
new FileInputStream("logInfo.out"));
LoggingInfo logInfo = (LoggingInfo)in.readObject();
System.out.println(logInfo.toString());
}
catch(Exception e) {//deal with exception}
If we run this code, we notice that the read-back object prints password as "NOT SET". This is exactly the effect we should have expected when we declared the pwd field as transient.

Now, let's see a potential problem that careless treatment of transient fields may cause. Suppose we modify our class definition and provide default values for the transient field, say we write:

public class GuestLoggingInfo implements java.io.Serializable
{
private Date loggingDate = new Date();
private String uid;
private transient String pwd;

GuestLoggingInfo()
{
uid = "guest";
pwd = "guest";
}
public String toString()
{
//same as above
}
}
Now, if we serialize an instance of GuestLoggingInfo, write it to disk, and read it back, we still see that the read-back object prints password as "NOT SET". In effect, the process of reading back (de-serializing) totally ignores the constructor of GuestLoggingInfo. So what happened?

The answer lies in the fact that the initialization code is not called because we are not initializing, in other words, we are not constructing a brand new object, but loading back the persistent state of an object of a class, and assigning that state to another object of the same class. Declaring the pwd field as transient, excludes the data for that


肖麦 2009-10-10 10:03 发表评论
]]>
Java中finally关键字的使用http://www.aygfsteel.com/merek/articles/189306.html肖麦肖麦Fri, 28 Mar 2008 08:59:00 GMThttp://www.aygfsteel.com/merek/articles/189306.htmlhttp://www.aygfsteel.com/merek/comments/189306.htmlhttp://www.aygfsteel.com/merek/articles/189306.html#Feedback0http://www.aygfsteel.com/merek/comments/commentRss/189306.htmlhttp://www.aygfsteel.com/merek/services/trackbacks/189306.html     与其他语a的模型相比,finally 关键字是?Java 异常处理模型的最佌充。finally l构使代码M执行Q而不有无异常发生。?finally 可以l护对象的内部状态,q可以清理非内存资源?如果没有 finallyQ?zhn)的代码就会很费解。例如,下面的代码说明,在不使用 finally 的情况下(zhn)必d何编写代码来释放非内存资源:

  import java.net.*;
  import java.io.*;

     class WithoutFinally
 {
       public void foo() throws IOException
  {
  //在Q一个空闲的端口上创Z个套接字
  ServerSocket ss = new ServerSocket(0);
  try
        {
        Socket socket = ss.accept();
        //此处的其他代?..
  }
  catch (IOException e)
       {
        ss.close();                                              //1
        throw e;
  }
  //...
  ss.close();                                                //2
  }
 }

 

  q段代码创徏了一个套接字Qƈ调用 accept Ҏ(gu)。在退Ҏ(gu)之前Q?zhn)必须关闭此套接字Q以避免资源漏洞。ؓ了完成这一dQ我们在 //2 处调?closeQ它是该Ҏ(gu)的最后一条语句。但是,如果 try 块中发生一个异怼怎么样呢Q在q种情况下,//2 处的 close 调用永远不会发生。因此,(zhn)必L莯个异常,q在重新发出q个异常之前?//1 处插入对 close 的另一个调用。这样就可以保在退Ҏ(gu)之前关闭套接字?/p>

 

 

 

  q样~写代码既麻烦又易于出错Q但在没?finally 的情况下q是必不可少的。不q的是,在没?finally 机制的语a中,E序员就可能忘记以这U方式组l他们的代码Q从而导致资源漏z。Java 中的 finally 子句解决了这个问题。有?finallyQ前面的代码可以重写ؓ以下的Ş式:

  import java.net.*;
  import java.io.*;

class WithFinally
{
 public void foo2() throws IOException
 {
  //在Q一个空闲的端口上创Z个套接字
  ServerSocket ss = new ServerSocket(0);
  try
        {
       Socket socket = ss.accept();
       //此处的其他代?..
  }
  finally
        {
        ss.close();
  }
 }
}

 

  finally 块确?close Ҏ(gu)总被执行Q而不?try 块内是否发出异常。因此,可以保在退Ҏ(gu)之前M调用 close Ҏ(gu)。这h可以确信套接字被关闭ƈ且?zhn)没有泄漏资源。在此方法中不需要再有一?catch 块。在W一个示例中提供 catch 块只是ؓ了关闭套接字Q现在这是通过 finally 关闭的。如果?zhn)实提供了一?catch 块,?finally 块中的代码在 catch 块完成以后执行?/p>

  finally 块必M try ?try/catch 块配合用。此外,不可能退?try 块而不执行?finally 块。如?finally 块存在,则它M执行。(无论从那点看Q这个陈q都是正的。有一U方法可以退?try 块而不执行 finally 块。如果代码在 try 内部执行一?System.exit(0); 语句Q则应用E序l止而不会执?finally 执行。另一斚wQ如果?zhn)?try 块执行期间拨掉电(sh)源,finally 也不会执行。)



肖麦 2008-03-28 16:59 发表评论
]]>
Java?异常机制"的深入研I?http://www.aygfsteel.com/merek/articles/188931.html肖麦肖麦Thu, 27 Mar 2008 01:31:00 GMThttp://www.aygfsteel.com/merek/articles/188931.htmlhttp://www.aygfsteel.com/merek/comments/188931.htmlhttp://www.aygfsteel.com/merek/articles/188931.html#Feedback0http://www.aygfsteel.com/merek/comments/commentRss/188931.htmlhttp://www.aygfsteel.com/merek/services/trackbacks/188931.htmlJava?异常机制"的深入研I?转蝲)

  作者:陈健?发文旉Q?004.03.10

  ׃本文旨在探讨Java"异常机制"的深层原理,因此关于"异常"的用方法都不做详细说明。首先看一D非常熟(zhn)的用于打开一个文件的CE序D:

  FILE *fp;

  fp=fopen(filename,"rw");

  if(fp==NULL){

  printf("cannot open file\n");

  exit(0);

  }

  在这D늨序中Qif条g语句中的一D는来处理没有找到指定文Ӟ或者其它原因无法正打开指定文g。可是如果遇C个责d不强的程序员Q他可能认ؓ出现找不到文件的可能性很,或者由于思\集中在程序功能的实现上而忘C处理q种情况。这时程序同样可以正编译,而且一般情况下也不会出现问题。但此时q段E序可以肯定说是不够健壮的,而且一旦这D늨序发生了错误也会让程序员很难发现错误出在哪里。在C语言以及其它大多数高U语a中都可以丑և很多q种例子?/p>

  也就是一个函数在使用的时候,可能会出现ƈ没有辑ֈq个函数的用目的的情况Q哪怕在q段E序的特定用环境下发生q种异常情况的可能性只有万分之一。常用处理的Ҏ(gu)是Q程序员在需要用某个函数时必须充分了解可能会有什么原因导致该函数不能正确执行Q然后加入相应的条g判断语句来进行处理。后面将有一个例子说明这个问题?/p>

  而Java?异常机制"是在处理上q问题中l了E序员非常简单而灵zȝ方式。一般来_其它高语言主要是让函数使用者来x该函数可能会出现的异常情况,而java则是把这件事情交l方?和函数对应的概念Q在Java中称Ҏ(gu))的设计者来做。这对于Ҏ(gu)的用者来说带来的方便是不会因d不强Q或者办事丢三那四,会忘了在使用Ҏ(gu)时处理可能发生的异常情况。而麻烦就是,在用一个可能会发生异常的方法时Q绝对不能视而不见,而必d出相应的处理。也是说象上述CE序D中Q如果忘了ifE序块,q个E序甚至q能蒙过一个外行上司,但当使用Java来完成这个功能时Q只要用到的Ҏ(gu)使用?异常"机制Q如果不对可能?异常"的方法进行相应处理,java~译器是不会让其通过的?/p>

  一?异常c?的组lŞ?/strong>

  JavapȝcM的方法生的异常都被l织?异常c?Q还有Errorc,不在本文讨论范围Q,此方法和它相关的"异常c?通过throws关键字关联在一Pq且q些c都必须是Exceptioncȝ子类。Q何一个自己开发的cȝҎ(gu)中如果可能会产生某种异常Q也可以这U异常组l成一?异常c?Q但q个"异常c?同样必须是Exception的子c,或孙子类{等?/p>

  ?Q?/p>

  /*isLegal于检查数据是否合法,?gt;0时视为合法,q回合法|

  *否则视ؓ不合法,抛出"异常"?/

  int isLegal(int dt) throws LowZeroException//q种定义本文中均UCؓҎ(gu)?异常"?/p>

  {  //qthrows建立了关?/p>

   if(dt>=0){

   return data;

   }

   else

   throw new LowZeroException();

  }

  /*自已写的异常c,l承自Exception*/

  class LowZeroException extends Exception

  {

   public LowZeroException(){

   super();

   }

  }

  仔细观察Ҏ(gu)isLegal()Q它体现出的最值得注意的特色是Q它有两U方式的函数出口Q一U是通过return语句Q返回的是方法本w定义的cd的实例,另一U是通过throwQ返回的?异常c?的对象实例,Java中称之ؓ抛出"异常"。对比一下C中如何处理同L问题的:

  int isLegal(int dt) {

   if(dt>=0){

   return data;

   }

   else

   return -1;//通过一个特定值来表明出错

  }

  ׃C只能通过returnq回函数|所以在处理异常情况时则可能通过以上方式来处理。当然这p求isLegal()函数的用者必ȝ道函C使用q回?1来表明出C合法数据的情c?/p>

  Ҏ(gu)q两U处理方法,可以知道java?异常机制"把处理异怺件的职能和方法本w的职能通过两个不同出口分离开来?/p>

  所有这?异常c?独立于它具体服务的方法被l一l织成一个类树?异常机制"好比高校的后勤C会化一P通过后勤C会化将学校的教学职能和学校的后勤保障分d来,q且后勤集团的组lŞ式也是独立于学校M的。事实证明,q种l织方式不仅提高了服务效率,也提高了服务质量。整个Java体系中的"异常c?l织形式如图1所C:

  

  在例1中的isLegal()Ҏ(gu)如果在调用过E中没有能正常返回整形数Q而是?异常"产生点生了"异常"对象Q那么这?异常"对象p来接Ӟq处理它呢?以下来解答q个问题?/p>

  二?异常"的处理过E?/strong>

  Java中由try…catch语法来处?异常"Q将兌?异常c?的方法包含在try{}E序块中Qcatch(){}关键字可以用Ş参,用于和方法生的"异常"对象l合。当调用某个Ҏ(gu)Ӟ引v异常事g发生的条件成立,便会抛出"异常"Q原来的E序程会在此Ҏ(gu)处中断,然后try模块后紧跟的catch中的"形参"和此异常对象完成了结合,l而进入了catch模块中运行。具体过ED例说明:

  ?Q?/p>

  /*关联有异常的方法包含在try模块?/

  int myMethod(int dt){

  int data = 0;

  try{

   int data = isLegal(dt);

  }catch(LowZeroException e){

   System.out.println("发生数据错误Q?);

  }

   return data;

   }

  三?异常"的处理方?/strong>

  有两U方法处?异常"Q第一U如?Q将含有"异常"出口的方法直接放到try块中Q然后由紧随其后的catch块捕捉。第二种是不直接监听捕捉被引用方法的"异常"Q而是这?异常"兌传递给引用Ҏ(gu)Q同时监听捕捉工作也相应向上传递?/p>

  ?Q?/p>

  int myMethod2(int dt)

  {

   int data = 0;

  try{

   data = myMethod(dt)

   }catch(LowZeroException e){

   System.out.println("发生数据错误Q?);

   e.printStackTrace();

   }

   return data;

  }

  int myMethod(int dt) throws LowZeroException

  {

   int data = isLegal(dt); //此处引用isLegal()Ҏ(gu)Q但q没有捕捉它?异常"

  return data;

  }

  从上例中可以看到Ҏ(gu)myMethod()与它引用的方法isLegal()产生?异常"LowZeroException建立了关联,也就是完成了?异常"兌的向上传递,此时的myMethod()Ҏ(gu)体中虽然只有一个returnq回语句Q但它事实上同样有两U方式的函数出口Q一U是由returnq回的整形|另一U则是返回方法名中的throws关键字所指的"异常c?的实例对象。相应的Q监听捕捉的工作交给了上一层方法myMethod2()。同L道理QmyMethod2()也可以将"异常"通过throws的关联l向上传递。这L话,一旦一?异常"被捕捉到Ӟq个"异常"必有一个传递\径,而如果我们在捕捉点的catchE序块中加入printStackTrace()Ҏ(gu)Q便能清楚的看到q个"异常"是怎样传递过来的。例如在?如果?异常"被捕捉到Qe.printStackTrace()打印出来的结果将是:

  LowZeroException:

  at Example.isLegal

  at Example myMethod

  at Example.myMethod2

  at Example main

  从上l果中我们可以看刎ͼ从LowZeroException"异常"产生点,卛_含throw new LowZeroException();子句的方法开始,然后一直追溯到产生当前U程的方法(注意QprintStackTrace()q不是追溯到捕捉点结束,而是C生当前线E的Ҏ(gu)l束Q?异常"产生点生的LowZeroException"异常"对象Q首先被赋给了isLegal()兌的LowZeroExceptioncȝ无名引用Q然后l赋lmyMethod()兌的LowZeroExceptioncȝ无名引用Q再l箋赋给myMethod2()中的catch块中的Ş参eQ最后在q里被处理掉Q这?异常"对象随即消失。可以说Qcatch(){}是"异常"对象的生命终l点?/p>

  另外q要注意一点,Ҏ(gu)?异常"的关联可以一直向上传递,当传递到与mainҎ(gu)兌后,卛_main()Ҏ(gu)的定义中使用了throws ExceptionQ这旉了虚拟机没有其它Ҏ(gu)能够引用main()Ҏ(gu)Q且在程序中可能看不到try…catchE序块,但ƈ不会产生错误Q因为此时虚拟机会捕?异常"Qƈ且会默认的调用printStackTrace()Ҏ(gu)打印?异常"路径。M只要一个方法关联了"异常"Q可以将q个"异常"兌向上传递,但是最l必M用catch来终?异常"Q或者一直传递到main()Ҏ(gu)交给Java虚拟机来l束"异常"对象的生命,否则是通不q编译的?/p>

  四、?异常机制"的需要注意的几点

  1.一个方法中可能会生多U不同的异常Q你可以讄多个"异常"抛出Ҏ(gu)解决q个问题?/p>

  2."异常"对象从生点产生后,到被捕捉后终止生命的全过E中Q实际上是一个传DE,所以你可以Ҏ(gu)需要,来合理的控制到"异常"的粒度。例如在?中,如果你ƈ不需要知道具体生的是LowZeroException"异常"Q那么你可以使用"异常"的公qcException来结?异常"对象Q即catch(Exception e){…}。同样在"异常"与方法关联的传递过E中Q也可以Ҏ(gu)需要控制关?异常"的粒度,即throws后面跟上异常对象的父cd?/p>

  3."异常机制"中还有一U特D情况――RuntimeException"异常c?Q见?Q,q个"异常c?和它的所有子c都有一个特性,是"异常"对象一产生pJava虚拟机直接处理掉Q即在方法中出现throw 子句的地方便被虚拟机捕捉了。因此凡是抛U?q行时异?的方法在被引用时Q不需要有try…catch语句来处?异常"?/p>

肖麦 2008-03-27 09:31 发表评论
]]>
java 日期格式?转蝲)http://www.aygfsteel.com/merek/articles/122404.html肖麦肖麦Wed, 06 Jun 2007 08:47:00 GMThttp://www.aygfsteel.com/merek/articles/122404.htmlhttp://www.aygfsteel.com/merek/comments/122404.htmlhttp://www.aygfsteel.com/merek/articles/122404.html#Feedback0http://www.aygfsteel.com/merek/comments/commentRss/122404.htmlhttp://www.aygfsteel.com/merek/services/trackbacks/122404.htmljava 日期格式?br>import java.util.Date;
import java.text.DateFormat;


/**
 * 格式化时间类
 * DateFormat.FULL = 0
 * DateFormat.DEFAULT = 2
 * DateFormat.LONG = 1
 * DateFormat.MEDIUM = 2
 * DateFormat.SHORT = 3
 * @author    Michael
 * @version   1.0Q?2007/03/09
 */

public class Test{
    public static void main(String []args){
        Date d = new Date();
        String s;
         
        /** Datecȝ格式: Sat Apr 16 13:17:29 CST 2006 */
        System.out.println(d);
         
        System.out.println("******************************************");  
       
        /** getDateInstance() */
        /** 输出格式: 2006-4-16 */
        s = DateFormat.getDateInstance().format(d);
        System.out.println(s);
       
        /** 输出格式: 2006-4-16 */
        s = DateFormat.getDateInstance(DateFormat.DEFAULT).format(d);
        System.out.println(s);
       
        /** 输出格式: 2006q??6?星期?*/
        s = DateFormat.getDateInstance(DateFormat.FULL).format(d);
        System.out.println(s);
       
        /** 输出格式: 2006-4-16 */
        s = DateFormat.getDateInstance(DateFormat.MEDIUM).format(d);
        System.out.println(s);
       
        /** 输出格式: 06-4-16 */
        s = DateFormat.getDateInstance(DateFormat.SHORT).format(d);
        System.out.println(s);
       
        /** 输出格式: 2006-01-01 00:00:00 */
        java.text.DateFormat format1 = new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        s = format1.format(new Date());
        System.out.println(s);
       
        /** 输出格式: 2006-01-01 00:00:00 */
        System.out.println((new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss")).format(new Date()));
       
        /** 输出格式: 20060101000000***/
        java.text.DateFormat format2 = new java.text.SimpleDateFormat("yyyyMMddhhmmss");
        s = format2.format(new Date());
        System.out.println(s); 
    }
}       
 




肖麦 2007-06-06 16:47 发表评论
]]>
java文g操作(一)http://www.aygfsteel.com/merek/articles/108649.html肖麦肖麦Thu, 05 Apr 2007 03:16:00 GMThttp://www.aygfsteel.com/merek/articles/108649.htmlhttp://www.aygfsteel.com/merek/comments/108649.htmlhttp://www.aygfsteel.com/merek/articles/108649.html#Feedback0http://www.aygfsteel.com/merek/comments/commentRss/108649.htmlhttp://www.aygfsteel.com/merek/services/trackbacks/108649.html1、流式输入与输出

行数据的输入、输出操作,Java中把不同的输入、输出源Q键盘、文件、网l连接等Q抽象ؓ“?#8221;QStreamQ,有两U基本的:输入和输出?/p>

Q?Q输入流Q只能从中读取数据,而不能向其写出数据?/p>

Q?Q输出流Q只能向其写出数据,而不能从中读取数据?/p>

实际上指在计算机的输入与输Z间运动的数据的序列,序列中的数据既可以是未l加工的原始二进制数据,也可以是l一定编码处理后W合某种格式规定的特定数据,如字W流序列、数字流序列{?/p>

1.1、字节流与字W流

按处理数据的cdQ流可以分ؓ字节和字符,它们处理的信息的基本单位分别是字节(byteQ与字符QcharQ?/p>

输入字节的cMؓInputStream

输出字节的cMؓOutputStream

输入字符的cMؓReader

输出字符的cMؓWriter

如下表,q四个类是抽象类Q其他的输入输出类都是它们的子cR?/p>

字节与字符?/p>

 

字节?/p>

字符?/p>

输入

InputStream

Reader

输出

OutputStream

Writer


 InputStreamc?br> 
Ҏ(gu)摘要
 int available()
          q回此输入流Ҏ(gu)的下一个调用方可以不受dC此输入流dQ或跌Q的字节数?/td>
 void close()
          关闭此输入流q放与该流兌的所有系l资源?/td>
 void mark(int readlimit)
          在此输入中标记当前的位|?/td>
 boolean markSupported()
          试此输入流是否支持 mark ?reset Ҏ(gu)?/td>
abstract  int read()
          从输入流d下一个数据字节?/td>
 int read(byte[] b)
          从输入流中读取一定数量的字节q将其存储在~冲区数l?b 中,以整数Ş式返回实际读取的字节数?/td>
 int read(byte[] b, int off, int len)
          输入流中最?len 个数据字节读入字节数l,读取的W一个字节存储在元素 b[off] 中,下一个存储在 b[off+1] 中,依次cL。读取的字节数最多等?len?/td>
 void reset()
          此重新定位到Ҏ(gu)输入最后调?mark Ҏ(gu)时的位置?/td>
 long skip(long n)
          跌和放弃此输入中?n 个数据字节?/td>
 

W一个readQ)Ҏ(gu)从输入流的当前位|处d一个字节(8位)的二q制数据Q然后以此数据ؓ低位字节Q配上一个全零字节合成ؓ一?6位的整型量(0~255)后返回给调用此方法的语句。如果输入流的当前位|没有数据,则返?1?

OutputStreamc?br>此抽象类是表C出字节流的所有类的超cR输出流接受输出字节q将q些字节发送到某个接收器?br>
Ҏ(gu)摘要
 void close()
          关闭此输出流q放与此流有关的所有系l资源?/td>
 void flush()
          h此输出流q强制写出所有缓冲的输出字节?/td>
 void write(byte[] b)
          ?b.length 个字节从指定的字节数l写入此输出?/td>
 void write(byte[] b, int off, int len)
          指定字节数l中从偏U量 off 开始的 len 个字节写入此输出?/td>
abstract  void write(int b)
          指定的字节写入此输出流?/td>
public abstract void write(int b) throws Ҏ(gu)摘要 abstract  void close()
          关闭该流?/td>  void mark(int readAheadLimit)
          标记中的当前位|?/td>  boolean markSupported()
          判断此流是否支持 mark() 操作?/td>  int read()
          d单个字符?/td>  int read(char[] cbuf)
          字W读入数l?/td> abstract  int read(char[] cbuf, int off, int len)
          字W读入数l的某一部分?/td>  int read( boolean ready()
          判断是否准备d此流?/td>  void reset()
          重置该流?/td>  long skip(long n)
          跌字符?/td>   Writer c?br> 
Ҏ(gu)摘要
  CharSequence csq)
          指定字W序列追加到?writer?/td>
 append(CharSequence csq, int start, int end)
          指定字W序列的子序列追加到?writer.Appendable?/td>
abstract  void close()
          关闭此流Q但要先h它?/td>
abstract  void flush()
          h此流?/td>
 void write(char[] cbuf)
          写入字符数组?/td>
abstract  void write(char[] cbuf, int off, int len)
          写入字符数组的某一部分?/td>
 void write(int c)
          写入单个字符?/td>
 void write( void write(
节点cd 节点?/td> 字符?/td>
File文g

FileInputStream

FileOutputStream

FileReader

FileWriter

Memory Array内存数组

ByteArrayInputStream

ByteArrayOutputStream

CharArrayReader

CharArrayWriter

Memory String字符?/td>

StringReader

StringWriter

Pipe道

PipedInputStream

PipedOutputStream

PipedReader

PipedWriter


常用的处理流
处理cd 字节?/td> 字符?/td>
Buffering~冲

BufferedInputStream

BufferedOutputStream

BufferedReader

BufferedWriter

Filteringqo

FilterInputStream

FilterOutputStream

FilterReader

FilterWirter

Converting between bytes and character

字节{为字W流

InputStreamReader

OutputStreamWriter

Object Serialization

对象序列?/p>

ObjectInputStream

ObjectOutputStream

Date coversion

基本数据cd转化

DateInputStream

DateOutputStream

Counting行号处理

LineNumberInputStream LineNumberReader

Peeking ahead可回退?/p>

PushBackInputStream PushbackReader
Pinting可显C处?/td> PrintStream PrintWriter
        基本输入、输出流是定义基本的输入、输出操作的抽象c,在JavaE序中真正实用的是它们的子类Q对应于不同的数据源和输入、输ZQ务,以及不同的输入、输出流。其中较常用的有Q过滤输入、输出流FilterInputStream和FilterOutputStream两个抽象c,又分别派生出DataInputStreamQDataOutputStream{子cR过滤输入、输出流的主要特Ҏ(gu)在输入、输出数据的同时能对所传输的数据做指定cd或格式的转换Q即可实现对二进制字节数据的理解和编码{换。文件输入、输出流FileInputStream和FileOutputStream主要负责完成Ҏ(gu)地磁盘文件的序d操作。管道输入、输出流PipedInputStream和PipedOutputStream负责实现E序内部的线E间通信或不同程序间通信。字节数l流ByteArrayInputStream和ByteArrayOutputStream可实C内存~冲区的同步d。顺序输入流SequenceInputStream可以把两个其他的输入首接,合ƈ成一个完整的输入,{等?br>       从抽象类Reader和Writer中也zZ些子c,q些子类使InputStream和OutputStream的以字节为单位输入、输{换ؓ以字Wؓ单位输入、输出,使用h比InputStream和OutputStream要方便很多?br>       数据输入、输出流DataInputStream和DataOutputStream分别是过滤输入、输出流FilterInputStream和FilterOutputStream的子cR过滤输入、输出流的最主要作用是在数据源和程序之间加一个过滤处理步骤,对原始数据做特定的加工、处理和变换操作?br>
标准输入和标准输?/strong>
         当javaE序需要与外界数据源做输入、输出的数据交换Ӟ它需要首先创Z个输入或输出cȝ对象来完成对q个数据源的q接。例如,当javaE序需要读写文件时Q它需要先创徏文g的输入或文g输出类的对象。除文g外,E序也经怋用字W界面的标准输入、输备进行读写操作?br>         计算机系l都有默认的标准输入讑֤和标准输备。对一般的pȝQ标准输入通常是键盘,标准输出通常是显C器屏幕。JavaE序使用字符界面与系l标准输入、输出间q行数据通信Q即从键盘读入数据,或向屏幕输出数据Q是十分常见的操作,为此而频频创入、输出流cd象将很不方便。ؓ此javapȝ事先定义好两个流对象Q分别与pȝ的标准输入和标准输出相联p,它们是System.in和System.out


肖麦 2007-04-05 11:16 发表评论
]]>
java.util包学习(二)集合框架Q接口)http://www.aygfsteel.com/merek/articles/106891.html肖麦肖麦Wed, 28 Mar 2007 02:54:00 GMThttp://www.aygfsteel.com/merek/articles/106891.htmlhttp://www.aygfsteel.com/merek/comments/106891.htmlhttp://www.aygfsteel.com/merek/articles/106891.html#Feedback0http://www.aygfsteel.com/merek/comments/commentRss/106891.htmlhttp://www.aygfsteel.com/merek/services/trackbacks/106891.html 集合框架的设计目?br />Q?Q基本集合(动态数l、链表、树、和散列表)的实现具有很高的效率
Q?Q这个框架必d怸同类型的集合用相似的方式q行处理且具有很高的互用?br />Q?Q扩展与修改集合必须是容易的.Z实现q一目标,整个集合框架被设计成一pd的标准接?q且实用工具包中提供了这些接口的几个标准实现,如LinkedList、HashSet和TreeSet?br />Q?Q允许程序员把标准数l集成到集合l构中的机制
集合框架的IteratorQP代器Q接口:
Iterator提供了访问集合元素的一U标准访问方式:逐个讉K方式。由于每个集合均实现Iterator接口Q所以Q何集合类的成员均可通过IteratorcȝҎ(gu)讉K
集合框架的接口:
下面介l集合框架的每个接口。首先从集合接口开始,因ؓ它们军_集合cȝ基本Ҏ(gu)?/p>
  • Collection          允许处理一l对象,位于集合分层l构的顶?
  • List                    扩展Collection接口来处理序列(卛_象序列)
  • Set                    扩展Collection接口来处理对象集Q其中集合元素必L惟一?
  • SortedSet          扩展Set接口来处理已排序的对象集

除了Collection外,集合中还有Comparator、Iterator、ListIterator和RandomAccess接口?br />Comparator定义怎样比较两个对象QIterator和ListIterator列D集合中的对象Q而通过实现RandomAccessQ列表允许对其元素进行有效的随机讉K?br />
Collection接口Q?/strong>
Collection接口是构造集合框架的基础Qƈ声明了各U集合所共有的核心方法。JDK 不提供此接口的Q?i>直接 实现Q它提供更具体的子接口(?Set ?ListQ实现?br />Collection接口中的Ҏ(gu)Q?br />

Method Summary
 boolean add (E o)
          Ensures that this collection contains the specified element (optional operation).
 boolean addAll (Collection<? extends E> c)
          Adds all of the elements in the specified collection to this collection (optional operation).
 void clear ()
          Removes all of the elements from this collection (optional operation).
 boolean contains (Object o)
          Returns true if this collection contains the specified element.
 boolean containsAll (Collection<?> c)
          Returns true if this collection contains all of the elements in the specified collection.
 boolean equals (Object o)
          Compares the specified object with this collection for equality.
 int hashCode ()
          Returns the hash code value for this collection.
 boolean isEmpty ()
          Returns true if this collection contains no elements.
 Iterator<E> iterator ()
          Returns an iterator over the elements in this collection.
 boolean remove (Object o)
          Removes a single instance of the specified element from this collection, if it is present (optional operation).
 boolean removeAll (Collection<?> c)
          Removes all this collection's elements that are also contained in the specified collection (optional operation).
 boolean retainAll (Collection<?> c)
          Retains only the elements in this collection that are contained in the specified collection (optional operation).
 int size ()
          Returns the number of elements in this collection.
 Object[] toArray ()
          Returns an array containing all of the elements in this collection.
<T> T[]
toArray (T[] a)
          Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array.
 
List接口
List接口扩展了Collection接口。用从0开始的索引Q可以把一个元素插入到列表中或讉K列表中的某个元素。除了Collection接口中所定义的方法外QList接口q定义了属于它自q一些方法。如下图Q?br />
Method Summary
 booleanadd(E o)
          Appends the specified element to the end of this list (optional operation).
 voidadd(int index, E element)
          Inserts the specified element at the specified position in this list (optional operation).
 booleanaddAll(Collection<? extends E> c)
          Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation).
 booleanaddAll(int index, Collection<? extends E> c)
          Inserts all of the elements in the specified collection into this list at the specified position (optional operation).
 voidclear()
          Removes all of the elements from this list (optional operation).
 booleancontains(Object o)
          Returns true if this list contains the specified element.
 booleancontainsAll(Collection<?> c)
          Returns true if this list contains all of the elements of the specified collection.
 booleanequals(Object o)
          Compares the specified object with this list for equality.
 Eget(int index)
          Returns the element at the specified position in this list.
 inthashCode()
          Returns the hash code value for this list.
 intindexOf(Object o)
          Returns the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element.
 booleanisEmpty()
          Returns true if this list contains no elements.
 Iterator<E>iterator()
          Returns an iterator over the elements in this list in proper sequence.
 intlastIndexOf(Object o)
          Returns the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element.
 ListIterator<E>listIterator()
          Returns a list iterator of the elements in this list (in proper sequence).
 ListIterator<E>listIterator(int index)
          Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list.
 Eremove(int index)
          Removes the element at the specified position in this list (optional operation).
 booleanremove(Object o)
          Removes the first occurrence in this list of the specified element (optional operation).
 booleanremoveAll(Collection<?> c)
          Removes from this list all the elements that are contained in the specified collection (optional operation).
 booleanretainAll(Collection<?> c)
          Retains only the elements in this list that are contained in the specified collection (optional operation).
 Eset(int index, E element)
          Replaces the element at the specified position in this list with the specified element (optional operation).
 intsize()
          Returns the number of elements in this list.
 List<E>subList(int fromIndex, int toIndex)
          Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.
 Object[]toArray()
          Returns an array containing all of the elements in this list in proper sequence.
<T> T[]
toArray(T[] a)
          Returns an array containing all of the elements in this list in proper sequence; the runtime type of the returned array is that of the specified array.
 
Set接口
Set接口扩展Set接口q定义这样一U集合:q种集合不允许含有相同的元素。因此,如果试图插入相同的元素到调用集合中,add()会q回false。Set接口没有定义它自qҎ(gu)。所有方法都l承自Collection接口?br />Sorted接口
SortedSet接口扩展Collection接口q定义一U升序集合。除了Set接口所定义的方法之外,SortedSet接口q定义了表所l出的方法,以便集合的操作变得更为方ѝ?br />
Method Summary
 Comparator<? super E>comparator()
          Returns the comparator associated with this sorted set, or null if it uses its elements' natural ordering.
 Efirst()
          Returns the first (lowest) element currently in this sorted set.
 SortedSet<E>headSet(E toElement)
          Returns a view of the portion of this sorted set whose elements are strictly less than toElement.
 Elast()
          Returns the last (highest) element currently in this sorted set.
 SortedSet<E>subSet(E fromElement, E toElement)
          Returns a view of the portion of this sorted set whose elements range from fromElement, inclusive, to toElement, exclusive.
 SortedSet<E>tailSet(E fromElement)
          Returns a view of the portion of this sorted set whose elements are greater than or equal to fromElement.
 

肖麦 2007-03-28 10:54 发表评论
]]>
java.util包学习(一Q类与接口结构图http://www.aygfsteel.com/merek/articles/106865.html肖麦肖麦Wed, 28 Mar 2007 02:01:00 GMThttp://www.aygfsteel.com/merek/articles/106865.htmlhttp://www.aygfsteel.com/merek/comments/106865.htmlhttp://www.aygfsteel.com/merek/articles/106865.html#Feedback0http://www.aygfsteel.com/merek/comments/commentRss/106865.htmlhttp://www.aygfsteel.com/merek/services/trackbacks/106865.html 实用工具包中的接口:

实用工具包中的类



肖麦 2007-03-28 10:01 发表评论
]]>
վ֩ģ壺 | | ˮ| | | ͩ| ֿ| | | | | ֦| ղ| ¹| ʶ| ˮ| | û| | | | | ԫ| ľ| | | ʻ| | | ̽| | | | | | ̨| | | | Ӫ| Ϸ|