琦 さんのプロフィール花未全开,月未满フォトブログリスト ツール ヘルプ
10月9日

居然不可以加自己写的东东,郁闷.

无聊,居然不可以加自己写的script.郁闷死了!!!
9月27日

大家现在都这么兴写BLOG,我也重新写写MSN SPACE吧

      Web 2.0记的去年还是个比较新的概念,今年BLOG已经这么流行.人人写,日日写.不过没有流行聊天软件的支持,能火多久呐.毕竟大部分人都是写来给朋友看的.只有名人和刁民的BLOG才会在意访问量.当大家都在疯狂的在各大网站注册BLOG空间的时候,大把的钞票进入了这些人的兜兜里,不过无可厚非,毕竟天下没有真正免费的午餐.那些没有通过BLOG出名或挣到钱的朋友也不用总是大放厥词的呼吁抵制广告,要求各大门户网站还WEB 2.0一片净土.相比各大网站的BLOG SITE,还是喜欢MSN SPACE,毕竟可以最快的让自己的朋友看到自己写的东东,也没那么多广告的骚扰.MSN.com把所有的产品整合的不错,Messager,Live search,Live Space之间的互动,协作都很好,但不知道为什么总是火不起来.好象所有的国外公司,在中国互联网的领域都有些水土不服.MSN的命运好象也是一样.不温不火.
      反正是重新开始写,也不知道该写什么.哈哈.就写到这里.
 
9月16日

有人说MSN space不能用了,我来实验一下!

有人说MSN space不能用了,我来实验一下!
7月18日

新封装的一个访问数据库的类,不过很简陋!!!

package datas;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class conDate {
 private Connection conn;
 private Statement stmt;
 private ResultSet rs;
 
 public static String sqlServer = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
 
 conDate(String jdbcNames,String urls,String users,String passwords) throws ClassNotFoundException, SQLException
 {
  Class.forName(jdbcNames);
  String url=urls;
  String user=users;
  String password=passwords;
  conn= DriverManager.getConnection(url,user,password);
  stmt= conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
 }
 
 public ResultSet executeDate(String sql) throws SQLException
 {
  rs = stmt.executeQuery(sql);
  return rs;
 }
 
 public int UpdateDate(String sql) throws SQLException
 {
  return stmt.executeUpdate(sql);
 }
 
 public int[] BatchDate(String sql) throws SQLException
 {
  return stmt.executeBatch();
 }
 
 
 
 public void closeDate() throws SQLException
 {
  rs.close();
  stmt.close();
  conn.close();
 }
}
6月17日

鄙视人妖老师!!!

今天准备完了JAVA考试的复习,最后发现居然编程题需要写两百多行代码,放到WORD里要五张纸才能放的下,我彻底晕到了.天呀,笔试居然出这种题.考试就一个半小时,TMD什么都不干了就写这点东西估计就要一个小时多吧.可怜死了.
5月11日

今天写的一个作业,Stream的缓冲区还是需要注意的.

如果把flush()和print()函数位置调换,会得到不同的结果,更好的说明了Stream的工作机制.当我们输出时,并不是直接输出,而是要先输出到STREAM的缓冲区里,然后由flush()帮我们输出.而println()等三个函数在我们创建流时,如果选择了autoflush,在遇到"/n","/r"时自动调用flush(),输出数据.
 
package TestAboutJava;
import java.io.*;
public class Doctor {
 void talk(InputStream in,OutputStream out) throws IOException{
  System.out.println("Hello");
  PrintWriter outs = new PrintWriter(
    out,true);
  while(true){
   BufferedReader ins = new BufferedReader(
     new InputStreamReader(in));
   String q = ins.readLine();
   
   reply(outs,q);
  }
 }
 
 void reply(PrintWriter out,String q){
  out.println(q);
   
 }
 public static void main(String[] args) throws IOException{
  Doctor dr = new Doctor();
  dr.talk(System.in,System.out);
 }
}

在看java.nio这个包,发现了一篇不错的教学文章.

 
在看java.nio这个包,看了看Thinking in java里的讲解,感觉不太清楚,读起来很糊涂.后来发现了这篇文章,真的不错,呵呵.供大家参考.
4月23日

使用类字面常量完成上一个例子

用类字面常量代替了"Class.forName()"方法,减少了关于异常的判断.使程序看起来个清晰和简单.而类字面常量系统会自动判断它是类还是接口.是属于Run-Time Execption.不需要程序员自行处理.
 
package Path10;
import java.util.*;
public class PetCount2 {
 private static Random rand = new Random();
 public static void main(String[] args) {
  Object[] pets = new Object[15];
  Class[] petTypes = {
     Pet.class,
     Dog.class,
     Pug.class,
     Cat.class,
     Rodent.class,
     Gerbil.class,
     Hamster.class,
       };
  try{
   for(int i = 0; i<pets.length; i++){
    int rnd = 1 + rand.nextInt(petTypes.length - 1);
    pets[i] = petTypes[rnd].newInstance();
   }
  }
  catch(InstantiationException a){
   System.out.println("Cannot instantiate");
   System.exit(1);
  }
  catch(IllegalAccessException a){
   System.out.println("Cannot Access");
   System.exit(1);
  }
  
  
  AssociativeArray map = new AssociativeArray(petTypes.length);
  
  for(int i = 0; i < petTypes.length; i++){
   map.put(petTypes[i].toString(),new Counter());
  }
  
  for(int i = 0;i<pets.length;i++){
   Object o = pets[i];
   if(o instanceof Pet)
    ((Counter)map.get("class Path10.Pet")).i++;
   if(o instanceof Dog)
    ((Counter)map.get("class Path10.Dog")).i++;
   if(o instanceof Pug)
    ((Counter)map.get("class Path10.Pug")).i++;
   if(o instanceof Cat)
    ((Counter)map.get("class Path10.Cat")).i++;
   if(o instanceof Rodent)
    ((Counter)map.get("class Path10.Rodent")).i++;
   if(o instanceof Gerbil)
    ((Counter)map.get("class Path10.Gerbil")).i++;
   if(o instanceof Hamster)
    ((Counter)map.get("class Path10.Hamster")).i++;
  }
  
  for(int i = 0;i<pets.length;i++){
   System.out.println(pets[i].getClass());
  }
  System.out.println(map);
 }
}
4月22日

利用上次的简单数据类型,实现一个RTTI的例子

package Path10;
import java.util.*;
public class PetCount {
 private static Random rand = new Random();
 
 static String[] typenames = {
  "Pet","Dog","Pug","Cat",
  "Rodent","Gerbil","Hamster",
  };
 
 public static void main(String[] args) {
  Object[] pets = new Object[15];
  try{
   Class[] petTypes = {
     Class.forName("Path10.Dog"),
     Class.forName("Path10.Pug"),
     Class.forName("Path10.Cat"),
     Class.forName("Path10.Rodent"),
     Class.forName("Path10.Gerbil"),
     Class.forName("Path10.Hamster"),
   };
   for(int i = 0; i<pets.length; i++){
    pets[i] = petTypes[rand.nextInt(petTypes.length)].newInstance();
   }
  }
  catch(InstantiationException a){
   System.out.println("Cannot instantiate");
   System.exit(1);
  }
  catch(IllegalAccessException a){
   System.out.println("Cannot Access");
   System.exit(1);
  }
  catch(ClassNotFoundException a){
   System.out.println("Cannot find Class");
   System.exit(1);
  }
  
  
  AssociativeArray map = new AssociativeArray(typenames.length);
  
  for(int i = 0; i < typenames.length; i++){
   map.put(typenames[i],new Counter());
  }
  
  for(int i = 0;i<pets.length;i++){
   Object o = pets[i];
   if(o instanceof Pet)
    ((Counter)map.get("Pet")).i++;
   if(o instanceof Dog)
    ((Counter)map.get("Dog")).i++;
   if(o instanceof Pug)
    ((Counter)map.get("Pug")).i++;
   if(o instanceof Cat)
    ((Counter)map.get("Cat")).i++;
   if(o instanceof Rodent)
    ((Counter)map.get("Rodent")).i++;
   if(o instanceof Gerbil)
    ((Counter)map.get("Gerbil")).i++;
   if(o instanceof Hamster)
    ((Counter)map.get("Hamster")).i++;
  }
  
  for(int i = 0;i<pets.length;i++){
   System.out.println(pets[i].getClass());
  }
  System.out.println(map);
 }
}
4月21日

一个简单的数据结构

package Path10;
public class AssociativeArray {
 
 private Object[][]pairs;
 
 private int index;
 
 public AssociativeArray(int length){
  pairs = new Object[length][2];
 }
 
 public void put(Object key,Object value){
  if(index >= pairs.length)
   throw new ArrayIndexOutOfBoundsException();
  
  pairs[index++] = new Object[]{key,value};
 }
 
 public Object get(Object key){
  for(int i = 0; i < index; i++)
   if(key.equals(pairs[i][0]))
    return pairs[i][1];
  throw new RuntimeException("FAILED TO FIND KEY");
 }
 
 public String toString(){
  String result = " ";
  for(int i = 0;i<index;i++){
   result += pairs[i][0] + " : " + pairs[i][1];
   if(i < index - 1)
    result += "\n";
  }
  return result;
 }
 
 public static void main(String[] args){
  AssociativeArray map = new AssociativeArray(6);
  map.put("sky", "blue");
  map.put("grass", "green");
  map.put("ocean", "dancing");
  map.put("ree", "tall");
  map.put("earth", "brown");
  map.put("sun", "warm");
  try{
   map.put("extra", "Object");
  }
  catch(ArrayIndexOutOfBoundsException e){
   System.out.println("Too Many Objects!");
  }
  System.out.println(map);
  System.out.println(map.get("Ocean"));
 }
}
4月12日

关于JAVA中内部类的例子

这个是Thinking in java中关于内部类的例子,在例子中我加入了toString()方法,JAVA中一切的输入输出都被看成为字符串,所以toStirng()函数也显得由为重要.但当我加入toString()是发现一个问题,这个例子没有办法很好的把内部类整合到外部类的toString()方法中.这才使我把内部类的用途完全想通.内部类只是一种控制机制,是为了隐藏创建的细节而产生的.而当要真正使用内部类对象一起整合成一个可用的类时,还是需要通过组合或者继承来完成.
 
Parcel2类中有一个方法叫ship(),可以用它来创建内部类对象,而创建的两个内不类对象在物理上和外部类没有明确的联系,导致无法组合它们的toString()方法到外部类中,虽然在逻辑上它们之间是有联系的.使用内部类对象也可以访问外部类的一切事物.但让我总觉得有些很别扭的地方.不知道大家有没有这种困扰.
 
而当在例子中结合使用组合后,许多问题都变的简单了.可以想象Parecle2中有两个内部类的引用c和d,这时我们就可以在外部类的toStirng()方法中把这个类从逻辑到物理上彻底的连接在一起了。也解决了物理上和逻辑上脱节的困扰.
 
public String toString(){
    return c.toString() + d.toString();
}
 
而在实现上就可以只用System.out.println(p)来输出这个类的信息了.
 
我的理解应该是对的吧,哈哈,希望大家指正.
 
 加入组合之前的例子:
package Path8;
public class Parcel2 {
 class Contents{
  private int i = 11;
  public int value(){return i;}
  public void ints(int i){this.i = i;}
  public String toString(){
   return "This Contents : " + i;
   }
 }
 class Destination{
  private String label;
  Destination(String whereTo){
   label = whereTo;
  }
  String readLabel(){
   return label;
  }
  public String toString(){
   return "This Destination : " + label;
   }
 }
 public Destination to(String s){
  return new Destination(s);
 }
 public Contents cont(){
  return new Contents();
 }
 public void ship(String s){
  Contents c = cont();
  Destination d = to(s);
  System.out.println(d.readLabel());
 }
 public static void main(String[] args) {
  Parcel2 p1 = new Parcel2();
  p1.ship("dest");
  Parcel2 p2 = new Parcel2();
  Parcel2.Contents cc = p2.cont();
  Parcel2.Destination dd = p2.to("dests");
  cc.ints(12);
  System.out.println("This Parcle Contents : " + cc);
  System.out.println("This Parcel Contents : " + dd);
 }
}
 
加入组合后的例子:
package Path8;
public class Parcel2 {
 public String toString(){
  return "This Parcel information : " + "\n" + c.toString() + "\n" + d.toString();
 }
 private Contents c;
 private Destination d;
 class Contents{
  private int i = 11;
  public int value(){return i;}
  public void ints(int i){this.i = i;}
  public String toString(){
   return "This Contents : " + i;
   }
 }
 class Destination{
  private String label;
  Destination(String whereTo){
   label = whereTo;
  }
  String readLabel(){
   return label;
  }
  public String toString(){
   return "This Destination : " + label;
   }
 }
 public void to(String s){
  d = new Destination(s);
 }
 public void cont(){
  c = new Contents();
 }
 public void ship(String s){
  cont();
  to(s);
 }
 public static void main(String[] args) {
  Parcel2 p = new Parcel2();
  p.ship("test");
  System.out.print(p);
 }
}
4月6日

继承中的初始化及类的加载问题.

在Java中都是以public类的main()方法为程序的入口,当编译器读入main()方法时,会去加载该main()方法的.java文件,并把文件内的类生成为.class文件.Java中对于类的初始化的顺序为先静态,然后是预定义,最后是构造器.而当被加载的类为其他类的子类时,会先读入它的父类,如果还有依次类推.
 
package Path6;
class Insect{
 private int i = 9;
 protected int j;
 Insect(){
  System.out.println("Insect Consturctor");
  System.out.println("i = " + i + ", j =  " + j);
  j = 39;
 }
 private static int x1 = print("static Insect.x1 initialized");
 static int print(String s){
  System.out.println(s);
  return 47;
 }
}
public class Beetle extends Insect {
 private int k = print("Beetle.k initalized");
 Beetle(){
  System.out.println("Beetle Constructor");
  System.out.println("k = " + k);
  System.out.println("j = " + j);
 }
 private static int x2 = print("static Beetle.x2 intitialized");
 public static void main(String[] args) {
  Beetle b = new Beetle();
 }
}
 
这个例子就是一个典型的例题,当读入main()方法时,由于并没有创建对象所以只会先创建父类的静态成员,然后是子类的静态成员.当创建一个Beetle对象实例时,程序读入父类,检查是否有预初始化.没有就调用构造器.然后是检查子类的.依次类堆.
4月3日

初始化引用的问题

Java中可以用三种方法初始化对象引用,它们分别为:
 
(1)在定义对象的地方,这意味着它们总是能够在构造器之前被初始化.
 
(2)在类的构造器中.
 
(3)就是在需要使用这些对象之前,这种方式被称为"惰性初始化".在生成对象不值得以及不必要每次都生成对象的情况下,这种方式可以减少额外的负担.
 
下面的例子包括了所有三种初始化方式,其中在toString()方法中所做的条件判断就是"惰性初始化".
 
package Path6;
class Soap{
 private String s;
 Soap(){
  System.out.println("Soap()");
  s= new String("Constructed");
 }
 public String toString(){
  return s;
 }
}
public class Path {
 
 private String
  s1 = new String("Happy"),
  s2 = "Happy",
  s3,s4;
 private Soap castille;
 private int i;
 private float toy;
 public Path(){
  System.out.println("Inside Bath()");
  s3 = new String("Joy");
  i =47;
  toy = 3.14f;
  castille = new Soap();
 }
 public String toString(){
  if(s4 == null)
   s4 = new String("Joy");
  return
   "s1 = " + s1 + "\n" +
   "s2 = " + s2 + "\n" +
   "s3 = " + s3 + "\n" +
   "s4 = " + s4 + "\n" +
   "i = " + i +"\n" +
   "toy = " + toy +"\n" +
   "castille = " + castille;
 }
 
 public static void main(String[] args) {
  Path b = new Path();
  System.out.println(b);
 }
}
4月2日

Java中的初始化问题

    在Java中,初始化的顺序是先"静态",后"预定义",最后才是"构造器".当一个Class拥有静态的成员,方法和对象引用是,所有一切的"静态"引用,成员,方法都是在第一次创建对象实例时创建,而此后无论创建多少个实例也不会在创建"静态"的一切,因为"静态"的含义和C++的"全局"概念有些相似,但这种"全局"只针对本类的实例,所有本类实例共用一个"静态"引用,成员,方法.类不会为每个实例分别创建"静态"的引用,成员,方法.
 
这个是关于一般对象初始化的例题
package Inheritance;
class Tag
{
 Tag(int marker)
 {
  System.out.println("Tag(" + marker + ")");
 }
}
class Card
{
 Tag t1 = new Tag(1);
 Card(){
  System.out.println("Card()");
  t3 = new Tag(33);
 }
 Tag t2 = new Tag(2);
 void f()
 {
  System.out.println("f()");
 }
 Tag t3 = new Tag(3);
}
public class OrderOfInitialization {
 public static void main(String[] args) {
  Card t = new Card();
  t.f();
 }
}
 
这个是关于静态成员,对象初始化的例题

package Inheritance;

class Bowl
{
 Bowl(int marker)
 {
  System.out.println("Bowl(" + marker + ")");
 }
 void f(int marker)
 {
  System.out.println("f(" + marker + ")");
 }
}

class Table
{
 static Bowl b1 = new Bowl(1);
 Table(){
  System.out.println("Table()");
  b2.f(1);
 }
 void f2(int marker)
 {
  System.out.println("f2(" + marker + ")");
 }
 static Bowl b2 = new Bowl(2);
}

class Cupboard
{
 Bowl b3 = new Bowl(3);
 static Bowl b4 = new Bowl(4);
 Cupboard()
 {
  System.out.println("Cupboard");
  b4.f(2);
 }
 void f3(int marker)
 {
  System.out.println("f3(" + marker + ")");
 }
 static Bowl b5 = new Bowl(5);
}

public class StaticInitialization {

 /**
  * @param args
  */
 public static void main(String[] args) {
  System.out.println("Creating new Cupboard() in main");
  new Cupboard();
  System.out.println("Creating new Cupboard() in main");
  new Cupboard();
  t2.f2(1);
  t3.f3(1);
 }
 static Table t2 = new Table();
 static Cupboard t3 = new Cupboard();
}

 
3月31日

无聊的很,不知道写什么,以后就一天写一个JAVA练习题了.

一切从零开始~第一个当然是HelloWorld
 
 
package JavaPractise;
public class HelloWorld
{
    public static void main(String[] args)
 
   {
       System.out.println("HelloWorld!");
   }
 
}
 
3月8日

重大决定:转向JAVA!!!

放弃一切微软的开发工具,转向学习SUN的开发平台.只有一个理由,免费.哈哈,微软太黑了,嘎嘎.