隨筆-1  評論-0  文章-0  trackbacks-0
            2008年7月17日
          第一章:
          1、Java應用程序分類:applate\應用程序
          2、環境配置:path:C:\Borland\JBuilder2005\jdk1.4\bin
          3、原程序(以.java為后綴)——字節碼(.class為后綴)——JVM
          4、程序結構
              注釋:單行://    多行:/*  */      文檔注釋:/**    */
          5、 JDK:javac    java            javadoc



          第二章
          1、數據類型分類:原始數據類型(float num; num=1.1234f;)   
          引用數據類型(數組、類、接口)
          2、數據類型轉換:自動數據類型轉換、強制數據類型轉換:(數據類型)變量名
          3、流程控制語句:條件分支:if        switch

                          循環:for(int i=0;i<5;i++)    while      do-while

                          跳轉語句:continue    break

          4、數組:
                  int arrName[]; arrName=new int[10];

                  int arrName[]=new int[10];

                  int arrName[]={1,2,3};

                  int arrName[]=new int[]{1,2,3};

                  arrName.length    大小


          第三章
          1、類
              面向對象(OOP):封裝、繼承、多態
              類:屬性(變量)、方法

              class  ClassName{
                  
          }
          構造方法:隱式、參數化
                  特點:沒有返回值類型、方法與類同名、不可以被對象調用、實例化時直接調用、構造可以重載

          2、包:避免命名沖突

              package  packageName;
              import packageName.className;


          第四章

          1、繼承:子類繼承父類(extends),子類具有父類的所有屬性和方法

                  先調用父類的構造方法 ,再調用子類的構造方法
                  super( ):調用父類的構造方法


          2、多態:重載(同一類里)、重寫(子類重寫父類的方法)


          重載:方法名相同、參數列表不同、與返回值類型無關
          重寫:發生繼承關系,子類重寫父類的方法,子類方法與父類的方法同名,實例化子類對象調用的是子類重寫后的方法.

          Super: 父類對象  調用父類的方法


          Java里不支持多繼承
          類可以實現多個接口 :interface    所有方法都是抽象的

          實現接口 :className  implements interfaceName1,interfaceName2  

          3、訪問修飾符:public  private  protected    默認

              方法的訪問修飾符:static  final    abstract



          第五章

          1、捕獲異常 try{

                  }catch(異常類型 異常名)

                  finally(無論是否已引發異常,這個塊都要執行)

          2、拋出異常 throw  在構造里使用
                  throws 在構造前使用

          3、自定義異常 Exception (配合throw多點)



          第六章 lang

          1、Character:
                  
          方法    說明
          isDigit()    確定字符是否為 0 至 9 之間的數字
          isLetter()    確定字符是否為字母
          isLowerCase()    確定字符是否為小寫形式
          isUpperCase()    確定字符是否為大寫形式
          isWhiteSpace()    確定字符是否為空格或換行符
          isUnicodeIdentifierStart()    確定是否允許將指定字符作為 Unicode 標識符中的首字符

          2、String:(不變性,所有方法以返回值得方式執行)
                length( )    //獲得字符串長度
                 equals( )    //比較字符串值是否相等(如果比較兩個對象是否相等:= =)

                      方法 ----------------------------------------------------------------->   說明

          boolean equalsIgnoreCase (String value)                    此方法比較兩個字符串,忽略大小寫形式
          int compareTo(String value)                                         按字母順序比較兩個字符串。
                                                                                               如果兩個字符串相等,則返回 0;
                                                                                               如果字符串在該值之前,則返回值小于 0;
                                                                                               如果字符串在該值之后,則返回值大于 0
          boolean startsWith(String value)                                  檢查一個字符串是否以另一個字符串開始。
          boolean endsWith(String value)                                   檢查一個字符串是否以另一個字符串結束。
          indexOf( ):                                                                    搜索某個字符串出現的位置(如果沒有找到,返回-1)
                   方法 ---------------------------------------------------->  說明
          public char charAt(int index)          此方法用于從指定位置提取單個字符,該位置由索引指定,索引中的值必須為非負
          public String substring(int index)    此方法用于提取從位置索引開始的字符串部分
          public String substring(int beginindex, int endindex)    此方法用于提取 beginindex 和 endindex 位置之間的字符串部分
          public String concat(String str)        此方法用于連接兩個字符串,并新建一個包含調用字符串的字符串對象
          public String replace(char old, char new)    此方法用于將調用字符串中出現某個字符的所有位置都替換為另一個字符
          public String trim()                           此方法用于返回一個前后不含任何空格的調用字符串的副本
          toLowerCase( )                                //把字符串轉化為小寫
          toUpperCase( )                               //把字符串轉化為大寫


          StringBuffer:
                    方法 ---------------------------------------------->   說明
          StringBuffer insert(String s,int  index)    在指定位置(index)插入指定的字符串(s)
          int length( )                                            確定 StringBuffer 對象的長度
          void setCharAt(int pos, char ch)            使用 ch 指定的新值設置 pos 指定的位置上的字符
          String toString( )                                    轉換為字符串形式
          StringBuffer reverse()                           保留 StringBuffer 對象中的字符
          StringBuffer delete(int start, int end)     此方法將刪除調用對象中從 start 位置開始直到 end 指定的索引 – 1 位置的 字符序列
          StringBuffer deleteCharAt(int pos)        此方法將刪除 pos 指定的索引處的字符
          StringBuffer replace(int start, int end, String s)    此方法使用一組字符替換另一組字符。將用替換字符串從 start 指定的位置開始替換,直到 end 指定的位置結束

          Math:                                                      方法都是靜態的,調用時直接用類名調用
          Exa:  Math.abs(-1);

          方法  ------------------------------------------------->  說明
          double sin (double numvalue)       計算角 numvalue 的正弦值
          double cos  (double numvalue)     計算角 numvalue 的余弦值
          double pow (double a, double b)   計算 a 的 b 次方
          double sqrt  (double numvalue)     計算給定值的平方根
          int abs (int numvalue)                    計算 int 類型值 numvalue 的絕對值,也接收 long、float 和 double 類型的參數
          double ceil (double numvalue)       返回大于等于 numvalue 的最小整數值
          double floor (double numvalue)     返回小于等于 numvalue 的最大整數值
          int max(int a, int b)                         返回 int 型值 a 和 b 中的較大值,也接收 long、float 和 double 類型的參數
          int min(int a, int b)                          返回 a 和 b 中的較小值,也可接收 long、float 和 double 類型的參數


          第7章

          Util:
          1、    Date:  Date objd=new Date(); objd.getTime();                       //獲取毫秒

                            objd.toString();                                                            //時間字符串

          2、    Calendar  Calendar objc=Calendar.getInstance();  objc.get(Calendar.Year)

          3、    Random  Random objr=new Random();  objr.nextInt();  objr.nextFloat();  objr.nextDouble();

          4、    ArrayList:

          a)    Add()  添加數組元素
          b)    Get()    察看元素值
          c)    indexOf()  查看某字符串第一次出現的位置
          d)    lastIndexOf()  查看某字符串最后一次出現的位置

          5、    LinkedList:

          a)    addLast()  從鏈表的最后一個元素執行增加
          b)    addFirst()  從鏈表的第一個元素執行增加
          c)    removeFirst()  從鏈表的第一個元素執行刪除
          d)    removeLast()  從鏈表的最后一個元素執行刪除

          6、    HashMap:

          方法:put(key,value)           //添加
                      get(key)                  //查找

          Exa:

              public void add(HashMap objhm,String key,String value){
                  objhm.put(key,value);
              }
              public void put(HashMap objhm,String key){
                  System.out.println(key+"的成績:"+objhm.get(key));
                  
          }

          完成修改:先刪除:remove(key)  //刪除
                  在添加:put(key,value)  //添加

          Exa:

              public void update(HashMap objhm,String key,String value){
                  objhm.remove(key);
                  objhm.put(key,value);
              }

          7、    Vector:

          添加元素:addElement( )  
          插入:insertElementAt( )
          搜索:indexOf( )
          獲得第一個元素:firstElement( )
          獲得最后一個元素:lastElement( )
          獲得容量:capacity( )

          Exa1:

          public void add(Vector objv,String str){
                  objv.addElement(str);
              }
              public void show(Vector objv){
                  int size=objv.size();
                  for(int i=0;i<size;i++){
                      System.out.println("第"+(i+1)+"個元素的值是:"+objv.get(i));
                  }
          }

          Exa2:

              public void addv(Vector objsup,Vector objsub){
                  objsup.addElement(objsub);
              }



          第八章 io

          文件輸入輸出:

          1、    文本文件:1)字節
          讀:FileInputStream  方法:read()

          Exa:

          public void fileRead(String fileName){
                  try {
                      FileInputStream objfi = new FileInputStream(fileName);
                      try {
                          int size = objfi.available();
                          char ch[]=new char[100];
                          for(int i=0;i<size;i++){
                              ch[ i ]=(char)(objfi.read());
                              System.out.print(ch[ i ]);
                          }
                          objfi.close();
                      } catch (IOException ex1) {
                      }
                      
                  } catch (FileNotFoundException ex) {
                  }
                  
              }


          寫:FileOutputStream    方法:write( )

          Exa:

          public void fileWrite(String fileName){
              try {
                  FileOutputStream objfo = new FileOutputStream(fileName,true);
                  String str="ACCP";
                  byte []arrb=str.getBytes();
                  try {
                      objfo.write(arrb, 0, arrb.length);
                      objfo.close();
                  } catch (IOException ex1) {
                  }
              } catch (FileNotFoundException ex) {
              }
              }

          2)字符
              讀:FileReader  BufferedReader
                  方法:readLine()

          Exa:

          public void charRead(String fileName){
                  try {
                      FileReader objfr = new FileReader(fileName);
                      BufferedReader objbr=new BufferedReader(objfr);
                      String line = null;
                      try {
                          line = objbr.readLine();
                          while(line!=null){
                              System.out.println(line);
                              line=objbr.readLine();
                      }
                      objbr.close();
                      objfr.close();
                      } catch (IOException ex1) {
                      }
                      
                  } catch (FileNotFoundException ex) {
                  }
                  
          }

          寫:FileWriter    BufferedWriter
          方法:write()

          Exa:

          public void charWrite(String fileName){
                  try {
                      FileWriter objfw = new FileWriter(fileName);
                      BufferedWriter objbw=new BufferedWriter(objfw);
                      objbw.write("t64");
                      objbw.write(" Very Good!");
                      objbw.newLine();
                      objbw.write("繼續努力");
                      objbw.close();
                      objfw.close();
                  } catch (IOException ex) {
                  }
                  
              }

          2、    二進制
          讀:FileInputStream  DataInputStream
          方法:read()
          寫:FileOutputStream  DataOutputStream
          方法:write()

          Exa:

          public void datacopy(String oldFileName,String newFileName){
                  try {
                      FileInputStream objfi = new FileInputStream(oldFileName);
                      DataInputStream objdi=new DataInputStream(objfi);
                      FileOutputStream objfo=new FileOutputStream(newFileName);
                      DataOutputStream objdo=new DataOutputStream(objfo);
                      try {
                          int temp = objdi.read();
                          while(temp!=-1){
                              objdo.write(temp);
                              temp=objdi.read();
                          }
                          objdo.flush();
                          objdo.close();
                          objdi.close();
                          objfi.close();
                          objfo.close();
                      } catch (IOException ex1) {
                      }
                      
                  } catch (FileNotFoundException ex) {
                  }
                  
          }



          后面章節的總結

          一、jdbc:數據庫連接處理

          二、核心類

              1、DriverManager:驅動管理器

                  1、得到連接
                      --odbc
                      Connection con=DriverManager.getConnection("jdbc:odbc:系統dns","sa","sa");
                      --專用接口
                      Connection con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;databaseName=pubs","sa","");

                  2、連接
                      Conenction con;
                      --產生執行sql的對象:
                      --PreparedStatement
                      PreparedStatement ps=con.preparedStatement(sql);
                      --Statement
                      Statemnet st=con.createStatemenet();

                  3、執行sql的對象
                      --PreparedStatemenet可傳參,如果一個sql多次重復被執行使用PreparedStatement
                      PreparedStatement ps=con.preparedStatement("insert into a1(?,?,?)");
                      ps.setString(1,"1");
                      --執行insert update delete
                      ps.executeUpdate();
                      --執行select
                      ResultSet rs=ps.executeQuery();
                      --Statement:不可傳參,不重復執行時可用
                      Statement sm=con.createStatement();
                      --執行insert update delete
                          sm.executeUpate("delete from customer");
                      --執行select
                          ResultSet rs=sm.executeQuery("select * from customer");

                  4、結果集(resultSet),要想取值必須next 一次
                      --取一行
                      if(rs.next())
                      {

                      }
                      --取多行
                      while(rs.next())
                      {

                      }
          posted @ 2008-07-17 14:25 www.javakf.com 閱讀(144) | 評論 (0)編輯 收藏
          僅列出標題  
          主站蜘蛛池模板: 全南县| 焦作市| 孟津县| 山阴县| 兰考县| 灵川县| 金沙县| 章丘市| 彝良县| 九台市| 周口市| 景洪市| 新乐市| 瑞安市| 寻乌县| 安徽省| 庆云县| 遂川县| 南京市| 门头沟区| 石楼县| 武宣县| 大连市| 唐山市| 永仁县| 高青县| 潼关县| 武宣县| 图片| 沙洋县| 文化| 竹山县| 香格里拉县| 和平县| 教育| 康平县| 南陵县| 枝江市| 四会市| 舟曲县| 玛纳斯县|