java技術博客

          jsp博客
          數據加載中……

          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 郭興華 閱讀(564) | 評論 (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 郭興華 閱讀(238) | 評論 (0)編輯 收藏
          VectorTest.java(待寫.....)

          /**
           * 通過這個程序,測試Vector的添加元素及插入元素
           
          */

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

          posted @ 2008-10-23 16:09 郭興華 閱讀(80) | 評論 (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 郭興華 閱讀(101) | 評論 (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 郭興華 閱讀(104) | 評論 (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 郭興華 閱讀(95) | 評論 (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 郭興華 閱讀(131) | 評論 (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 郭興華 閱讀(127) | 評論 (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 郭興華 閱讀(148) | 評論 (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 郭興華 閱讀(152) | 評論 (0)編輯 收藏
          僅列出標題
          共9頁: 上一頁 1 2 3 4 5 6 7 8 9 下一頁 
          主站蜘蛛池模板: 湖州市| 高密市| 乌拉特前旗| 舒城县| 霍城县| 方正县| 理塘县| 交城县| 通榆县| 东台市| 横峰县| 广宁县| 安仁县| 德钦县| 柳林县| 贡山| 高雄县| 康定县| 永福县| 安阳市| 南皮县| 张北县| 大同市| 丽江市| 菏泽市| 库伦旗| 小金县| 康平县| 天全县| 浦城县| 轮台县| 吴江市| 城固县| 黑龙江省| 甘孜县| 曲麻莱县| 当阳市| 县级市| 庆阳市| 游戏| 井陉县|