java技术博客

jsp博客
数据加载中……

2008年10月13日

jquery的ajax应用

//定义用户名校验的方法
function verify(){
    
//首先测试一下页面的按钮按下,可以调用这个方法
    //使用javascript的alert方法,显示一个探出提示框
    //alert("按钮被点击了!!!");

    
//1.获取文本框中的内容
    //document.getElementById("userName");  dom的方式
    //Jquery的查找节点的方式,参数中#加上id属性值可以找到一个节点。
    //jquery的方法返回的都是jquery的对象,可以继续在上面执行其他的jquery方法
    var jqueryObj = $("#userName");
    
//获取节点的值
    var userName = jqueryObj.val();
    
//alert(userName);

    
//2.将文本框中的数据发送给服务器段的servelt
    //使用jquery的XMLHTTPrequest对象get请求的封装
    $.get("AJAXServer?name=" + userName,null,callback);


}


//回调函数
function callback(data) {
//    alert("服务器段的数据回来了!!");
    //3.接收服务器端返回的数据
//
    alert(data);
    //4.将服务器段返回的数据动态的显示在页面上
    //找到保存结果信息的节点
    var resultObj = $("#result");
    
//动态的改变页面中div节点中的内容
    resultObj.html(data);
    alert(
"");
}

posted @ 2009-01-17 16:35 郭兴华 阅读(329) | 评论 (0)编辑 收藏
上海交通大学java视频教程共31讲

上海交通大学java视频教程共31讲
If you are interested in java, you can spend time learning about it

posted @ 2009-01-12 22:17 郭兴华 阅读(576) | 评论 (0)编辑 收藏
*.class 如何打包

先放下吧

posted @ 2008-11-13 09:12 郭兴华 阅读(163) | 评论 (0)编辑 收藏
java中的printf

public class TestPrintf{
    
public static void main(String args[]){
        System.out.printf(
"%+8.3f",3.14);    
        System.out.println();            
        System.out.printf(
"%+-8.3f\n",3.14);
        System.out.printf(
"%08.3f\n",3.14);
        System.out.printf(
"%(8.3f\n",-3.14);
        System.out.printf(
"%,f\n",2356.34);
        System.out.printf(
"%x\n",0x4a3b);
        System.out.printf(
"%#x\n",0x4a3b);        
        System.out.println(
"------------");    
        System.out.printf(
"你好:%s,%3d岁,工资%-7.2f\n","张三",38,15000.00);        
        System.out.printf(
"你好:%1$s,%2$3d岁,%2$#x岁\n","张三",38);        
        System.out.printf(
"%3d,%#<x",38);
    }
    
}

posted @ 2008-11-13 09:09 郭兴华 阅读(364) | 评论 (0)编辑 收藏
java中的集合

     摘要: Integer[] a = {3,25,12,79,48};         System.out.println(a);         System.out.println(Arrays.toStrin...  阅读全文

posted @ 2008-11-13 09:07 郭兴华 阅读(268) | 评论 (0)编辑 收藏
Arraylist

 

/**
 * 测试数组列表的使用
 
*/

 
import java.util.ArrayList;

public class ArrayListTest
{
    
public static void main(String[] args)
    
{
        ArrayList list 
= new ArrayList();
        list.add(
new Student("Tom","20020410"));
        list.add(
new Student("Jack","20020411"));
        list.add(
new Student("Rose","20020412"));

        
for(int i = 0; i < list.size(); i++)
        
{
            System.out.println((Student)list.get(i));
        }

    }

}


class Student
{
    
private String strName = "";//学生姓名
    private String strNumber = "";//学号
    private String strSex = "";//性别
    private String strBirthday = "";//出生年月
    private String strSpeciality = "";//专业
    private String strAddress = "";//地址

    
public Student(String name, String number)
    
{
        strName 
= name;
        strNumber 
= number;
    }


    
public String getStudentName()
    
{
        
return strName;
    }


    
public String getStudentNumber()
    
{
        
return strNumber;
    }


    
public void setStudentSex(String sex)
    
{
        strSex 
= sex;
    }


    
public String getStudentSex()
    
{
        
return strSex;
    }


    
public String getStudentBirthday()
        
{
        
return strBirthday;
    }


    
public void setStudentBirthday(String birthday)
    
{
        strBirthday 
= birthday;
    }


    
public String getStudentSpeciality()
    
{
        
return strSpeciality;
    }


    
public void setStudentSpeciality(String speciality)
    
{
        strSpeciality 
= speciality;
    }


    
public String getStudentAddress()
    
{
        
return strAddress;
    }


    
public void setStudentAddress(String address)
    
{
        strAddress 
= address;
    }


    
public String toString()
    
{
        String information 
= "学生姓名=" + strName + ", 学号=" + strNumber;  
        
if!strSex.equals("") )
            information 
+= ", 性别=" + strSex;
        
if!strBirthday.equals(""))
            information 
+= ", 出生年月=" + strBirthday;
        
if!strSpeciality.equals("") )
            information 
+= ", 专业=" + strSpeciality;
        
if!strAddress.equals("") )
            information 
+= ", 籍贯=" + strAddress;
        
return information;
    }

}

posted @ 2008-11-07 16:34 郭兴华 阅读(210) | 评论 (0)编辑 收藏
java的动态多态

/**
 * 通过本程序的测试,主要学习抽象类及子类,抽象方法的实现
 * 动态绑定,多态
 
*/

 
import java.text.NumberFormat;

public class AbstractTest
{
    
public static void main(String[] args)
    
{
        Person[] p 
= new Person[2];
        p[
0= new Worker("Jack"1000);
        p[
1= new Student("Tom""Computer");
        
        
for(int i = 0; i < p.length; i++)
        
{
            Person people 
= p[i];
            System.out.println(people.getDescription());
        }

    }

}


/**
 * 抽象类
 
*/

abstract class Person
{
    
private String strName;

    
public Person(String strName)
    
{
        
this.strName = strName;
    }


    
public String getName()
    
{
        
return strName;
    }


    
//抽象方法,返回人的描述
    public abstract String getDescription();
}


/**
 * 工人类,扩展了抽象类,并实现了抽象方法
 
*/

class Worker extends Person
{
    
private double salary;
    
    
public Worker(String strName, double s)
    
{
        
super(strName);
        salary 
= s;
    }

    
    
public String getDescription()
    
{
        NumberFormat formate 
= NumberFormat.getCurrencyInstance();
        
return "the worker with a salary of " + formate.format(salary);
    }

}


/**
 * 学生类,扩展了抽象类,实现了抽象方法
 
*/

class Student extends Person
{
    
private String strMajor;
    
    
public Student(String strName, String strMajor)
    
{
        
super(strName);
        
this.strMajor = strMajor;
    }

    
    
public String getDescription()
    
{
        
return "the student majoring in " + strMajor;
    }

}

posted @ 2008-11-07 16:31 郭兴华 阅读(268) | 评论 (0)编辑 收藏
java中的HashMapTest

     摘要: /** *//**  * 通过这个程序,测试散列映像的存储与遍历,方法的使用  */ import java.util.HashMap; import java.util.Collection; import java.util.Iterator; import java.util.Set; public&nb...  阅读全文

posted @ 2008-11-07 16:12 郭兴华 阅读(319) | 评论 (0)编辑 收藏
java中的treeset

/**
 * 通过这个程序,测试树集的添加元素的无序性与输出的有序性
 
*/

 
import java.util.TreeSet;
import java.util.Iterator;

public class TreeSetTest
{
    
public static void main(String[] args)
    
{
        TreeSet tree 
= new TreeSet();
        tree.add(
"China");
        tree.add(
"America");
        tree.add(
"Japan");
        tree.add(
"Chinese");
        
        Iterator iter 
= tree.iterator();
        
while(iter.hasNext())
        
{
            System.out.println(iter.next());
        }

    }

}

posted @ 2008-11-07 16:10 郭兴华 阅读(495) | 评论 (0)编辑 收藏
java中的treemap

     摘要: /** *//**  * 通过这个程序,测试树映像的使用,表目集合的遍历  */ import java.util.TreeMap; import java.util.Map; import java.util.Iterator; import java.util.Set; public class&...  阅读全文

posted @ 2008-11-07 16:08 郭兴华 阅读(4590) | 评论 (0)编辑 收藏
java中的vector

     摘要: /** *//** *//** *//**  * 我们设计的学生基本类  */ class Student {     private String strName = "";//学生姓名     ...  阅读全文

posted @ 2008-11-07 16:02 郭兴华 阅读(342) | 评论 (0)编辑 收藏
记录类被实例化的次数

/*01*/public class classNumberDemo 
/*02*/{
/*03*/      public static int objNum=0;
/*04*/      public classNumberDemo()
/*05*/      {
/*06*/          classNumberDemo.objNum++;
/*07*/      }

/*08*/      public void show()
/*09*/      {
/*10*/          System.out.println("the No."+classNumberDemo.objNum);
/*11*/      }

/*12*/      
/*13*/        public static void main(String args[])
/*14*/        {
/*15*/             classNumberDemo p=null;
/*16*/             p=new classNumberDemo();
/*17*/             p.show();
/*18*/             p=new classNumberDemo();
/*19*/             p.show();
/*20*/             p=new classNumberDemo();
/*21*/             p.show();             
/*22*/      }

/*23*/}

posted @ 2008-11-05 22:16 郭兴华 阅读(352) | 评论 (0)编辑 收藏
java编程小实例

/**   2005 Aptech Limited
 *     版权所有
 
*/


/**
 * 该程序测试使用 break 关键字来检测的质数
 * 
@version 1.0, 2005 年 5 月 22 日
 * 
@author Michael
 
*/


public class PrimeNumber {

    
/** 构造方法*/
    PrimeNumber() 
{
    }


     
/**
      * 这是一个 main 方法
      * 
@param args 传递至 main 方法的参数
      
*/


    
public static void main(String[] args) {

    
int number = 29;

    
for (int i = 2; i < number; i++{

        
if (number % i == 0{
        System.out.println(
"不是质数");
        
break;
        }
 else {
            System.out.println(
"它是一个质数");
            
break;
           }

       }

    }

}





/*
 * 2005 Aptech Limited
 * 版权所有
 
*/


/**
 * 此类将输出数组中第二个最大的数字
 * 
@version 1.0, 2005 年 5 月 22 日
 * 
@author Michael
 
*/


public class HighestNumber {

    
/** 构造函数. */
    HighestNumber() 
{
    }


     
/**
      * 这是一个 main 方法
      * 
@param args 传递至 main 方法
      
*/


     
public static void main(String[] args) {


     
int[] array = {43798};
     
int greatest = 0;
     
int secondhighest = 0;

     
for (int i = 1; i < 5; i++{

         
if (greatest < array [i]) {

         secondhighest 
= greatest;
         greatest 
= array[i];

         }
 else {

             
if (secondhighest < array[i]) {

                 secondhighest 
= array[i];
                 }

             }

         }

         System.out.println(
"第二大的数字是: " + secondhighest);

     }

}

posted @ 2008-11-04 07:56 郭兴华 阅读(150) | 评论 (0)编辑 收藏
i++与++i的区别

public class ppDemo
{
    
public static void main(String[] args)
    
{
    
int result=0;
    
int p=2*result++;
    System.out.println(p);
    System.out.println(result);
    result
=0;
    
int y=2*++result;
    System.out.println(result);
    System.out.println(y);
    }

}

posted @ 2008-11-03 14:37 郭兴华 阅读(119) | 评论 (0)编辑 收藏
java静态成员

/*01*/public class static_demo
/*02*/{
/*03*/    public static int i=0;
/*04*/    public int j=0;
/*05*/    public void show()
/*06*/    {
/*07*/    System.out.println(i);
/*08*/    System.out.println(j);
/*09*/    }

/*10*/}

/*11*/
/*12*/class test
/*13*/{
/*14*/    public static void main(String args[])
/*15*/    {
/*16*/    static_demo obj1=new static_demo();
/*17*/    obj1.i=100;
/*18*/        obj1.j=200;
/*19*/        obj1.show();
/*20*/        static_demo obj2=new static_demo();
/*21*/    obj2.show();
/*22*/    }

/*23*/}

posted @ 2008-11-03 14:14 郭兴华 阅读(91) | 评论 (0)编辑 收藏
java中的静态代码段

/*01*/public class static_block
/*02*/{
/*03*/    public String name;
/*04*/    public String sex;
/*05*/    public int    age;
/*06*/  public static_block(String na,String se,int ag)
/*07*/  {
/*08*/      name=na;
/*09*/      sex=se;
/*10*/      age=ag;
/*11*/  }

/*12*/    public void show()
/*13*/    {
/*14*/        System.out.println("Name:"+name);
/*15*/        System.out.println("Sex:"+sex);
/*16*/        System.out.println("Age:"+age);
/*17*/    }

/*18*/    static{
/*19*/          System.out.println("hello block");
/*20*/    }

/*21*/    public static void main(String args[])
/*22*/    { System.out.println("hello main");
/*23*/        static_block pObj=new static_block("zhangsan","male",30);
/*24*/        pObj.show();
/*25*/    }

/*26*/}

posted @ 2008-11-03 08:47 郭兴华 阅读(310) | 评论 (0)编辑 收藏
++i与i++

public class ppDemo{
public static void main(String[] args)
{
int i=0;
result
=1+i++;
System.out.println(i);
System.out.println(result);
i
=0;
result
=1+++i;
System.out.println(i);
System.out.println(result);
}

}

posted @ 2008-10-31 11:57 郭兴华 阅读(101) | 评论 (0)编辑 收藏
java代理模式

package orj.jzkangta.proxydemo02;

public class ComputerMaker implements SaleComputer {

    
public void sale(String type) {
        System.out.println(
"卖出了一台"+type+"电脑");

    }


}



package orj.jzkangta.proxydemo02;

import java.lang.reflect.Proxy;

public class ComputerProxy {
    
public static SaleComputer getComputerMaker(){
        ProxyFunction pf
=new ProxyFunction();
        
return (SaleComputer)Proxy.newProxyInstance(ComputerMaker.class.getClassLoader(), ComputerMaker.class.getInterfaces(), pf);
    }

}





package orj.jzkangta.proxydemo02;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class ProxyFunction implements InvocationHandler {
    
private ComputerMaker cm;
    
    
public void youHui(){
        System.out.println(
"我给你一些优惠。。。");
    }

    
    
public void giveMouse(){
        System.out.println(
"我还要送你一个鼠标。。。 ");
    }

    
public Object invoke(Object arg0, Method arg1, Object[] arg2)
            
throws Throwable {
        String type
=(String)arg2[0];
        
if(type.equals("联想")||type.equals("三星")){
            
if(cm==null){
                cm
=new ComputerMaker();
                youHui();
                giveMouse();
                arg1.invoke(cm, type);
            }

        }
else{
            System.out.println(
"我没有你要的这个牌子的电脑。。。。");
        }

        
return null;
    }


}

package orj.jzkangta.proxydemo02;

public interface SaleComputer {
    
public void sale(String type);
}


package orj.jzkangta.proxydemo02;

public class Test {

    
    
public static void main(String[] args) {
        SaleComputer sc
=ComputerProxy.getComputerMaker();
        
//sc.sale("联想");
        
//sc.sale("三星");
        sc.sale("Dell");

    }


}

posted @ 2008-10-31 07:49 郭兴华 阅读(720) | 评论 (0)编辑 收藏
java中的多态

/*01*/public class overdemo1
/*02*/{
/*03*/    public static void main(String args[])
/*04*/    {
/*05*/    Child c=new Child();
/*06*/        int iResult=c.add(1,2);
/*07*/    double dResult=c.add(1.0,2.0);
/*08*/    System.out.println(iResult);
/*09*/    System.out.println(dResult);
/*10*/    }

/*11*/}

/*12*/
/*13*/class Parent
/*14*/{
/*15*/   public int add(int a, int b)
/*16*/   {
/*17*/       return  a+b;
/*18*/   }

/*19*/}

/*20*/
/*21*/class Child extends Parent
/*22*/{
/*23*/   public double add(double a, double b)
/*24*/   {
/*25*/        return a+b;
/*26*/   }

/*27*/}

posted @ 2008-10-30 14:31 郭兴华 阅读(120) | 评论 (0)编辑 收藏
java方法的重载

/*01*/public class calculator
/*02*/{
/*03*/   public int add(int a, int b)   
/*04*/   {
/*05*/        return a+b;
/*06*/   }

/*07*/   public double add(double a, double b)
/*08*/   {
/*09*/         return a+b;
/*10*/   }

/*11*/   public float add(float a, float b)
/*12*/   {
/*13*/         return a+b;
/*14*/   }

/*15*/   public static void main(String args[])
/*16*/   {
/*17*/          calculator cal=new calculator();
/*18*/          int iResult=cal.add(12,13);
/*19*/          double dResult=cal.add(12.0,13.0);
/*20*/          float  fResult=cal.add(12.0f13.0f);
/*21*/          System.out.println(iResult);
/*22*/          System.out.println(dResult);
/*23*/          System.out.println(fResult);
/*24*/   }

/*25*/}

posted @ 2008-10-30 14:23 郭兴华 阅读(72) | 评论 (0)编辑 收藏
本程序搜索文件中的字

     摘要: /** *//**  (C) 北大青鸟APTECH.  *   版权所有  */ /** *//**  * 本程序导入所需的类.  */ import java.io.File; import java.io.BufferedR...  阅读全文

posted @ 2008-10-30 09:12 郭兴华 阅读(59) | 评论 (0)编辑 收藏
本程序搜索文件中的字

     摘要: /** *//**  (C) 北大青鸟APTECH.  *   版权所有  */ /** *//**  * 本程序导入所需的类.  */ import java.io.File; import java.io.BufferedR...  阅读全文

posted @ 2008-10-30 09:12 郭兴华 阅读(80) | 评论 (0)编辑 收藏
本程序搜索文件中的字

     摘要: /** *//**  (C) 北大青鸟APTECH.  *   版权所有  */ /** *//**  * 本程序导入所需的类.  */ import java.io.File; import java.io.BufferedR...  阅读全文

posted @ 2008-10-30 09:12 郭兴华 阅读(92) | 评论 (0)编辑 收藏
判断一个一个路径是否是目录

/**  
 *   (C) 北大青鸟APTECH.
 *   版权所有
 
*/


/**
 * 本程序导入所需的类.
 
*/

import java.io.File;

/**
 * 本程序演示 File 类的使用.
 * 
@version 1.0 2005 年 5 月 20 日
 * 
@author Michael
 
*/


class ListDirectory {

/** 存储要搜索的目录名称. */
    String directoryName;

/** 声明一个 File 对象. */
    File fileObj;

/** 
 * 构造方法.
 * 
@param name 是一个字符串
 
*/

    ListDirectory(String name) 
{
       directoryName 
= name;
       fileObj 
= new File(name);
    }


/** 
 * 显示目录和子目录的方法.
 
*/

    
void display() {
       
if (fileObj.isDirectory()) {
          System.out.println(
"目录是 : " + directoryName);
          String[] fileName 
= fileObj.list();

          
for (int ctr = 0; ctr < fileName.length; ctr++{
              File nextFileObj 
= new File(directoryName + "/" + fileName[ctr]);

              
if (nextFileObj.isDirectory()) {
                 System.out.println(fileName[ctr] 
+ " 是一个目录");
              }
 else {
                 System.out.println(fileName[ctr] 
+ " 是一个文件");
              }

          }

        }
 else {
              System.out.println(directoryName 
+ " 不是一个有效目录");
        }

    }

}


/**
 * 本程序测试 ListDirectory 类.
 * 
@version 1.0 2005 年 5 月 20 日
 * 
@author Michael
 
*/


class DirectoryTest {

/** 
 * 构造方法. 
 
*/

    
protected DirectoryTest() {
    }


/**
 * 这是一个 main 方法.
 * 
@param args 被传递至 main 方法
 
*/

    
public static void main(String[] args) {
        ListDirectory listObj 
= new ListDirectory("java");
        listObj.display();
    }

}

posted @ 2008-10-30 08:09 郭兴华 阅读(1078) | 评论 (0)编辑 收藏
抽象类和方法的用法.

     摘要: /**//* 北大青鸟APTECH  * 版权所有  */ /** *//**  * 这个程序演示抽象类和方法的用法.  * @版本 1.0 2005 年 5 月 20 日  * @author M...  阅读全文

posted @ 2008-10-29 18:52 郭兴华 阅读(206) | 评论 (0)编辑 收藏
java的多态

/*  北大青鸟APTECH.
 *  版权所有
 
*/


/**
 * 这个程序演示动态多态性的用法.
 * 
@version 1.0 2005 年 5 月 20 日
 * 
@author Michael
 
*/

abstract class Shape {

    
/** 存储任何形状的长. */
    
protected double length;

    
/** 存储任何形状的宽. */
    
protected double width;

    
/** 
     * 构造方法.
     * 
@param num 传递至构造方法
     * 
@param num1 传递至构造方法
     
*/

    Shape(
final double num , final double num1) {

    
/** 初始化变量. */
        length 
= num;
        width 
= num1;
    }


    
/**
     * 抽象方法.
     * 
@return double 值
     
*/

    
abstract double area();
}


/**
 * 这个类重写父类的方法.
 * 
@version 1.0 2005 年 5 月 20 日
 * 
@author Michael
 
*/


class Square extends Shape {

    
/** 构造方法.
     *
@param num 传递至构造方法的参数
     *
@param num1 传递至构造方法的参数
     
*/

    Square(
final double num, final double num1) {
        
super(num, num1);
    }


    
/**
     * 计算正方形的面积.
     * @return传递给构造方法的 length
     
*/


    
double area() {
        System.out.println(
"正方形的面积为:" );
        
return length * width;
    }

}


/**
 * 这个类重写父类的方法.
 * 
@version 1.0 2005 年 5 月 20 日
 * 
@author Michael
 
*/


class Triangle extends Shape {

    
/** 构造方法.
     *
@param num 传递至构造方法的参数
     *
@param num1 传递至构造方法的参数
     
*/

    Triangle(
final double num, final double num1) {
        
super(num, num1);
    }


    
/**
     * 计算三角形的面积.
     *
@return double  传递给构造方法的length
     
*/


    
double area() {
        System.out.println(
"三角形的面积为:" );
        
return (0.5 * length * width);
    }

}


/**
 * 这个类测试对象引用.
 * 
@version 1.0 2005 年 5 月 20 日
 * 
@author Michael
 
*/


public class CalculateArea {

    
/** 构造方法. */
    
protected CalculateArea() {
    }


    
/**
     * 这是 main 方法.
     * 
@param arg 传递至 main 方法的参数
     
*/


    
public static void main(final String[] arg) {
        
// 初始化变量
        Shape fObj;
        Square sqObj 
= new Square(10 , 20);
        Triangle trObj 
= new Triangle(12 , 8);
        fObj 
= sqObj;
        System.out.println(fObj.area());
        fObj 
= trObj;
        System.out.println(fObj.area());
    }

}

posted @ 2008-10-29 07:39 郭兴华 阅读(126) | 评论 (0)编辑 收藏
java数组的Copy

/**
* 测试数组元素拷贝
*/
public class ArrayCopy
{
public static void main(String[] args)
{
ArrayCopy aCopy
= new ArrayCopy();
int[] a = {1, 2, 3, 4, 5};
int[] b = {10,20,30,40,50};
aCopy.copy(a, b);

}

public void copy(int[] from, int[] to)
{
System.out.println(
"第一个数组中的元素");
for (int i = 0; i < from.length; i++)
{
System.out.print(
" " + from[i]);//打印出数组中的每一个元素
}
System.out.println(
"\n");

System.out.println(
"第二个数组中的元素");
for (int i = 0; i < to.length; i++)
{
System.out.print(
" " + to[i]);//打印出数组中的每一个元素
}

System.out.println(
"\n\n将第一个数组拷贝到第二个数组\n");
System.arraycopy(from,
2, to, 0, 3);

System.out.println(
"拷贝完成后第二个数组中的元素");
for (int i = 0; i < to.length; i++)
{
System.out.print(
" " + to[i]);//打印出数组中的每一个元素
}
}
}

输出结果是3 4 5 40 50

posted @ 2008-10-28 10:11 郭兴华 阅读(174) | 评论 (0)编辑 收藏
JDBC连接SQLSERVER

     摘要: <%@page language="java" import="java.util.*,java.sql.*,Oper.*,voo.*" pageEncoding="GBK"%> <table border=1> <tr>     <th>编号</th>...  阅读全文

posted @ 2008-10-26 09:46 郭兴华 阅读(1813) | 评论 (0)编辑 收藏
jsp读取*.TXT

package mypack;
import java.io.*;

public class ReadText{
    
public String getShiGe(){
        
//File f=new File("guoxinghua.txt");
        File f=new File(this.getClass().getResource("guoxinghua.txt").toURI());
        
try{
            FileReader fr
=new FileReader(f);
            BufferedReader buff
=new BufferedReader(fr);//BufferedReader用于读取文本
            String line="";
            
while((line=buff.readLine())!=null)
            
{
                retstr
+line+"<br>";
                }

                buff.close();
                }

            
catch(Exception e)
            
{
                e.printStackTrace();
                
                }

                
                
                
return retstr;
                }

    }



<%@page language="java" import="java.util.*,mypack" page Encoding="GBK"%>
<%
ReadText rt
=new ReadText();
%>
<%=rt.getShiGe()%>

posted @ 2008-10-26 07:20 郭兴华 阅读(753) | 评论 (1)编辑 收藏
java1.5注解(二)


import java.util.Date;
import java.util.Map;
import java.util.TreeMap;
class  SuppressWarningsTest
{
    
public static void main(String[] args) 
    
{
        Map
<String,Date> map=new TreeMap<String,Date>();
        map.put(
"hello",new Date());
        System.out.println(map.get(
"hello"));
    }

}





import java.util.Date;
import java.util.Map;
import java.util.TreeMap;
class  SuppressWarningsTest2
{
    
public static void main(String[] args) 
    
{
        Map map
=new TreeMap();
        
//Map<String,Date> map=new TreeMap<String,Date>();
        map.put("hello",new Date());
        System.out.println(map.get(
"hello"));
    }

}




import java.util.Date;
import java.util.Map;
import java.util.TreeMap;
class  SuppressWarningsTest3
{
    @SuppressWarnings(
"unchecked")
    
public static void main(String[] args) 
    
{
        Map map
=new TreeMap();
        
//Map<String,Date> map=new TreeMap<String,Date>();
        map.put("hello",new Date());
        System.out.println(map.get(
"hello"));
    }

}






import java.util.Date;
import java.util.Map;
import java.util.TreeMap;
class DeprecatedTest 
{
    
public void doSomething(){
    System.out.println(
"guoxinghua");
    }

    
public static void main(String[] args) 
    
{
        DeprecatedTest test
=new DeprecatedTest();
        test.doSomething();
        
    }

}


class  SuppressWarningsTest2
{
    
public static void main(String[] args) 
    
{
        Map map
=new TreeMap();
        
//Map<String,Date> map=new TreeMap<String,Date>();
        map.put("hello",new Date());
        System.out.println(map.get(
"hello"));
    }

}




import java.util.Date;
import java.util.Map;
import java.util.TreeMap;
class DeprecatedTest 
{
    
public void doSomething(){
    System.out.println(
"guoxinghua");
    }

    
public static void main(String[] args) 
    
{
        DeprecatedTest test
=new DeprecatedTest();
        test.doSomething();
        
    }

}


class  SuppressWarningsTest2
{
    @SuppressWarnings(
{"unchecked","deprecation"})
    
public static void main(String[] args) 
    
{
        Map map
=new TreeMap();
        
//Map<String,Date> map=new TreeMap<String,Date>();
        map.put("hello",new Date());
        System.out.println(map.get(
"hello"));
        DeprecatedTest test
=new DeprecatedTest();
        test.doSomething();
    }

}


posted @ 2008-10-26 00:21 郭兴华 阅读(348) | 评论 (0)编辑 收藏
java1.5注解(一)

 

 

由来

减少代码和程序错误的发生
C#中的也有这种情况

对java程序没有直接影响,
内置注解
Override
Deprecated
SuppressWarnings

//对学框架有帮助
通过程序来说明

注意override与overload区别
class OverrideTest2 
{
    @Override
    
public String toString(){
    
return "guoxinghua";
    }

    
public static void main(String[] args) 
    
{
        OverrideTest2 test
=new OverrideTest2();

        System.out.println(test.toString());
    }

}



class OverrideTest3 
{
    
//@Override
    public String ToString(){
    
return "guoxinghua";
    }

    
public static void main(String[] args) 
    
{
        OverrideTest3 test
=new OverrideTest3();

        System.out.println(test.toString());
    }

}


class OverrideTest3 
{
    @Override
    
public String ToString(){
    
return "guoxinghua";
    }

    
public static void main(String[] args) 
    
{
        OverrideTest3 test
=new OverrideTest3();

        System.out.println(test.toString());
    }

}






class DeprecatedTest 
{
    
public void doSomething(){
    System.out.println(
"guoxinghua");
    }

    
public static void main(String[] args) 
    
{
        DeprecatedTest test
=new DeprecatedTest();
        test.doSomething();
        
    }

}





class DeprecatedTest 
{
    @Deprecated
    
public void doSomething(){
    System.out.println(
"guoxinghua");
    }

    
public static void main(String[] args) 
    
{
        DeprecatedTest test
=new DeprecatedTest();
        test.doSomething();
        
    }

}








class SubDeprecatedTest extends DeprecatedTest 
{
    @Override
    
public void doSomething(){
    System.out.println(
"guoxinghua");
    }

    
public static void main(String[] args) 
    
{
        SubDeprecatedTest sub
=new SubDeprecatedTest();
        sub.doSomething();
    }

}

posted @ 2008-10-25 22:22 郭兴华 阅读(557) | 评论 (0)编辑 收藏
jsp中使用类




package mypack;
class Student 
{
    
private int age;
    
private String xm;
    
private float mark;
    
public void setAge(int age){
        
this.age=age;
        }

        
public int getAge(){
        
return age;
        }

        
public void setXm(String xm)
    
{
        
this.xm=xm;
        }

        
public String getXm()
    
{
        
return xm;
        }

        
public void setMark(float mark)
    
{
        
this.mark=mark;
        }

        
public float getMark(){
        
return mark;
        }

        

}



package mypack;
class Say 
{
    
public String hello(String xm) 
    
{return "Hello World "+xm;
    }

}






<%@page language="java" import ="java.util.*,mypack.*" pageEncoding="GBK"%>
   <%@import="....."%>//用于多个包的导入
<%!
public int add(int x,int y)
{
return x+y;
}

int a=10;

%>


<%
Student stu
=new Student();
stu.setAge(
29);
stu.setXm(
"guoxinghua");
stu.setMark(
200.0F);
int a=100;
%>
<%Say s=new Say()%>
<%=s.hello(stu.getXm())%>
<%=s.add(10,20)%><%=stu.getAge()%>
<%=stu.getXm()%>
<%=stu.getMark()%>
<%=this.a%>
<%=a%>

<%%>这种是代码段,在这里声明的方法和变量是在局部的
<%!%>这种是声明语句,在这里声明的变量和方法是全局的
 <%=%>这种是表达式

posted @ 2008-10-25 11:55 郭兴华 阅读(226) | 评论 (0)编辑 收藏
VectorTest.java(待写.....)

/**
 * 通过这个程序,测试Vector的添加元素及插入元素
 
*/

import java.util.Vector;
public class VectorTest{
public static void main(String[] args)
{
}
 }

posted @ 2008-10-23 16:09 郭兴华 阅读(72) | 评论 (0)编辑 收藏
VectorTest2.java

 

/**
*通过这个程序,测试Vector的ratainAll方法
*/

import java.util.Vector;
public class VectorTest{
public static void main(String[] args){
VectorTest2 test
=new VectorTest2();
Vector vec1
=new Vector();
Vector vec2
=new Vector();

Student tom 
=new Student("tom","20020410");
Student jack
=new Student("jack","20020411");
Student smith
=new Student("Smith","20020412");
Student rose
=new Student("rose","20020413");
vec1.add(tom);
vec1.add(jack);
vec1.add(smith);
vec1.add(rose);
System.out.println(
"第一个Vector中的元素分别是:");
test.display(vec1);
vec2.add(rose);
vec2.add(tom);
System.out.println(
"\n第二个Vector中的元素分别是:");
test.display(vec2);
System.out.println(
"\n调用retainAll方法后,第一个Vector中的元素分别是:");
vec1.retainAll(vec2);
test.display(vec1);
}

public void display(Vector vec){
for(int i=0;i<vec.size();i++)
{
 System.out.println(vec.get(i));
}

}

}

posted @ 2008-10-23 15:54 郭兴华 阅读(93) | 评论 (0)编辑 收藏
VectorTest2.java

 

/**
*通过这个程序,测试Vector的ratainAll方法
*/

import java.util.Vector;
public class VectorTest{
public static void main(String[] args){
VectorTest2 test
=new VectorTest2();
Vector vec1
=new Vector();
Vector vec2
=new Vector();

Student tom 
=new Student("tom","20020410");
Student jack
=new Student("jack","20020411");
Student smith
=new Student("Smith","20020412");
Student rose
=new Student("rose","20020413");
vec1.add(tom);
vec1.add(jack);
vec1.add(smith);
vec1.add(rose);
System.out.println(
"第一个Vector中的元素分别是:");
test.display(vec1);
vec2.add(rose);
vec2.add(tom);
System.out.println(
"\n第二个Vector中的元素分别是:");
test.display(vec2);
System.out.println(
"\n调用retainAll方法后,第一个Vector中的元素分别是:");
vec1.retainAll(vec2);
test.display(vec1);
}

public void display(Vector vec){
for(int i=0;i<vec.size();i++)
{
 System.out.println(vec.get(i));
}

}

}

posted @ 2008-10-23 15:54 郭兴华 阅读(89) | 评论 (0)编辑 收藏
VectorTest1.java(数据结构练习)

/**
*通过这个程序,测试Vector的添加元素及插入元素
*/

import java.util.Vector;
public static void main(String[] args){
Vector vec
=new Vector();
Student tom
=new Student("tom","20020410");
Student jack
=new Student("jack","20020412");
Student smith
=new Student("Smith","20020412");
vec.add(tom);
vec.add(
0,jack);//inset a new element
vec.add(0,smith);//inset a new element too
for(int i=0;i<vec.size();i++){
System.out.println(vec.get(i));
}

}

posted @ 2008-10-23 15:39 郭兴华 阅读(86) | 评论 (0)编辑 收藏
AbstractTest.java

 

/**
 * 通过本程序的测试,主要学习抽象类及子类,抽象方法的实现
 * 动态绑定,多态
 
*/

import java.text.NumberFormat;
public class AbstractTest{
public static void main(String[] args)
{
Person[] p
=new Person[2];
p[
0]=new Worker("jack",1000);
p[
1]=new Student("tom","computer");
for(int i=0;i<p.length;i++){
Person people
=p[i];
System.out.println(people.getDescription());
}
}
}

/**
*抽象类
*/

abstract class Person{
private String strName;

 
public Person(String strName)
 
{
  
this.strName = strName;
 }


 
public String getName()
 
{
  
return strName;
 }


//抽象方法,返回人的描述
public abstract String getDescription();
}

/**
 * 工人类,扩展了抽象类,并实现了抽象方法
 
*/

class Worker extends Person{
private double salary;
public worker(String strName,double s)
{
super(strName);
salary
=s;
}

public String getDescription(){
NumberFormat formate
=NumberFormat.getCurrencyInstance();
return "the worker with a salary of "+formate.format(salary);
}


}

/**
 * 学生类,扩展了抽象类,实现了抽象方法
 
*/

class Student extends Person{
private String strMajor;
public Student(String strName,String strMajor)
{
super(strName);
this.strMajor=strMajor;
}

public String getDescription(){
return "the student majoring in "+strMajor;
}

}

posted @ 2008-10-23 15:23 郭兴华 阅读(120) | 评论 (0)编辑 收藏
MuilInterfaceTest.java

 

/**
*通过这个程序,我们要测试接口的多重实现,并学习对象比较方法的实现
*/

import java.util.Arrays
public class MuilInterfaceTest{
public static void main(String[] args){
Student[] staff
=new student[3];
staff[
0]=new Student("tom","20031020");
staff[
1]=new Student("jack","20031022");
staff[
2]=new Student("rose","20021023");
Arrays.sort(staff);
for(int i=0;i<staff.length;i++)
{
System.out.println((Student)staff[i]);
}
}
 }


/*
*学生类,包括学生的基本信息,实现了Person与Comparable接口
*/

class Student implements Person, Comparable
{
 
private String strName = "";//学生姓名
 private String strNumber = "";//学号
 private String strSex = "";//性别
 private String strBirthday = "";//出生年月
 private String strSpeciality = "";//专业
 private String strAddress = "";//地址

 
public Student(String name, String number)
 
{
  strName 
= name;
  strNumber 
= number;
 }
public int compareTo(Object otherObject){
Student other
=(Student)otherObject;
int otherNumber=Integer.parseInt(other.strNumber);
int thisNumber=Integer.parseInt(this.strNumber);
if(thisNumber>otherNumber)
return 1;
else if(thisNubmer==otherNumber)
return 0;
else return -1;
}



public String getName()
 
{
  
return strName;
 }


 
public String getStudentNumber()
 
{
  
return strNumber;
 }


 
public void setStudentSex(String sex)
 
{
  strSex 
= sex;
 }


 
public String getSex()
 
{
  
return strSex;
 }


 
public String getBirthday()
  
{
  
return strBirthday;
 }


 
public void setStudentBirthday(String birthday)
 
{
  strBirthday 
= birthday;
 }


 
public String getStudentSpeciality()
 
{
  
return strSpeciality;
 }


 
public void setStudentSpeciality(String speciality)
 
{
  strSpeciality 
= speciality;
 }


 
public String getAddress()
 
{
  
return strAddress;
 }


 
public void setAddress(String address)
 
{
  strAddress 
= address;
 }

public String toString(){
String information
="student name="+strName+"student numbeer="+strNumber;
if(!strSex.equals(""))
information
+=",sex="+strSex;
if(!strBirthday.equals(""))
information
+=",Birthday="+strBirthday;
if(!strSpeciality.equals(""))
information
+=",专业="+strSpeciality;
if(!strAddress.equals(""))
information
+=",address="+strAddress;
return information;}
}

posted @ 2008-10-23 15:02 郭兴华 阅读(119) | 评论 (0)编辑 收藏
CloneTest2.java

     摘要:   /**//* *测试包含对象的克隆及clone方法的重写 */ import java.util.GregorianCalendar; import java.util.Date; public class CloneTest{ public static void main(String[]&nbs...  阅读全文

posted @ 2008-10-23 14:40 郭兴华 阅读(137) | 评论 (0)编辑 收藏
CloneTest.java

 

/**
*i测试对象的克隆及clone方法的重写
*/

public class CloneTest{
public static void main(String[] args){
Student tom
=new Student("tom","20020410");
Student tomcopy
=(Student)tom.clone();
tomcopy.setStudentSex(
"man");
tomcopy.setStudentAddress(
"America");
System.out.println(tom);
System.out.println(tomcopy);
}

}

/*
 * 学生类,包括学生的基本信息,实现了Cloneable接口
 
*/

class Student implements Cloneable
{
 
private String strName = "";//学生姓名
 private String strNumber = "";//学号
 private String strSex = "";//性别
 private String strBirthday = "";//出生年月
 private String strSpeciality = "";//专业
 private String strAddress = "";//地址
 
 
public Student(String name, String number)
 
{
  strName 
= name;
  strNumber 
= number;
 }

public Object clone(){
try{
return super.clone();
}

catch(CloneNotSupportedException e){
return null;}

}

public String getStudentName(){
return strNumber;
}

public void setStudentSex(String sex)
{
strSex
=sex;
}

public String getStudentSex(){
return strSex;
}

public String getStudentBirthday(){
return strBirthday;
}

public String getStudentSpeciality(){
return strSpeciality;
}

public void setStudentSpeciality(String speciality){
strSpeciality
=speciality;
}

public String getStudentAddress() {
return strAddress;
}

public void setStudentAddress(String address){
strAddress
=address;
}

public Stirng toString()
{
String information
="student name="+strName+",student number="+strNumber;
if(!strSex.equals(""))
information
+=",sex="+strSex;
if(!strBirthday.equals(""))
information
+=",birthday="+strBirthday;
if(!strSpeciality.equals(""))
information
+=",专业="+strSpeciality;
if(!strAddress.equals(""))
information
+=",address="+strAddress;
return information;
}

}

}

posted @ 2008-10-23 14:16 郭兴华 阅读(146) | 评论 (0)编辑 收藏
SERVLET(2)

package cn.mldn.lxh.servlet ;
import java.io.* ;
import javax.servlet.* ;
import javax.servlet.http.* ;

public class FormServlet extends HttpServlet
{
    
private ServletConfig config = null ;
    
public void init(ServletConfig config) throws ServletException 
    
{
        
this.config = config ;
    }

    
// 表示处理get请求
    public void doGet(HttpServletRequest req,HttpServletResponse resp) throws IOException,ServletException
    
{
        
// System.out.println("** Servlet doGet处理提交参数 ") ;
        this.doPost(req,resp) ;
    }

    
// 处理post请求
    public void doPost(HttpServletRequest req,HttpServletResponse resp) throws IOException,ServletException
    
{
        String name 
= req.getParameter("uname") ;
        
// 取得application对象
        
// ServletContext app = this.getServletContext() ;
        ServletContext app = this.config.getServletContext() ;
        app.setAttribute(
"addr","www.MLDN.cn") ;
        
// 取得一个session对象
        HttpSession session = req.getSession() ;
        session.setAttribute(
"sname",name) ;
        
// System.out.println("** Servlet doPost处理提交参数 ") ;
        System.out.println("name = "+name) ;
        
// 重定向
        resp.sendRedirect("demo.jsp") ;
    }

}
;

/*
  <servlet>
    <servlet-name>form</servlet-name>
    <servlet-class>cn.mldn.lxh.servlet.FormServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>form</servlet-name>
    <url-pattern>/formServlet</url-pattern>
  </servlet-mapping>
*/
初始化两种方法
有参数与无参数
有参数的方法优先


多个地址可以映射到同一个SERVLET
配置初始化参数

form表单
<form action="formServlet" method="post">
用户名:
<input type="text" name="uname">
<input type="submit" value="提交">
</form>



下面是处理表单的servlet
package cn.mldn.lxh.servlet ;
import java.io.* ;
import javax.servlet.* ;
import javax.servlet.http.* ;

public class InitParameterServlet extends HttpServlet
{
    
// 初始化
    
// 要取得初始化参数,必须使用以下初始化方法
    public void init(ServletConfig config) throws ServletException
    
{
        
// config对象中有取得初始化参数的方法:getInitParameter("参数名称")
        String ref1 = config.getInitParameter("ref1") ;
        String ref2 
= config.getInitParameter("ref2") ;
        String dd 
= config.getInitParameter("DBDRIVER") ;

        System.out.println(
"REF1 => "+ref1) ;
        System.out.println(
"REF2 => "+ref2) ;
        System.out.println(
"DBDRIVER => "+dd) ;
    }


    
// 表示处理get请求
    public void doGet(HttpServletRequest req,HttpServletResponse resp) throws IOException,ServletException
    
{
        
// System.out.println("** Servlet doGet处理 ") ;
    }

    
// 处理post请求
    public void doPost(HttpServletRequest req,HttpServletResponse resp) throws IOException,ServletException
    
{
        
// System.out.println("** Servlet doPost处理 ") ;
    }

    
// 销毁
    public void destroy()
    
{
        
// System.out.println("** Servlet 销毁 ") ;
    }

}
;

/*
  <servlet>
    <servlet-name>param</servlet-name>
    <servlet-class>cn.mldn.lxh.servlet.InitParameterServlet</servlet-class>
    <load-on-startup>0</load-on-startup>
    <init-param>
        <param-name>ref1</param-name>
        <param-value>MLDN</param-value>
    </init-param>
    <init-param>
        <param-name>ref2</param-name>
        <param-value>LiXingHua</param-value>
    </init-param>
    <init-param>
        <param-name>DBDRIVER</param-name>
        <param-value>oracle.jdbc.driver.OracleDriver</param-value>
    </init-param>
  </servlet>

  <servlet-mapping>
    <servlet-name>param</servlet-name>
    <url-pattern>/ipar</url-pattern>
  </servlet-mapping>
*/


学习资料下载

posted @ 2008-10-23 12:36 郭兴华 阅读(141) | 评论 (0)编辑 收藏
SERVLET

SERVLET是一种特殊的CGI
与CGI不同是多线程,性能很高

package cn.mldn.lxh.servlet ;
import java.io.* ;
// HttpServlet属于javax.servlet.http包下
// ServletException属于javax.servlet包下
import javax.servlet.* ;
// HttpServletRequest、HttpServletResponse存放在javax.servlet.http包下
import javax.servlet.http.* ;

public class SimpleServlet extends HttpServlet
{
    
// 表示处理get请求
    public void doGet(HttpServletRequest req,HttpServletResponse resp) throws IOException,ServletException
    
{
        PrintWriter out 
= resp.getWriter() ;
        out.println(
"<HTML>") ;
        out.println(
"<HEAD>") ;
        out.println(
"<TITLE>THE FIRST SERVLET</TITLE>") ;
        out.println(
"</HEAD>") ;
        out.println(
"<BODY>") ;
        out.println(
"<H1>Hello World!!!</H1>") ;
        out.println(
"</BODY>") ;
        out.println(
"</HTML>") ;
        out.close() ;
    }

    
public void doPost(HttpServletRequest req,HttpServletResponse resp) throws IOException,ServletException
    
{
        
this.doGet(request,response) ;
    }

}
;

/*
  <servlet>
    <servlet-name>simple</servlet-name>
    <servlet-class>cn.mldn.lxh.servlet.SimpleServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>simple</servlet-name>
    <url-pattern>/demo</url-pattern>
  </servlet-mapping>
*/

输出 Html用out.println()
很难维护
生命周期
生老病死(与人相似)
package cn.mldn.lxh.servlet ;
import java.io.* ;
import javax.servlet.* ;
import javax.servlet.http.* ;

public class LifeCycleServlet extends HttpServlet
{
    
// 初始化
    public void init(ServletConfig config) throws ServletException
    
{
        System.out.println(
"** Servlet 初始化 ") ;
    }

    
// 表示处理get请求
    public void doGet(HttpServletRequest req,HttpServletResponse resp) throws IOException,ServletException
    
{
        System.out.println(
"** Servlet doGet处理 ") ;
    }

    
// 处理post请求
    public void doPost(HttpServletRequest req,HttpServletResponse resp) throws IOException,ServletException
    
{
        System.out.println(
"** Servlet doPost处理 ") ;
    }

    
// 销毁
    public void destroy()
    
{
        System.out.println(
"** Servlet 销毁 ") ;
    }

}
;

/*
  <servlet>
    <servlet-name>life</servlet-name>
    <servlet-class>cn.mldn.lxh.servlet.LifeCycleServlet</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>life</servlet-name>
    <url-pattern>/lc</url-pattern>
  </servlet-mapping>
*/

init
doservices
destroy
创建要求
继承HttpServlet(先导入javax.servlet.*)必须在包中
在web-inf/class下
重写两个方法
doGet(req,resp)throws IOException(javax.servlet.http.*,java.io.*)
用PrintWriter输出
修改WEB.XML文件,映射SERVLET
<servlet>
<servlet-name>simple</servlet-name>
<servlet-class>cn.mldn.lxh.servlet.SimpleServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>simple</servlet-name>
<url-pattern>/demo</url-pattern>//在地址中输入的内容</servlet-mapping>
笔记下载
servlet只初始一次(在第一次使用servlet程序后,也可以在
容器启动时初始化servlet程序,通过修改web.xml文件)
<load-on-startup>1</load-on-startup>
doGet,doPost(doget是输入地址,doPost是表单请求)
destroy(服务器关闭,或者长时间不用)
注意
开发框架和配置

posted @ 2008-10-23 11:22 郭兴华 阅读(101) | 评论 (0)编辑 收藏
StudentTest1.java

 

/**
* main方法单独设计,编译是不能通过
*/

public class StudentTest1{
public static void main(String[] args)
{
String[] course
={"计算机原理","编译方法","数据结构"};
Student one
=new Student("Tom","20021024");
one.setStudentCourse(course);
}

}


/**
 * 我们设计的学生基本类
 
*/

class Student
{
 
 
private String strName = "";//学生姓名
 private String strNumber = "";//学号
 private String strSex = "";//性别
 private String strBirthday = "";//出生年月
 private String strSpeciality = "";//专业
 private String strAddress = "";//地址

 
public Student(String name, String number)
 
{
  strName 
= name;
  strNumber 
= number;
 }


 
public String getStudentName()
 
{
  
return strName;
 }


 
public String getStudentNumber()
 
{
  
return strNumber;
 }


 
public void setStudentSex(String sex)
 
{
  strSex 
= sex;
 }


 
public String getStudentSex()
 
{
  
return strSex;
 }


 
public String getStudentBirthday()
 
{
  
return strBirthday;
 }


 
public void setStudentBirthday(String birthday)
 
{
  strBirthday 
= birthday;
 }


 
public String getStudentSpeciality()
 
{
  
return strSpeciality;
 }


 
public void setStudentSpeciality(String speciality)
 
{
  strSpeciality 
= speciality;
 }


 
public String getStudentAddress()
 
{
  
return strAddress;
 }


 
public void setStudentAddress(String address)
 
{
  strAddress 
= address;
 }


 
public String toString()
 
{
  String information 
= "学生姓名=" + strName + ", 学号=" + strNumber;  
  
if!strSex.equals("") )
   information 
+= ", 性别=" + strSex;
  
if!strBirthday.equals(""))
   information 
+= ", 出生年月=" + strBirthday;
  
if!strSpeciality.equals("") )
   information 
+= ", 专业=" + strSpeciality;
  
if!strAddress.equals("") )
   information 
+= ", 籍贯=" + strAddress;
  
return information;
 }

public void setStudentCourse(final String[] strCourse){
class Course{
private int courseNumber=strCourse.length;
private void getCourse(){
for(int i=0;i<courseNumber;i++)
{System.out.println("\t"+strCourse[i]);
}

}

public void getDescription(){
System.out.println(
"学生:"+strName+" student number is :"+strNumber+"。一共选了"+courseNumber+"门课,分别是:");
getCourse();
}
}

Course course
=new Course();
course.getDescription();
}

}

posted @ 2008-10-23 10:18 郭兴华 阅读(220) | 评论 (1)编辑 收藏
StaticInnerClass.java

/**
*静态内部类的测试
*/
import java.util.Vector;
public class StaticInnerClass{
public static void main(String[] args){
Vector vec=new Vector();
Student tom=new Student("Tom","20020410");
Student jack=new Student("jack","20020411");
Studentsmith=new Student("Smith ","20020412");
Student rose=new Student("Rose","20020413");
tom.setStudentScore(456);
jack.setStudentScore(500);
smith.setStudentScore(634);
rose.setStudentScore(414);
vec.add(tom);
vec.add(jack);
vec.add(smith);
vec.add(rose);
ArrayScore.PairScore pair=ArrayScore.minMax(vec);
System.out.println("最高分数为:"+pair.getMaxScore());
System.out.println("最低的分数为:")+pair.getMinScore();
}}
class ArrayScore{
static class PairScore{
private double maxScore;
private double minScore;
public PairScore(double max,double min){
maxScore=max;
minScore=min;
}
public double getMaxScore(){
return maxScore;
}
public double getMinScore(){
return minScore;
}
}
public static PairScore minMax(Vector studentVec){
double minScore=((Student)studentVec.get(0)).getStudentScore();
double maxScore=((Student)studentVec.get(0)).getStudentScore();
for(int i=1;i<studentVec.size();i++){
double score=((Student)studentVec.get(i)).getStudentScore();
if(minScore>score)
minScore=score;
if(maxScore<score)
maxScore=score;
}
return new PairScore(maxScore,minScore);
}
}
/**
*我们设计的学生基本类
*/
class Student{
private String strName="";
private Stirng strNumber="";
private Stirng strSex="";
private String strBirthday="";
private String strSpeciality="";
private String strAddress="";
private double totalScore;//学生的总分数
public Student(String name,String number){
strName=name;
strNumber=number;
}
public String getStudentName(){
return strName;
}
public String getStudentNumber(){
return strNumber;
}
public void setStudentSex(String sex){
strSex=sex;
}
public String getStudentSex(){
return strSex;
}
public String getStudentBirthday(){
return strBirthday;
}
public void setStudentBirthday(String birthday){
strBirthday=birthday;
}
public String getStudentSpeciality(){
return strSpeciality;
}
public void setStudentSpeciality(String speciality) {
strSpeciality=speciality;
}
public String getStudentAddress(){
return strAddress;
}
public void setStudentAddress(String address){
strAddress=address;
}
public double getStudentScore(){
return totalScore;
}
public void setStudentScore(double score){
totalScore=score;
}
public String toString(){
String information ="student name="+strName+"student number="+strNumber;
if(!strSex.equals(""))
information+=",sex="+strSex;
if(!strBirthday.equals(""))
information+=",Birthday="+strBirthday;
if(!strSpeciality.equals(""))
information+=",专业="+strSpeciality;
if(!strAddress.equals(""))
information+=",Address="+strAddress;
return information;
}



}

posted @ 2008-10-23 09:40 郭兴华 阅读(117) | 评论 (0)编辑 收藏
Student.java

     摘要: /** *//**  * 我们设计的学生基本类  */ class Student {     private String strName = "";//学生姓名     private String&nb...  阅读全文

posted @ 2008-10-23 00:08 郭兴华 阅读(185) | 评论 (0)编辑 收藏
Person.java

public interface Person{
String getName();
String getSex();
String getBirthday();
String getAddress();
void setAddress(String strAddress);
}

posted @ 2008-10-22 23:57 郭兴华 阅读(90) | 评论 (0)编辑 收藏
ObjectVarTest.java

/**
*测试这个程序,测试对象类型的动态绑定
*/
public class ObjectVarTest
{
public static void main(String[] args){
B b=new B();
C.method3(b);
}
}
class A{
public void method1(){
System.out.println("this is class A method1");
}
}
class B extends A{
public void method1(){
System.out.println("this is class B method1");
public void method2(){
System.out.println("this is class B method2");
}
}
class c{
public static void method3(A a){
a.method1();
}}
}

posted @ 2008-10-22 23:53 郭兴华 阅读(73) | 评论 (0)编辑 收藏
ObjectTypeTest.java

 

/**
*通过这个程序,测试对象类型的多态实现
*/

public class ObjectTypeTest{
public static void main(String[] args){
B a
=new B();
a.method2();
}
}

class A{
public void method1(){
System.out.println(
"this is class A method1");}
}

class B extends A{
public void method1(){
System.out.println(
"this is class B method1");}

public void method2(){
System.out.println(
"this is class B method2");}

}

posted @ 2008-10-22 23:46 郭兴华 阅读(96) | 评论 (0)编辑 收藏
BasicTypeTest.java

/**
*测试基本类型的类型转换
*/

public class BasicTypeTest{
public static void main(String[] args){
int a=10;
long b=a;
System.out.println(
"the value of b is "+b);
}

}

posted @ 2008-10-22 23:38 郭兴华 阅读(68) | 评论 (0)编辑 收藏
ArrayListTest.java

/**
*i测试数组列表的使用
*/
import java.util.ArrayList;
public class ArrayList{
public static void main(String[] args){
ArrayList list=new ArrayList();
list.add(new Student("Tom","20020410"));
list.add(new Student("Jack","20020411"));
list.add(new Student("Rose","20020412"));
for(int i =0;i<list.size();i++)
{
System.out.println((Student)list.get(i));
}}}
class Student {
private String strName="";
private String strNumber="";
private String strSex="";
private String strBirthday="";
private String strAddress="";
public Student(String name,String number){
strName=name;
strNumber=number;
}
public String getStudentName(){
return strName;
}
public String getStudentNumber() {
return strNumber;
}
public String setStudentSex(String sex)
{
strSex=sex;
}
public String getStudentSex(){
return strSex;
}
public String getStudentBirthday(){
return strBirthday;
}
public void setStudentBirthday(String birthday){
strBirthday=birthday;
}
public String getStudentSpeciality(){
return strSpeciality;}
public void setStudentSpececiality(String speciality){
strSpeciality=speciality;
}
public void setStudentAddress(String address){
strAddress=address;
}
public String toString(){
String information="student name="+strName+",student number="+strNumber;
if(!strSex.equals(""))
information+=",sex="+strSex;
if(!strBirthday.equals(""))
information+=",birthday="+strBirthday;
if(!strSpeciality.equals(""))
information+=",专业="+strSpeciality;
if(!strAddress.equals(""))
information+=",籍贯="+strAddress;
return information;
}
}

posted @ 2008-10-22 23:33 郭兴华 阅读(132) | 评论 (0)编辑 收藏
DAO设计模式

产生的原因
JDBC不能出现在JSP页面中
什么是DAO
J2EE组件层次
客户端——》表示层--》业务层--》数据层(DAO)

--delete
DROP TABLE person;
--create 
CREATE TABLE person{
}
--ts
commit;


异常 的处理通常由调用它的方法来处理

posted @ 2008-10-22 23:03 郭兴华 阅读(121) | 评论 (0)编辑 收藏
MVC设计模式

jsp+javabean开发(jsp接收参数,调用 javaBean)

开发速度快,有一个问题,藕合性高,维护困难

一个人开发使用,人多了不好控制

jsp+DAO设计模式

jsp+servlet+javabean(servlet调用javabean)

jsp:UI

javaBean:重复调用

servlet:安全性高性能也高,

jsp两种跳转方式

  1. response.sendRedirect():客户端跳转,请求不保存
  2. <jsp:forward page="">:服务器端跳转,请求要保存

 

 

 

jsp中有四种属性范围:page ,response,application,session

package cn.mldn.lxh.servlet ;

import java.io.* ;
import javax.servlet.* ;
import javax.servlet.http.* ;
import cn.mldn.lxh.bean.MVCCheck ;

public class MVCServlet extends HttpServlet
{
    
public void doGet(HttpServletRequest req,HttpServletResponse resp) throws IOException,ServletException
    
{
        
this.doPost(req,resp) ;
    }

    
public void doPost(HttpServletRequest req,HttpServletResponse resp) throws IOException,ServletException
    
{
        String name 
= req.getParameter("uname") ;
        MVCCheck mc 
= new MVCCheck() ;
        
// 将请求内容设置到mc对象之中
        mc.setName(name) ;
        String path 
= null ;
        
if(mc.isValidate())
        
{
            
// 保存名字在request范围之中
            req.setAttribute("name",mc.getName()) ;
            path 
= "mvc_success.jsp" ;
        }

        
else
        
{
            path 
= "mvc_failure.jsp" ;
        }

        
// 进行跳转
        req.getRequestDispatcher(path).forward(req,resp) ;//向下传
    }

}
;
/*
  <servlet>
    <servlet-name>mvc</servlet-name>
    <servlet-class>cn.mldn.lxh.servlet.MVCServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>mvc</servlet-name>
    <url-pattern>/mvcdemo.mldn</url-pattern>
  </servlet-mapping>
*/
servlet传值传不过去,用Session传,但是Session占用空间
解决方法:Dispatcher


本章资料下载
PDF笔记

posted @ 2008-10-22 21:22 郭兴华 阅读(130) | 评论 (0)编辑 收藏
jsp标签库编程


笔记下载
代码下载地址:
/Files/guohua/TaglibProject.rar
hello.java
package org.lxh.demo01;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

public class Hello extends TagSupport {

    @Override
    
public int doStartTag() throws JspException {
        
// 向JSP页面中打印“www.mldn.cn”的字符串
        String str = "www.mldn.cn" ;
        
// 在Servlet里如果要打印,则要使用PrintWriter
        
// 如果在标签库中打印需要使用pageContext
        JspWriter out = pageContext.getOut() ;
        
try {
            out.println(str);
        }
 catch (IOException e) {
            e.printStackTrace();
        }

        
// 只要打印完了字符传,则后面的代码就不需要执行了
        return TagSupport.SKIP_BODY;
    }


}


hello.jsp
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/WEB-INF/hello.tld" prefix="lxh"%>
<html>
  
<head>
    
<title>My JSP 'hello.jsp' starting page</title>
    
<!--
    
<link rel="stylesheet" type="text/css" href="styles.css">
    
-->

  
</head>
  
  
<body>
    
<h1><lxh:mldn/></h1>
  
</body>
</html>
helloxml.jsp
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/WEB-INF/hello.tld" prefix="lxh"%>
<html>
  
<head>
    
<title>My JSP 'hello.jsp' starting page</title>
    
<!--
    
<link rel="stylesheet" type="text/css" href="styles.css">
    
-->

  
</head>
  
  
<body>
    
<h1><lxh:mldn/></h1>
  
</body>
</html>
hello.tld
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" "web-jsptaglibrary_1_2.dtd" >
<taglib>
    
<tlib-version>1.0</tlib-version>
    
<jsp-version>2.0</jsp-version>
    
<short-name>hello</short-name>
    
<tag>
        
<name>mldn</name>
        
<tag-class>org.lxh.demo01.Hello</tag-class>
        
<body-content>empty</body-content>
    
</tag>
</taglib>

posted @ 2008-10-22 19:20 郭兴华 阅读(163) | 评论 (0)编辑 收藏
jdbcorache.jsp

<%@ page contentType="text/html;charset=gb2312"%>
<%@page import ="java.sql.*"%>
<%--
使用JDBC连接Oracle数据库
使用MLDN数据库
用户名:scott
密码:tiger
--%>
<%!
String DBDRIVER="oracle.jdbc.driver.OracleDriver";
String DBURL="jadb:oracle:thin:@localhost:1521:mldn";
String DBUSER="scott";
String DBPASSWORD="tiger";
Connection conn=null;
statement stmt=null;
%>
<%try{Class.forname(DBDRIVER);
conn=DriverManger.getConnection(DBURL,DBUSER,DBPASSWORD);
//create table
String sql="CREATE TABLE mldnab(name vachar(20))";
stmt=conn.createStatement();
stmt.executeUpdate(sql);
stmt.close();
conn.close();
}catch(Exception e){
out.println(e);

}


posted @ 2008-10-22 16:37 郭兴华 阅读(75) | 评论 (0)编辑 收藏
ConstructorTest

/**
*测试类构造器的调用顺序
*/
public class ConstructorTest{
public static void main(String[] args){
C c=new C("hello");
}
}
class A{
public A(){
System.out.println("this is A");
}
}
class C extends B{
public C(String str){
super(str);
System.out.println("this is C");
}
}


posted @ 2008-10-22 13:49 郭兴华 阅读(123) | 评论 (0)编辑 收藏
ToStringTest.java

public class ToStringTest{
public static void main(String[] args){
System.out.println(new Student("youName","20031001"));
}
}

posted @ 2008-10-22 13:41 郭兴华 阅读(102) | 评论 (0)编辑 收藏
SubStringTest.java

/**
*通过这个程序,展示字符串求取子串的方法
*/
public class SubStringTest{
public static void main(String[] args){
String str="I am a Programmer";//定义字符串
for(int i=0;i<str.length();i++){
System.out.println("这是第"+i+"个子串:"+str.subString(i));
}}}

posted @ 2008-10-22 13:38 郭兴华 阅读(154) | 评论 (0)编辑 收藏
InputTest.java

/**
*读取键盘输入
*/
import javax.swing.JOptionPane;
public class InputTest{
public static void main(String[] args){
String strName=JOptionPane.showInputDialog("Input your name:");
String strAge=JOptionPane.showInputDialog("Input your age:");
int age=Integer.parseInt(strAge);
System.out.println("Welcome you :"+strName);
System.out.println("你还有"+(60-age)+"年可以退休了!!");
System.exit(0);
}
}

posted @ 2008-10-22 13:30 郭兴华 阅读(130) | 评论 (0)编辑 收藏
FormateValue.java

/**
*通过这个程序,测试格式器的使用方法
*/
import java.text.NumberFormat;
import java.util.locale;
public class FormateValue{
public static void main(String[] args){
double x=100000.0/3;
System.out.println("the value is :"+x);
//首先以默认地区的格式器来输出
System.out.println("接下来输出的是美国地区的格式器的结果:");
NumberFormat number=NumberFormat.getNumberInstance(Locale.US);
NumberFormat number=NumberFormat.getCurrencyInstance(Locale.US);
NumberFormat percent=NumberFormat.getPercentInstance(Locale.US);


FormatValue fm=new FormatValue();
fm.print(number,x);
fm.print(currency.x);
fm.print(percent,x);

System.out.println("接下来输出的是默认地区的格式器的结果:");
NubmerFormat nu=NumberFormat.getNumberInstance();
NubmerFormat cu=NumberFormat.getCurrencyInstance();
NubmerFormat be=NumberFormat.getPercentIntstance();
fm.print(nu,x);
fm.print(cu,x);
fm.print(pe,x);
}
public void print(NubmerFormat nu,double x){
System.out.println(nu.format(x));
}
}

posted @ 2008-10-22 13:21 郭兴华 阅读(174) | 评论 (0)编辑 收藏
FindSubstring.java

/**
*查找特定的子串
*/
public class FindSubstring{
public static void main(String[] args){
String str="Welcome the body.";
System.out.println("Find the substring boy occurrence:"+str.indexOf("boy"));//查找子串
System.out.println("Find the substring by occurrence: "+str.indexOf("by"));//查找子串
System.out.println("Find the char t occurrence: "+str.indexOf('t'));//查找特定的字符
System.out.println("Test the string begin with wel.:"+str.startsWith("wel"));//是否以"wel"开始
System.out.pritnln("Test the string end with body.:"+str.endWith("boy"));//是否以"boy"结束
}
}

posted @ 2008-10-22 13:06 郭兴华 阅读(190) | 评论 (0)编辑 收藏
CommandInput.java

/*
*命令行参数的输入,从命令行输入的任何参数,对于java来讲都是用字符串处理的
*/
public class CommandInput{
public static void main(String[] args){
if(args.length==0){
System.out.println("你没有输出参数,程序退出");

}

else{
System.out.println("你一共输入了"+args.length+"个参数");
if(args[0].equals("h"))
System.out.print("hello");
if(args[0].equals("g"))
System.out.print("Bye-Bye");



for(int i=1;i<args.length;i++)
{
System.out.print("  "+args[i]);

}
}
}
}

posted @ 2008-10-22 08:20 郭兴华 阅读(138) | 评论 (0)编辑 收藏
CapacityTest.java

public class CapacityTest{
public static void main(String[] args){
String buffer sb=new StringBuffer(10);
sb.append("this is a a");
System.out.println(sb.capacity());
System.out.println(sb.length());
}
}

posted @ 2008-10-22 07:57 郭兴华 阅读(83) | 评论 (0)编辑 收藏
ArraySort.java

/*
*数组排序及随机数的产生
*/
import java.util.Arrays;
import javax.swing.*
public class ArraySort{
public static void main(String[] args){
String strIn=JoptionPane.showInputDialog("请输入工共多少个彩球:");
String strOut=JOptionPane.showInputDialog("请输入需抽取多少个彩球:");
int in=Integer.parseInt(strIn);
int[] total=new int[in];//生成彩球总数数组
for(int i=0;i<in;i++){
total[i]=i+1;
}
int[] out=new int[Integer.parseInt(strOut)];
for(int i=0;i<out.length;i++){
int r=(int)Math.random()*in;//产生随机元素序列号
out[i]=total[r];
total[r]=total[in-1];//将最后一个元素移到当前位置,把取出的删除
in--;

System.out.print(" "+out[i]);}
Arrays.sort(out);
System.out.println("抽取的数字排序后是:");
for (int i=0;i<out.length;i++){
System.out.print(" "+out[i]);
}
System.exit(0);
}}

posted @ 2008-10-22 07:49 郭兴华 阅读(472) | 评论 (0)编辑 收藏
ArrayTest.java

/**
*通过这个程序,我们要测试两个方面:
*1.匿名数组可以赋值与一个已经存在数组变量,不关心原来数组变量的容量
*2.数组变量的类型必须要与匿名数组的类型一致




public class ArrayTest{
public static void main(String[] args){
ArrayTest aTest=new ArrayTest();
int[] a={1,2,3};//声明一个新的数组,并赋值与一个新的数组变量
aTest.aprint(a);
a=new int[]{10,20,30,40,50};//将匿名数组赋值与存在的数组变量a
//a=new String[]{"a","b"};//将字符型匿名数组赋值与存在的数组变量a
aTest.print(a);
}
public void print(int[] array){
System.out.println(" 数组变量的长度是 "+array.length);
System.out.println(" 数组中的每一个元素是:");

for(int i=0;i<array.length;i++)
{
System.out.print(" "+array[i]);//打印出数组中的每一个元素
}System.out.println("\n*************");
}
}

posted @ 2008-10-22 07:26 郭兴华 阅读(86) | 评论 (0)编辑 收藏
ArrayPointer.java

/**
*测试数组元素传递方式
*/
public class ArrayPointer{
public static void main(String[] args){
ArrayPointer aPointer=new ArrayPinter();
int[] a={1,2,3,4,5};
System.out.println(打印数组a中的元素);
aPointer.print(a);
int[] b=a;
System.out.println("\n改变数组b中的第三个元素的值。\n ");
System.out.println("打印数组b中的元素。");
b[2]=a[2]+10;
aPointer.print(b);
System.out.println("再打印数组a中的元素。");
aPointer.print(b);
}
public void print(int[] array){
for(int i=0;i<array.length;i++){
System.out.println("  "+array[i]);//打印出数组中的每一个元素
}
System.out.println("\n*******************8");

}}

posted @ 2008-10-22 07:08 郭兴华 阅读(65) | 评论 (0)编辑 收藏
ArrayInitTest.java

/**
*通过这个程序,测试数组元素默认值
*/
public class ArrayInitTest{
public static void main(String[] args)
{
ArrayInitTest aTest=new ArrayInitTest();
int[] a=new int[10];//声明一个新的整数数组,并赋值与一个新的数组变量
aTest.println(a);//输出数组元素到控制台
boolean[] c=new boolean[10];//声明一个新的布尔数组
aTest.pprintln(c);
}
public void printInt(int[] array){
System.out.println(" 整数型数组的长度是 "+array.length);
for(int i=0;i<5;i++){
array[i]=i;
}
System.out.println(" 数组中的每个元素是: ");
for(int i=0;i<array.length;i++){
System.out.println("  "+array[i]);//打印出数组中的每一个元素
}
System.out.println("\n******************************");
}
public void printString(String[] array){
System.out.println(" 字符型数组的长度是 "+array.length);
for(int i=0;i<5;i++){
array[i]="元素"+i;
}
System.out.println(" 数组中的每个元素是: ");
for(int i=0;i<array.length;i++){
System.out.println(" "+array[i]);//打印出数组中的每一个元素
}
System.out.println("\n****************************");
}
public void printBoolean(boolean[] array){
System.out.println(" 布尔型数组的长度是 "+array.legnth);
for(int i=0;i<5;i++){
if(i%2==0)
array[i]=true;
else
array[i]=false;
}
System.out.println(" 数组中的每个元素是: ");
for (int i=0;i<array.length;i++){
System.out.print("  "+array[i]);//打印出数组中的每一个元素
}
System.out.println("\n**********************************");

}}

posted @ 2008-10-22 06:30 郭兴华 阅读(135) | 评论 (0)编辑 收藏
ArrayCopy.java

/**
*测试数组元素的拷贝
*/
public class ArrayCopy{
public static void main(String[] args){
ArrayCopy aCopy=new ArrayCopy();
int[] a={1,2,3,4,5};
int[] b={10,20,30,40,50};
aCopy.copy(a,b);
}
public void copy(int[] from,int[] to){
System.out.println("第一个数组中的元素");
for(int i=0;i<from.length;i++){
System.out.println("   "+from[i]);
}System.out.println("\n");
System.out.println("第二个数组中的元素");
for(int i=0;i<to.length;i++){
System.out.println("   "+to[i]);//打印出数组中的每一个元素
}
System.out.println("\n\n将第一个数组拷贝到第二个数组\n");
System.arraycopy(from,2,to,0,3);
System.out.println("拷贝完成后第二个数组中的元素");
for(int i=0;i<to.length;i++){
System.out.println("  "+to[i]);//打印出数组中的每一个元素}}}

posted @ 2008-10-21 21:13 郭兴华 阅读(257) | 评论 (0)编辑 收藏
StudentTest3.java

public class StudentTest3{
public static void main(String[] args){
Student tom=new Student("Tom","20020410");
tom.setStudentSex("man");
tom.setSutdentAddress("America");
System.out.println(tom.toString());
}
}
class Student{
private String strName="";
private String strNumber="";
private String sexSex="";
private String strBirthday="";
private String strSpeciality="";
private String strAddress="";
public static void main(String[] args){
Student aStudent=new Student("沙和尚","19990000");
aStudent.setStudentAddress("通天河");
System.out.println(aStudent.toString());
}
public Student (String name,String number){
strName=name;
strNumber=number;
}
public String getStudentName(){
return strName;
}
public void setStudentSex(String sex){
strSex=sex;
}
public  String getStudentSex(){
return strSex;
}
public String getStudentBirthday(){
return strBirthday;
}
public void setStudentSpciality(String speciality){
strSpeciality=speciality;
}
public String getStudentAddress(){
return strAddress;
}
public void setStudentAddress(String address) {
strAddress=address;
}

public String toString(){
String information="学生姓名="+strName+",学号="+strNumber;
if(!strSex.equals("")){
information+=",性别="+strSex;
if(!strBirthday.equals(""))
information+=", 出生年月="+strBirthday;
if(!strSpeciality.equals(""))
information+=",专业="+strSpeciality;
if(!strAddress.equals(""))
information+=",籍贯="+strAddress;
return information;
}
}
   }

posted @ 2008-10-21 20:56 郭兴华 阅读(107) | 评论 (0)编辑 收藏
StudentTest2.java

/*
*学生类,包括学生的基本信息
*/
public class studentTest2{
public static void main(String[] args){
int i;
for(i=0;i<10;i++) {
Student tom=new Student("Tom"+i);
if(i%2==0){
tom.setStudentSex("man");
}else{
tom.setStudentSex("female");
}
tom.setStudentAddress("America");
tom.setStudentNumber();
System.out.println(tom.toString());
}}}
class Student{
private String strName="";
private int number=0;
private String strSex="";
private String strBirthday="";
private String strSpeciality="";
private String strAddress="";
private Static int nextNumber=1;
public Student(String name){
strName=name;
}
public String getStudentName(){
return strName;
}
public int getStudentNumber(){
return number;
}
public void setStudentNumber(){
number=nextNumber;
nextNumber++;
}
public void setStudentSex(String sex){
strSex=sex;
}
public String getStudentBirthday(){
return strBirthday;
}
public void setStudentBirthday(String birthday){
strBirthday=birthday;
}
public String getStudentSpeciality(){
return strSpciality;
}
public void setStudentSpeciality(String speciality){
strSpeciality=speciality;
}
public String getStudentAddress(){
return strAddress;
}
public String toString (){
String information="student name="+strName+",student number="+number;
if(!strSex.equals(""))
information +=",sex="+strSex;
if(!strBirthday.equals(""))
information+=",birthday="+strBirthday;
if(!strSpeciality.equals(""))
information+=",专业="+strSpeciality;
if(!strAddress.equals(""))
information+=",籍贯="+strAddress;
return information;
}}

posted @ 2008-10-21 20:25 郭兴华 阅读(150) | 评论 (0)编辑 收藏
StudentTest1.java

/*
*学生类,包括学生的基本信息
*/
public class StudentTest1{
public static void main(){
Student1 tom=new Student1("Tom","20020410");
Student2 jack=new Student2("jack","20030911");
System.out.println(jack.toString());
System.out.println("通过公开字段,修改实例字段值。")
//tom.strName='唐僧";
jack.strName="孙悟空";
System.out.println(jack.toString());
}}
 class Student1{
private String strName="";
private String strNumber="";
public Student1(String name,String number){
strName=name;
strNumber=number;
}
public String getStudentName(){
return strName;
}
public String getStudentNumber(){
return strNumber;
}
public String toString(){
return "student="+strName+",student number="+strNumber;
} }
class Student2{
public String strName="";
public String strNuber="";
public Student2(String name,String number){
strName=name;
strNumber=number;
}
public String getStudentName(){
return strName;}
public String getStudentNumber(){
return strNumber;
}
public String toString(){
return "学生姓名="+strName+",学号="+strNumber;
}
}

posted @ 2008-10-21 19:16 郭兴华 阅读(72) | 评论 (0)编辑 收藏
StaticMothed.java

 /*
*静态方法访问实例字段及静态字段
*/
public class StaticMethod(){
static int a=15;
static int b=2;
public static void main(String[] args)
{
System.out.println(a+"/"+b+"="+(a/b));
}
}

posted @ 2008-10-21 18:38 郭兴华 阅读(82) | 评论 (0)编辑 收藏
StudentTest.java

/*
*学生类,包括学生类的基本信息
*/
public class StudentTest{
public static void main(String[] args)
{
Student tom=new Student("Tom","20020410");
tom.setStudentSex("man");
tom.setStudentAddress("America");
System.out.println(tom.toString());
}
}
class Student{
private String strName=";
private String strNumber="";
private String strSex="";
private String strSpeciality="";
private String strAddress="";
public Student(String name,String number){
strName=name;
strNumber=number;
}
public String getStudentName(){
return strName;
}
public String getStudentNumber(){
return strNumber;
}
public String getStudentSex(){
return strStudentSex;
}
public String setStudentSex(String sex)
{
strSex=sex;
}
public String getStudentBirthday(){
return strBirthday;
}
public void setStudentBirthday(String birthday){
strBirthday=birthday;
}
public String getStudentSpeciality()
{
return strSpeciality;
}
public void setStudentSpeciality(){
strSpeciality=speciality;
}
public String getStudentAddress(){
return strAddress;
}
public void setStudentAddress(String address){
strAddress=address;
}
public String toString(){
String information ="student name="+strName+",student number ="+strNumber;
if(!strSex.equals(""))
information+=",sex="+strSex;
if(!strBirthday.equals(""))
information+=",birthday ="+strBirthday;
if(!strAddress.equals(""))
information+=",address="+strAddress;
return information;
}

}

}

posted @ 2008-10-21 18:16 郭兴华 阅读(210) | 评论 (0)编辑 收藏
StudentOverloading.java

/*
*学生类的重载
*/
public class StudentOverloading{
public static void main(String[] args){
Student tom=new Student("Tom");
}}

/*
*学生类,包括学生的基本信息
*/
public static void main(String[] args){
S}
class Student{
private String strName="";
private String strNumber="";
private String strSex="";
private String strBirthday="";
private String strSpciality="";
private String strAddress="";
public Student(String name,Stirng number){
strName=name;
StrNumber=number;}
public String getStudentName(){
return strName;
}
public String getStudentNumber(){
return strNumber;
}
public String setStudentSex(String sex){
srtSex=sex;
}
public String getStudentSex(){
return strSex;
}
public String getStudentBirthday(){
return strBirthday;
}
public void setStudentBirthday(String birthday){
strBirthday=birthday;}
public String getStudentSpeciality(){
teturn strSpeciality;
}
public void setStudentSpeciality(String speciality){
strSpeciality=speciality;
}
public String getStudentAddress(){
return strAddress;
}
public void set}

posted @ 2008-10-20 14:33 郭兴华 阅读(83) | 评论 (0)编辑 收藏
StaticMethod.java

/*
*静态方法访问实例字段及静态字段
*/
public class StaticMethod{
static int a=15;
static int b=2;
public static void main(String[] args){
System.out.println(a+"/"+b+"="+(a/b));
}}

posted @ 2008-10-20 13:51 郭兴华 阅读(58) | 评论 (0)编辑 收藏
MathTest.java

/*
*Math类数学函数的运用,由于Math类中的方法全部是静态的,所以可以直接利用类名调用
*/
public class MathTest{
public static void main(String[] args){
double x=4.51;
System.out.println(Math.sqrt(x));
System.out.println(Math.round(x));
}}

posted @ 2008-10-20 13:44 郭兴华 阅读(85) | 评论 (0)编辑 收藏
InstanceTest.java

/*
*访问同名的实例字段 和局部变量
*/
public class InstanceTest{
private int a=10;
public static void main(String[] args){
new InstanceTest().print();
}
public void print(){
int a =15;
int b=10;
if(b==10){
System.out.println("局部变量 a="+a);
System.out.println("实例字段变量a ="+this.a);
}
}
}

posted @ 2008-10-20 13:39 郭兴华 阅读(67) | 评论 (0)编辑 收藏
InitObject.java

/*
*对象变量的初始化
*/
import java.util.Date;
public class InitObject{
private Date today;//构建一个对象变量
public static void main(String[] args){
new InitObject().print();
}
public void print(){
System.out.println(today.toString());
}
}

posted @ 2008-10-20 13:34 郭兴华 阅读(122) | 评论 (0)编辑 收藏
ImportTest.java

/*
*包名的引用
*/
import java.util.Date;
public class ImportTest{
public static void main(String[] args){
System.out.println(new Date());
}}

posted @ 2008-10-20 13:29 郭兴华 阅读(51) | 评论 (0)编辑 收藏
FormateDateOutput.java

/*
*日历按照格式输出
*/
import java.util.Calendar;
import java.swing.JOptionPane;
import java.text.SimpleDateFormat;
public class FormatDateOutput{
private int year;
public static void main(String[] args){
String input=JOptionPane.showInputDialog("请输入有效的年分(YYYY):");
int year1=Integer.parseInt(input);//将字符串转化为整数
FormateDateOutput out=new FormateDateOutput();
out.setYear(year1);
if(year1!=0&&input.length()==4)
{
out.FormateDateStr();
}else{
System.out.println("输入的年份无效。");
}System.exit(0);}
public void FormateDateStr(){
SimpleDateFormat formatter=(SimpleDateFormat)SimpleDateFormat.getDateInstance();
formatter.applyPattern("yyyy-MM-dd");
Calendar cal=Calendar.getInstance();
for(int i=0;i<12;i++){
cal.set(year,i,1);
int temp=cal.getActualMaxmum(Calendar.DAY_OF_MONTH);
for (int j=1;j<=temp;j++){
cal.set(year,i,j);
String str=formatter.format(cal.getTime());
System.out.println("当前的时间是:"+str);}}}
public void setYear(int year){
this.year=year;
System.out.println("the year is "+this.year);
}
public int getYear(){
return year;}}

posted @ 2008-10-20 13:24 郭兴华 阅读(79) | 评论 (0)编辑 收藏
CalendarTest.java

/*
*GregroianCalendar类的设置器与访问器
*/
import java.util.*;
public class CalendarTest{
public static void main(String[] args){
new CalendarTest().print();
}
public void print(){
Calendar calendar=new GregorianCalendar();
Date TrialTime=new Date();
Calendar.setTime(trialtTime);
System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
System.out.println("DATE: "+ calendar.get(Calendar.DATE));
System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));
System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY));
System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
System.out.println("Current Time, with hour reset to 3");
calendar.clear(Calendar.HOUR_OF_DAY); // so doesn't override
calendar.set(Calendar.HOUR, 3);
System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
System.out.println("DATE: " + calendar.get(Calendar.DATE));
System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
System.out.println("DAY_OF_YEAR: "+ calendar.get(Calendar.DAY_OF_YEAR));
System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
System.out.println("HOUR: "+ calendar.get(Calendar.HOUR));
System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY));
System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND)); }}

posted @ 2008-10-20 13:01 郭兴华 阅读(227) | 评论 (0)编辑 收藏
BigIntegerTest.java

/*

*用户输入两个数字,程序将通知你中奖的机率有多大
*/
import javax.swing.*;
import java.math.*;
public class BigIntegerTest{
public static void main(String[] args){
String input =JoptionPane.showInputDialog("请输入彩球总数:");
int n=Inter.parseInt(input);//将字符串转化为整数
/*中奖计算公式
(n*(n-1)*(n-2)*...*(n-m+1))/(1*2*...*m)
*/
BigInteger option =BigInteger.valueOf(1);
for(int i=0;i<m;i++){
option=option.multiply(BigInteger.valueOf(n-i)).divide(BigInteger.valueOf(i+1));}
System.out.println("你的中奖机率为每" + option + "次中有一次!"); System.out.println("祝你好运!"); System.exit(0); }}

posted @ 2008-10-20 12:47 郭兴华 阅读(105) | 评论 (0)编辑 收藏
java1.6省去了包装类

import java.util.*;
public class BaoZhuang{
    public static void main(String[] args)
    {
        Vector a=new Vector();
        a.add("123");
        a.add(244);
    }
}
这样写在1.4运行环境下,是不能通过的
但在1.6运行环境下,却可以。

posted @ 2008-10-16 08:21 郭兴华 阅读(182) | 评论 (0)编辑 收藏
测试自增、自减操作

/*
*测试自增、自减操作
*/
public class SelfAction
{
 public static void main(String[] args)
 {
  int x = 10;
  int a = x + x++;
  System.out.println("a=" + a);
  System.out.println("x=" + x);
  int b = x + ++x;
  System.out.println("b=" + b);
  System.out.println("x=" + x);
  int c = x + x--;
  System.out.println("c=" + c);
  System.out.println("x=" + x);
  int d = x + --x;
  System.out.println("d=" + d);
  System.out.println("x=" + x); 


 }
}
输出 是
a=20
x=11
b=23
x=12
c=24
x=11
d=21
x=10

posted @ 2008-10-13 07:06 郭兴华 阅读(115) | 评论 (0)编辑 收藏