﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-java开发社区</title><link>http://www.blogjava.net/javakf/</link><description>小白聊聊吧</description><language>zh-cn</language><lastBuildDate>Thu, 07 May 2026 09:27:23 GMT</lastBuildDate><pubDate>Thu, 07 May 2026 09:27:23 GMT</pubDate><ttl>60</ttl><item><title>Java笔记整理</title><link>http://www.blogjava.net/javakf/archive/2008/07/17/www_javakf_com.html</link><dc:creator>www.javakf.com</dc:creator><author>www.javakf.com</author><pubDate>Thu, 17 Jul 2008 06:25:00 GMT</pubDate><guid>http://www.blogjava.net/javakf/archive/2008/07/17/www_javakf_com.html</guid><wfw:comment>http://www.blogjava.net/javakf/comments/215479.html</wfw:comment><comments>http://www.blogjava.net/javakf/archive/2008/07/17/www_javakf_com.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/javakf/comments/commentRss/215479.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/javakf/services/trackbacks/215479.html</trackback:ping><description><![CDATA[第一章：<br />
1、Java应用程序分类：applate\应用程序<br />
2、环境配置：path：C:\Borland\JBuilder2005\jdk1.4\bin<br />
3、原程序（以.java为后缀）——字节码（.class为后缀）——JVM<br />
4、程序结构<br />
&nbsp; &nbsp; 注释：单行：//&nbsp; &nbsp; 多行：/*&nbsp;&nbsp;*/&nbsp; &nbsp;&nbsp; &nbsp;文档注释：/**&nbsp; &nbsp; */<br />
5、 JDK：javac&nbsp; &nbsp; java&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;javadoc<br />
<br />
<br />
<br />
第二章<br />
1、数据类型分类：原始数据类型（float num; num=1.1234f;）&nbsp; &nbsp; <br />
引用数据类型(数组、类、接口)<br />
2、数据类型转换：自动数据类型转换、强制数据类型转换：（数据类型）变量名<br />
3、流程控制语句：条件分支：if&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;switch<br />
<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 循环：for(int i=0;i&lt;5;i++)&nbsp; &nbsp; while&nbsp; &nbsp;&nbsp; &nbsp;do-while<br />
<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 跳转语句：continue&nbsp; &nbsp; break<br />
<br />
4、数组：<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<font color="#ff0000">int arrName[]; arrName=new int[10];</font><br />
<font color="#ff0000"><br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;int arrName[]=new int[10];<br />
</font><br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;int arrName[]={1,2,3};<br />
<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;int arrName[]=new int[]{1,2,3};<br />
<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;arrName.length&nbsp; &nbsp; 大小<br />
<br />
<br />
第三章<br />
1、类<br />
&nbsp; &nbsp; 面向对象（OOP）:<font color="#ff0000">封装、继承、多态</font><br />
&nbsp; &nbsp; 类：属性（变量）、方法<br />
<br />
&nbsp; &nbsp; class&nbsp;&nbsp;ClassName{<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<br />
}<br />
构造方法：<font color="#ff0000">隐式、参数化</font><br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;特点：没有返回值类型、方法与类同名、不可以被对象调用、实例化时直接调用、构造可以重载<br />
<br />
2、包：避免命名冲突<br />
<br />
&nbsp; &nbsp; package&nbsp;&nbsp;packageName;<br />
&nbsp; &nbsp; import packageName.className;<br />
<br />
<br />
第四章<br />
<br />
1、继承：子类继承父类（extends），子类具有父类的所有属性和方法<br />
<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<font color="blue">先调用父类的构造方法 ，再调用子类的构造方法<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;super( ):调用父类的构造方法</font><br />
<br />
2、多态：<font color="#ff0000">重载（同一类里）、重写（子类重写父类的方法）</font><br />
<br />
<br />
重载：<font color="blue">方法名相同、参数列表不同、与返回值类型无关</font><br />
重写：<font color="blue">发生继承关系，子类重写父类的方法，子类方法与父类的方法同名，实例化子类对象调用的是子类重写后的方法.<br />
</font><br />
Super: 父类对象&nbsp;&nbsp;调用父类的方法<br />
<br />
<br />
<font color="#ff0000">Java里不支持多继承<br />
类可以实现多个接口 ：interface&nbsp; &nbsp; 所有方法都是抽象的</font><br />
实现接口 ：className&nbsp;&nbsp;implements interfaceName1,interfaceName2&nbsp;&nbsp;<br />
<br />
3、访问修饰符：public&nbsp;&nbsp;private&nbsp;&nbsp;protected&nbsp; &nbsp; 默认<br />
<br />
&nbsp; &nbsp; 方法的访问修饰符：static&nbsp;&nbsp;final&nbsp; &nbsp; abstract<br />
<br />
<br />
<br />
第五章 <br />
<br />
1、捕获异常 try{<br />
<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}catch（异常类型 异常名）<br />
<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;finally（无论是否已引发异常，这个块都要执行）<br />
<br />
2、抛出异常 throw&nbsp;&nbsp;在构造里使用<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;throws 在构造前使用<br />
<br />
3、自定义异常 Exception （配合throw多点） <br />
<br />
<br />
<br />
第六章 lang<br />
<br />
1、Character:<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<br />
方法&nbsp; &nbsp; 说明<br />
<font color="red">isDigit()</font>&nbsp; &nbsp; 确定字符是否为 0 至 9 之间的数字<br />
<font color="red">isLetter()</font>&nbsp; &nbsp; 确定字符是否为字母<br />
<font color="red">isLowerCase()</font>&nbsp; &nbsp; 确定字符是否为小写形式<br />
<font color="red">isUpperCase()</font>&nbsp; &nbsp; 确定字符是否为大写形式<br />
<font color="red">isWhiteSpace()</font>&nbsp; &nbsp; 确定字符是否为空格或换行符<br />
<font color="red">isUnicodeIdentifierStart()</font>&nbsp; &nbsp; 确定是否允许将指定字符作为 Unicode 标识符中的首字符<br />
<br />
2、String:（不变性，所有方法以返回值得方式执行）<br />
&nbsp; &nbsp;&nbsp; &nbsp;length( )&nbsp; &nbsp; //获得字符串长度<br />
&nbsp; &nbsp;&nbsp; &nbsp; equals( )&nbsp; &nbsp; //比较字符串值是否相等（如果比较两个对象是否相等：= =）<br />
<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;方法 -----------------------------------------------------------------&gt;&nbsp; &nbsp;说明<br />
<br />
<font color="red">boolean equalsIgnoreCase (String value)</font>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;此方法比较两个字符串，忽略大小写形式<br />
<font color="red">int compareTo(String value)</font>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;按字母顺序比较两个字符串。<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 如果两个字符串相等，则返回 0；<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 如果字符串在该值之前，则返回值小于 0；<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 如果字符串在该值之后，则返回值大于 0<br />
<font color="red">boolean startsWith(String value)</font>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 检查一个字符串是否以另一个字符串开始。<br />
<font color="red">boolean endsWith(String value)</font>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;检查一个字符串是否以另一个字符串结束。<br />
<font color="red">indexOf( ):</font>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;搜索某个字符串出现的位置（如果没有找到，返回-1）<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;方法 ----------------------------------------------------&gt;&nbsp;&nbsp;说明<br />
<font color="red">public char charAt(int index)</font>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 此方法用于从指定位置提取单个字符，该位置由索引指定，索引中的值必须为非负<br />
<font color="red">public String substring(int index)</font>&nbsp; &nbsp; 此方法用于提取从位置索引开始的字符串部分<br />
<font color="red">public String substring(int beginindex, int endindex)</font>&nbsp; &nbsp; 此方法用于提取 beginindex 和 endindex 位置之间的字符串部分<br />
<font color="red">public String concat(String str)</font>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;此方法用于连接两个字符串，并新建一个包含调用字符串的字符串对象<br />
<font color="red">public String replace(char old, char new)</font>&nbsp; &nbsp; 此方法用于将调用字符串中出现某个字符的所有位置都替换为另一个字符<br />
<font color="red">public String trim()</font>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;此方法用于返回一个前后不含任何空格的调用字符串的副本<br />
<font color="red">toLowerCase( )</font>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//把字符串转化为小写<br />
<font color="red">toUpperCase( )</font>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; //把字符串转化为大写<br />
<br />
<br />
<font color="blue">StringBuffer:</font><br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 方法 ----------------------------------------------&gt;&nbsp; &nbsp;说明<br />
<font color="red">StringBuffer insert(String s,int&nbsp;&nbsp;index)</font>&nbsp; &nbsp; 在指定位置(index)插入指定的字符串（s）<br />
<font color="red">int length( )</font>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;确定 StringBuffer 对象的长度<br />
<font color="red">void setCharAt(int pos, char ch)</font>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;使用 ch 指定的新值设置 pos 指定的位置上的字符<br />
<font color="red">String toString( )</font>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;转换为字符串形式<br />
<font color="red">StringBuffer reverse()</font>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;保留 StringBuffer 对象中的字符<br />
<font color="red">StringBuffer delete(int start, int end)</font>&nbsp; &nbsp;&nbsp;&nbsp;此方法将删除调用对象中从 start 位置开始直到 end 指定的索引 &#8211; 1 位置的 字符序列<br />
<font color="red">StringBuffer deleteCharAt(int pos)</font>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;此方法将删除 pos 指定的索引处的字符<br />
<font color="red">StringBuffer replace(int start, int end, String s)</font>&nbsp; &nbsp; 此方法使用一组字符替换另一组字符。将用替换字符串从 start 指定的位置开始替换，直到 end 指定的位置结束<br />
<br />
<font color="red">Math:&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;方法都是静态的，调用时直接用类名调用</font><br />
Exa:&nbsp;&nbsp;Math.abs(-1);<br />
<br />
方法&nbsp;&nbsp;-------------------------------------------------&gt;&nbsp;&nbsp;说明<br />
<font color="red">double sin (double numvalue)&nbsp;&nbsp;</font>&nbsp; &nbsp;&nbsp;&nbsp;计算角 numvalue 的正弦值<br />
<font color="red">double cos&nbsp;&nbsp;(double numvalue) </font>&nbsp; &nbsp; 计算角 numvalue 的余弦值<br />
<font color="red">double pow (double a, double b) </font>&nbsp;&nbsp;计算 a 的 b 次方<br />
<font color="red">double sqrt&nbsp;&nbsp;(double numvalue)&nbsp;&nbsp;</font>&nbsp; &nbsp;计算给定值的平方根<br />
<font color="red">int abs (int numvalue)&nbsp; &nbsp;&nbsp; &nbsp;</font>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;计算 int 类型值 numvalue 的绝对值，也接收 long、float 和 double 类型的参数<br />
<font color="red">double ceil (double numvalue)&nbsp; &nbsp;</font>&nbsp; &nbsp; 返回大于等于 numvalue 的最小整数值<br />
<font color="red">double floor (double numvalue) </font>&nbsp; &nbsp; 返回小于等于 numvalue 的最大整数值<br />
<font color="red">int max(int a, int b)&nbsp;&nbsp;</font>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;返回 int 型值 a 和 b 中的较大值，也接收 long、float 和 double 类型的参数<br />
<font color="red">int min(int a, int b)</font>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;返回 a 和 b 中的较小值，也可接收 long、float 和 double 类型的参数<br />
<br />
<br />
第7章<br />
<br />
Util:<br />
1、&nbsp; &nbsp; Date:&nbsp;&nbsp;Date objd=new Date(); objd.getTime();&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//获取毫秒<br />
<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;objd.toString();&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//时间字符串<br />
<br />
2、&nbsp; &nbsp; Calendar&nbsp;&nbsp;Calendar objc=Calendar.getInstance();&nbsp;&nbsp;objc.get(Calendar.Year)<br />
<br />
3、&nbsp; &nbsp; Random&nbsp;&nbsp;Random objr=new Random();&nbsp;&nbsp;objr.nextInt();&nbsp;&nbsp;objr.nextFloat();&nbsp;&nbsp;objr.nextDouble();<br />
<br />
4、&nbsp; &nbsp; ArrayList:<br />
<br />
a)&nbsp; &nbsp; Add()&nbsp;&nbsp;添加数组元素<br />
b)&nbsp; &nbsp; Get()&nbsp; &nbsp; 察看元素值<br />
c)&nbsp; &nbsp; indexOf()&nbsp;&nbsp;查看某字符串第一次出现的位置<br />
d)&nbsp; &nbsp; lastIndexOf()&nbsp;&nbsp;查看某字符串最后一次出现的位置<br />
<br />
5、&nbsp; &nbsp; LinkedList：<br />
<br />
a)&nbsp; &nbsp; addLast()&nbsp;&nbsp;从链表的最后一个元素执行增加<br />
b)&nbsp; &nbsp; addFirst()&nbsp;&nbsp;从链表的第一个元素执行增加<br />
c)&nbsp; &nbsp; removeFirst()&nbsp;&nbsp;从链表的第一个元素执行删除<br />
d)&nbsp; &nbsp; removeLast()&nbsp;&nbsp;从链表的最后一个元素执行删除<br />
<br />
6、&nbsp; &nbsp; HashMap:<br />
<br />
方法：put(key,value)&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//添加<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;get(key)&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//查找<br />
<br />
Exa:<br />
<br />
&nbsp; &nbsp; public void add(HashMap objhm,String key,String value){<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;objhm.put(key,value);<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; public void put(HashMap objhm,String key){<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;System.out.println(key+"的成绩："+objhm.get(key));<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<br />
}<br />
<br />
完成修改：先删除：remove(key)&nbsp;&nbsp;//删除<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;在添加：put(key,value)&nbsp;&nbsp;//添加<br />
<br />
Exa:<br />
<br />
&nbsp; &nbsp; public void update(HashMap objhm,String key,String value){<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;objhm.remove(key);<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;objhm.put(key,value);<br />
&nbsp; &nbsp; }<br />
<br />
7、&nbsp; &nbsp; Vector:<br />
<br />
添加元素：addElement( )&nbsp;&nbsp;<br />
插入：insertElementAt( )<br />
搜索：indexOf( )<br />
获得第一个元素：firstElement( ) <br />
获得最后一个元素：lastElement( )<br />
获得容量：capacity( )<br />
<br />
Exa1:<br />
<br />
public void add(Vector objv,String str){<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;objv.addElement(str);<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; public void show(Vector objv){<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;int size=objv.size();<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;for(int i=0;i&lt;size;i++){<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;System.out.println("第"+(i+1)+"个元素的值是："+objv.get(i));<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br />
}<br />
<br />
Exa2:<br />
<br />
&nbsp; &nbsp; public void addv(Vector objsup,Vector objsub){<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;objsup.addElement(objsub);<br />
&nbsp; &nbsp; }<br />
<br />
<br />
<br />
第八章 io<br />
<br />
文件输入输出：<br />
<br />
1、&nbsp; &nbsp; 文本文件：1）字节<br />
读：FileInputStream&nbsp;&nbsp;方法：read()<br />
<br />
Exa:<br />
<br />
public void fileRead(String fileName){<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;try {<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;FileInputStream objfi = new FileInputStream(fileName);<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;try {<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; int size = objfi.available();<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; char ch[]=new char[100];<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; for(int i=0;i&lt;size;i++){<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;ch[ i ]=(char)(objfi.read());<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;System.out.print(ch[ i ]);<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; objfi.close();<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;} catch (IOException ex1) {<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;} catch (FileNotFoundException ex) {<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<br />
&nbsp; &nbsp; }<br />
<br />
<br />
写：FileOutputStream&nbsp; &nbsp; 方法：write( )<br />
<br />
Exa:<br />
<br />
public void fileWrite(String fileName){<br />
&nbsp; &nbsp; try {<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;FileOutputStream objfo = new FileOutputStream(fileName,true);<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;String str="ACCP";<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;byte []arrb=str.getBytes();<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;try {<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;objfo.write(arrb, 0, arrb.length);<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;objfo.close();<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;} catch (IOException ex1) {<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br />
&nbsp; &nbsp; } catch (FileNotFoundException ex) {<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; }<br />
<br />
2）字符<br />
&nbsp; &nbsp; 读：FileReader&nbsp;&nbsp;BufferedReader<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;方法：readLine()<br />
<br />
Exa:<br />
<br />
public void charRead(String fileName){<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;try {<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;FileReader objfr = new FileReader(fileName);<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;BufferedReader objbr=new BufferedReader(objfr);<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;String line = null;<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;try {<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; line = objbr.readLine();<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; while(line!=null){<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;System.out.println(line);<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;line=objbr.readLine();<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;objbr.close();<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;objfr.close();<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;} catch (IOException ex1) {<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;} catch (FileNotFoundException ex) {<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<br />
}<br />
<br />
写：FileWriter&nbsp; &nbsp; BufferedWriter<br />
方法：write()<br />
<br />
Exa:<br />
<br />
public void charWrite(String fileName){<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;try {<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;FileWriter objfw = new FileWriter(fileName);<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;BufferedWriter objbw=new BufferedWriter(objfw);<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;objbw.write("t64");<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;objbw.write(" Very Good!");<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;objbw.newLine();<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;objbw.write("继续努力");<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;objbw.close();<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;objfw.close();<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;} catch (IOException ex) {<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<br />
&nbsp; &nbsp; }<br />
<br />
2、&nbsp; &nbsp; 二进制<br />
读：FileInputStream&nbsp;&nbsp;DataInputStream<br />
方法：read()<br />
写：FileOutputStream&nbsp;&nbsp;DataOutputStream<br />
方法：write()<br />
<br />
Exa:<br />
<br />
public void datacopy(String oldFileName,String newFileName){<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;try {<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;FileInputStream objfi = new FileInputStream(oldFileName);<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;DataInputStream objdi=new DataInputStream(objfi);<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;FileOutputStream objfo=new FileOutputStream(newFileName);<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;DataOutputStream objdo=new DataOutputStream(objfo);<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;try {<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; int temp = objdi.read();<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; while(temp!=-1){<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;objdo.write(temp);<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;temp=objdi.read();<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; objdo.flush();<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; objdo.close();<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; objdi.close();<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; objfi.close();<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; objfo.close();<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;} catch (IOException ex1) {<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;} catch (FileNotFoundException ex) {<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<br />
}<br />
<br />
<br />
<br />
后面章节的总结<br />
<br />
一、jdbc:数据库连接处理<br />
<br />
二、核心类<br />
<br />
&nbsp; &nbsp; 1、DriverManager:驱动管理器<br />
<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;1、得到连接<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;--odbc<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Connection con=DriverManager.getConnection("jdbc:odbc:系统dns","sa","sa");<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;--专用接口<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Connection con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;databaseName=pubs","sa","");<br />
<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;2、连接<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Conenction con;<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;--产生执行sql的对象:<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;--PreparedStatement<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;PreparedStatement ps=con.preparedStatement(sql);<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;--Statement<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Statemnet st=con.createStatemenet();<br />
<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;3、执行sql的对象<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;--PreparedStatemenet可传参，如果一个sql多次重复被执行使用PreparedStatement<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;PreparedStatement ps=con.preparedStatement("insert into a1(?,?,?)");<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;ps.setString(1,"1");<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;--执行insert update delete<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;ps.executeUpdate();<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;--执行select<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;ResultSet rs=ps.executeQuery();<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;--Statement:不可传参，不重复执行时可用<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Statement sm=con.createStatement();<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;--执行insert update delete<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; sm.executeUpate("delete from customer");<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;--执行select<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; ResultSet rs=sm.executeQuery("select * from customer");<br />
<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;4、结果集(resultSet)，要想取值必须next 一次<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;--取一行<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if(rs.next())<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;{<br />
<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;--取多行<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;while(rs.next())<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;{<br />
<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}
<img src ="http://www.blogjava.net/javakf/aggbug/215479.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/javakf/" target="_blank">www.javakf.com</a> 2008-07-17 14:25 <a href="http://www.blogjava.net/javakf/archive/2008/07/17/www_javakf_com.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>