數(shù)據(jù)加載中……

          java1.5注解(一)

           

           

          由來(lái)

          減少代碼和程序錯(cuò)誤的發(fā)生
          C#中的也有這種情況

          對(duì)java程序沒有直接影響,
          內(nèi)置注解
          Override
          Deprecated
          SuppressWarnings

          //對(duì)學(xué)框架有幫助
          通過(guò)程序來(lái)說(shuō)明

          注意override與overload區(qū)別
          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 郭興華 閱讀(563) | 評(píng)論 (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="....."%>//用于多個(gè)包的導(dǎo)入
          <%!
          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%>

          <%%>這種是代碼段,在這里聲明的方法和變量是在局部的
          <%!%>這種是聲明語(yǔ)句,在這里聲明的變量和方法是全局的
           <%=%>這種是表達(dá)式

          posted @ 2008-10-25 11:55 郭興華 閱讀(236) | 評(píng)論 (0)編輯 收藏
          VectorTest.java(待寫.....)

          /**
           * 通過(guò)這個(gè)程序,測(cè)試Vector的添加元素及插入元素
           
          */

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

          posted @ 2008-10-23 16:09 郭興華 閱讀(80) | 評(píng)論 (0)編輯 收藏
          VectorTest2.java

           

          /**
          *通過(guò)這個(gè)程序,測(cè)試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(
          "第一個(gè)Vector中的元素分別是:");
          test.display(vec1);
          vec2.add(rose);
          vec2.add(tom);
          System.out.println(
          "\n第二個(gè)Vector中的元素分別是:");
          test.display(vec2);
          System.out.println(
          "\n調(diào)用retainAll方法后,第一個(gè)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 郭興華 閱讀(101) | 評(píng)論 (0)編輯 收藏
          VectorTest2.java

           

          /**
          *通過(guò)這個(gè)程序,測(cè)試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(
          "第一個(gè)Vector中的元素分別是:");
          test.display(vec1);
          vec2.add(rose);
          vec2.add(tom);
          System.out.println(
          "\n第二個(gè)Vector中的元素分別是:");
          test.display(vec2);
          System.out.println(
          "\n調(diào)用retainAll方法后,第一個(gè)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 郭興華 閱讀(102) | 評(píng)論 (0)編輯 收藏
          VectorTest1.java(數(shù)據(jù)結(jié)構(gòu)練習(xí))

          /**
          *通過(guò)這個(gè)程序,測(cè)試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 郭興華 閱讀(95) | 評(píng)論 (0)編輯 收藏
          AbstractTest.java

           

          /**
           * 通過(guò)本程序的測(cè)試,主要學(xué)習(xí)抽象類及子類,抽象方法的實(shí)現(xiàn)
           * 動(dòng)態(tài)綁定,多態(tài)
           
          */

          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();
          }

          /**
           * 工人類,擴(kuò)展了抽象類,并實(shí)現(xiàn)了抽象方法
           
          */

          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);
          }


          }

          /**
           * 學(xué)生類,擴(kuò)展了抽象類,實(shí)現(xiàn)了抽象方法
           
          */

          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 郭興華 閱讀(130) | 評(píng)論 (0)編輯 收藏
          MuilInterfaceTest.java

           

          /**
          *通過(guò)這個(gè)程序,我們要測(cè)試接口的多重實(shí)現(xiàn),并學(xué)習(xí)對(duì)象比較方法的實(shí)現(xiàn)
          */

          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]);
          }
          }
           }


          /*
          *學(xué)生類,包括學(xué)生的基本信息,實(shí)現(xiàn)了Person與Comparable接口
          */

          class Student implements Person, Comparable
          {
           
          private String strName = "";//學(xué)生姓名
           private String strNumber = "";//學(xué)號(hào)
           private String strSex = "";//性別
           private String strBirthday = "";//出生年月
           private String strSpeciality = "";//專業(yè)
           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
          +=",專業(yè)="+strSpeciality;
          if(!strAddress.equals(""))
          information
          +=",address="+strAddress;
          return information;}
          }

          posted @ 2008-10-23 15:02 郭興華 閱讀(125) | 評(píng)論 (0)編輯 收藏
          CloneTest2.java

               摘要:   /**//* *測(cè)試包含對(duì)象的克隆及clone方法的重寫 */ import java.util.GregorianCalendar; import java.util.Date; public class CloneTest{ public static void main(String[]&nbs...  閱讀全文

          posted @ 2008-10-23 14:40 郭興華 閱讀(147) | 評(píng)論 (0)編輯 收藏
          CloneTest.java

           

          /**
          *i測(cè)試對(duì)象的克隆及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);
          }

          }

          /*
           * 學(xué)生類,包括學(xué)生的基本信息,實(shí)現(xiàn)了Cloneable接口
           
          */

          class Student implements Cloneable
          {
           
          private String strName = "";//學(xué)生姓名
           private String strNumber = "";//學(xué)號(hào)
           private String strSex = "";//性別
           private String strBirthday = "";//出生年月
           private String strSpeciality = "";//專業(yè)
           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
          +=",專業(yè)="+strSpeciality;
          if(!strAddress.equals(""))
          information
          +=",address="+strAddress;
          return information;
          }

          }

          }

          posted @ 2008-10-23 14:16 郭興華 閱讀(151) | 評(píng)論 (0)編輯 收藏
          僅列出標(biāo)題
          共9頁(yè): 上一頁(yè) 1 2 3 4 5 6 7 8 9 下一頁(yè) 
          主站蜘蛛池模板: 栾城县| 乐清市| 南靖县| 美姑县| 曲水县| 安庆市| 游戏| 壤塘县| 林州市| 景谷| 湖北省| 维西| 临西县| 庐江县| 济南市| 夏邑县| 鱼台县| 桂阳县| 商河县| 顺昌县| 滨海县| 宝清县| 库尔勒市| 公主岭市| 达孜县| 邵阳市| 定南县| 黄陵县| 灌云县| 当雄县| 金坛市| 息烽县| 乌审旗| 横山县| 响水县| 上饶市| 昌都县| 岐山县| 尚义县| 临清市| 天门市|