Microsoft PowerPoint - course6.ppt

Size: px
Start display at page:

Download "Microsoft PowerPoint - course6.ppt"

Transcription

1 回顧 Java 程式設計基礎班 (6) Java Inner class Class/Object 基本使用方法 劉根豪台大電機所網路資料庫研究室 Java Utilities String 類別 字元與字串 (String) StringBuffer java.lang.string Java 中的字串不像 char int float 是基本資料型態, 而是使用 java.lang.string 類別加以表示, 該類別定義了許多方法來操作字串 String 物件是固定不變的 ; 一旦一個 String 物件被建立之後, 就沒有任何的方法可以改變它的內容 每個運作字串的方法都會傳回一個新的字串物件 外界看起來好像是更動了字元或字串的長度, 實際上是將原有的物件內容拷貝到新的物件中, 在回傳該新物件 3 4 String 的建構 String 的建構 建立字串 : String s = to be or not to be ; String s = new String(); s = to be or not to be ; String s = new String( to be or not to be ); 若字串很長, 要以多行來表示 : String poem = Twas brillig, and the slithy toves\n + Did gyre and gimble in the wabe:\n + All mimsy were the borogoves.\n + And the mome raths outgrabe.\n ; String t = s + is your choice ; String name = John + + Smith ; String name = John.concat( Smith ); + 是 Java 中唯一可以重載的運算子 5 6 1

2 取得字元 子字串 搜尋 取代字串 三種方法 :charat() tochararray() 配合 getchars() 或者是 substring() public class App { public static void main( String [] args ) { String s1 = Hello from Java! ; char c1 = s1.charat(0); System.out.println( The first char is + c1 ); int indexof(char c); int indexof(string s) int lastindexof(char c); int lastindexof(string s) 會回傳所搜尋的字 或子字串出現在從頭 0 開始算起的第幾個位置 String replace(char oldchar, char newchar) replace 會產生一個新的 String 物件, 回傳之 7 8 String 的比較 String 的比較 因為字串是參照型態的物件, 所以需使用 equals 來比對字串的內容 也沒有 > < <= >=, 因為 Java 不能將參照轉回成整數值 boolean equals(object anobject) boolean equalsignorecase(string anotherstring) int compareto(object o) int compareto(string anotherstring) int comparttoiqnorecase(string str) 與另一字串做比較, 以整數傳回值的來表示大 小 等於 String abc = abc ; String def = def ; String num = 123 ; if( abc.compareto( def ) < 0 ) // yes if( abc.compareto( abc ) == 0 ) // yes if( abc.compareto( num ) > 0 ) // yes 9 10 字串緩衝區 (StringBuffer) java.lang Class StringBuffer java.lang.object + -java.lang.stringbuffer All Implemented Interfaces: Serializable 因為若以 String 配合 + 運算子來增加字串, 因為 String 會反覆的拷貝 建立物件 ( 因為 String 的內容不能更改 ), 將會影響到程式的執行速度 如果需要一直加入新的字元 或字串時, 那麼可以使用 StringBuffer 有了 String 與 StringBuffer 那麼字串的處理就可以很有效率了 Hello Sasha, How are you? String message = Hello ; message = message + Sasha, ; message = message + How are you? ; System.out.println(message ); StringBuffer message = new StringBuffer( Hello ); message.append( Sasha, ); message.append( How are you? ); System.out.println(message ); // 其實是呼叫 StringBuffer 的 tostring() String message = new StringBuffer().append( Hello ).append( Sasha, ).append( How are you? ).tostring(); System.out.println(message ); String msg = message.tostring(); System.out.println( msg );

3 建立字串緩衝區 (StringBuffer) 建立字串緩衝區 以建構子方式 或 insert() 一個預設的 StringBuffer 物件有 16 個空字元 StringBuffer(. ); insert( int offset, ); For example: String x = "a" 4 "c" ; is compiled to the equivalent of: String x = new StringBuffer().append("a").append(4).append("c").toString() ; For example: StringBuffer z = new StringBuffer( start ).append( le ); is compiled to the equivalent of: StringBuffer z = new StringBuffer( start ).insert(4, "le"); //sb.insert(sb.length(), x) StringTokenizer Constructor Summary public class StringTokenizer extends Object implements Enumeration 把字串分成一個一個的單字 (word)or 標記 (token) StringTokenizer(String str) Constructs a string tokenizer for the specified string. StringTokenizer(String str, String delim) Constructs a string tokenizer for the specified string. StringTokenizer(String str, String delim, boolean returndelims) Constructs a string tokenizer for the specified string. StringTokenizer(String str, String delim, boolean returndelims) str - a string to be parsed. delim - the delimiters. returndelims - flag indicating whether to return the delimiters as tokens. Constructs a string tokenizer for the specified string. All characters in the delim argument are the delimiters for separating tokens. If the returndelims flag is true, then the delimiter characters are also returned as tokens. Each delimiter is returned as a string of length one. If the flag is false, the delimiter characters are skipped and only serve as separators between tokens Code Snippet StringTokenizer The following is one example of the use of the tokenizer. The code: StringTokenizer st = new StringTokenizer("this is a test"); while ( st.hasmoretokens() ) { System.out.println( st.nexttoken() ); prints the following output: this is a test StringTokenizer 實作 java.util.enumeration 介面, 擁有 hasmoreelement() nextelement() 可以依序的傳回一連串的元素 nextelement() 傳回型態為 Object

4 StringTokenizer text = ; tok = new StringTokenizer( text, /: ); Java Input/Output Streaming IO If ( tok.counttokens() < 2 ) // bad URL String protocol = tok.nexttoken(); // http String hostname = tok.nexttoken();// 了解 Stream( 串流 ) Data Stream Keyboard Stream program Input Stream Output Stream Stream Data Stream Monitor printer Stream Stream I/O Stream 的概念 Stream 一個輸出入裝置的抽象表示 表達了 資料來源 或 資料目的地 的概念 這些資料以位元組 (bytes) 為單位, 並且以一定的順序依序傳遞 不論是要從檔案 鍵盤 網路 甚至記憶體中, 讀取或寫入一串循序的資料, 都可以 Stream 的方式來達成 Stream I/O Stream I/O 根據要進行的操作類型,Stream 又分成兩大類 : InputStream - 代表 資料的來源, 可以從中讀取資料 ; OutputStream - 代表 資料的目的地, 可以寫入資料 注意! 串流輸出 輸入的方向都是單向的, 也就是說, 我們不能對 InputStream 寫入資料, 也不可能從 OutputStream 中讀出資料 Java 提供兩種型態的串流 : binary stream character stream 在 Java 中的任何讀寫, 都會是 binary data 因為 Java 會把所有的資料以 Unicode 的位元碼來表示 character stream 可以讓我們用來讀取非 Java 程式所採生的檔案內容

5 Stream I/O Java Input/Output 工具 在 java.io 套件的各種 Stream 中 : 有些屬於提供真正資料的 Stream, 像是連接到檔案或記憶體的 Stream 另外一些則是屬於過濾器 (Filter) 的性質, 可以串接在別的 Stream 之上, 用來提供更強的運作能力 如將 scanner 讀進來的資料, 直接轉成 image Java 將所有的 I/O 動作都視為串流 (Stream) 包含 : 讀寫檔案 存取記憶體 網路資源或將資料顯示在螢幕上, 都算是 I/O 串流 透過串流來讀取或寫入資料, 甚至也可以透過串流連接到網路上的資料源來讀取, 並以位元或字元陣列的形式來儲存 Java Input/Output 工具 套件 java.io 包含了六個主要的基本類別以提供來處理 Stream I/O 在 Java 裡, 我們可以透過它的 InputStream OutputStream Reader 與 Writer 類別來處理串流 InputStream OutputStream Reader Writer 都是抽象類別, 其中定義了許多基本的方法 因為是抽象類別, 我們並無法實作出這樣的一個物件, 所以我們並需繼承自訂新的 I/O 串流處理類別 或使用 Java 目前所提供的 File java.io 套件中的基本串流處理工具 abstract OutputStream abstract InputStream abstract Writer abstract Reader RandomAccessFile 此類別的物件可用來表示目前欲使用的檔案 或目錄路徑 此基本抽象類別用來處理位元組型態的輸出串流 此基本抽象類別用來處理位元組型態的輸入串流 此基本抽象類別用來處理字元型態的輸出串流 此基本抽象類別用來處理字元型態的輸入串流 此類別可用來提供隨機檔案的讀取 Java Input/Output 工具 File 類別 InputStream 與 OutputStream 類別主要適用來處理位元型態 (bit) 的資料串流 Reader 與 Writer 類別主要適用來處理字元型態的資料串流 本章節會介紹多個 Java 套件中已提供的實用子類別 Stream 為資料的輸出入提供一個抽象而且適用性廣泛的概念, 但如果已經確定要處理的是檔案的話,Java 可以提供更多有關檔案的資訊 先不管檔案的內容, 檔案在磁碟上的資訊要如何取得呢? java.io.file 類別為檔案提供了對應的物件

6 File 類別 路徑名稱與相關路徑 File 物件代表的是檔案或目錄在處儲存裝置中的路徑名稱, 不是串流 建立這樣一個檔案物件的目的是來可以把他當作參數傳遞 並使用到檔案這類別中所提供的相關方法, 可以建立 移除或讀取 變更檔案的屬性等 On Windows 95, 98, NT/2000, 我們可以使用 \\ 取代 / UNC(Universal Naming Conversion) 在 Windows 的環境中, 提供了 UNC 的路徑表示法, 用來提供網路環境中不同機器平台之間的名稱表示的一致 File myfile = new File( \\\\mypc\\shared\\jdk1.3\\src\\java\\io, File.java ); 以 \\ 開頭每一層目錄也都以 \\ 連接 建立 File 物件 測試 檢查檔案物件 (option) 有三種方式可以建立一個檔案物件 : 以檔案路徑名稱 或目錄路徑名稱的字串當作 File 建構子的參數 File mydir = new File("D:/jdk1.3/src/java/io "); File myfile = new File( D:/jdk1.3/src/java/io/File.java "); 以目錄路徑的檔案物件與檔案名稱當作 File 建構子的參數 File mydir = new File(" C:/jdk1.3/src/java/io "); File myfile = new File( mydir, File.java ); boolean exists() boolean isdirectory() boolean isfile() boolean ishiddlen() boolean isabsolute() 檢查檔案物件是否對應到一個絕對路徑 ( 以磁碟機符號開頭加冒號 或是一個反斜線 或雙反斜線 ) boolean equals( File obj) 比較兩檔案物件所對應到的路徑名稱是否相等 測試 檢查檔案物件 (option) 測試 檢查檔案物件 boolean canread() 檢查一檔案物件的屬性是否為可以讀取若不允許讀取, 會回傳 false 並可都出一個 SecurityException ( 配合 try-catch 可獲得 ) boolean canwrite() 檢查一檔案物件的屬性是否為可以寫入檢查一檔案物件的屬性是否為可以讀取若不允許讀取, 會回傳 false 並可都出一個 SecurityException ( 配合 try-catch 可獲得 ) 見例一

7 讀取檔案物件 (optional) 讀取檔案物件 (optional) String getname() 回傳檔案物件的名稱 String getpath() 回傳檔案物件的 ( 包含檔案名稱 ) 路徑名稱 String getabsolutepath() 回傳此檔案物件中所對應到的 ( 包含檔案名稱 ) 絕對路徑名稱 String getparent() 傳回上一層的目錄名稱 String [] list() 傳回一字串陣列, 其中每一個元素代表此目錄下的檔案 或目錄名稱的字串 若為空目錄, 則傳回空陣列 若為檔案, 則傳回 null 可配合 try-catch 擷取 SecurityException 若是沒有目錄的使用權限 long length() 傳回目前檔案物件所代表的檔案內容之長度 ( 以 byte 計算 ) 讀取檔案物件 (optional) 讀取檔案物件 (optional) File [] listfiles() 傳回一檔案物件陣列, 其中每一個元素代表此目錄嚇得一個檔案 或目錄的物件 若為空目錄, 則傳回空陣列 若為檔案, 則傳回 null 可配合 try-catch 擷取 SecurityException 若是沒有目錄的使用權限 long lastmodified() 傳回最近一次檔案物件所對應到的檔案被更改的時間 以 milliseconds 計算, 我們可以使用 Date() 來轉換使用 String tostring() int hashcode() static File [] listroots() 傳回一陣列 : 元素為所有系統有效的根目錄 File [] roots = File.listRoots(); for ( int i = 0, i < roots.length; i++ ) System.out.println( Root directory + i + : + roots[i] ); 過濾檔案名冊 (filter a file list) (optional) 修改檔案物件與檔案 (optional) list() 與 listfiles() 這兩方法可以進一步被改寫, 透過傳入的參數來過濾檔案名冊 Java 提供了兩個介面 FilenameFilter 與 FileFilter, 都包含 abstract boolean accept(); 可以被實作來過濾檔案名冊 若使用 list() 則要實作 FilenameFilter 介面 若使用 listfiles() 則可以擇一實作 FilenameFilter 或 FileFilter 介面 41 boolean renameto( File path) 這方法會直真正改掉磁碟上的檔案名稱 程式執行完後依舊有效 boolean setreadonly( File obj) 某檔案物件設定為只可讀取 boolean mkdirs() 新增一目錄 boolean createnewfile() 建議一個空檔案 42 7

8 修改檔案物件與檔案 (optional) 修改檔案物件與檔案 (optional) static File createtempfile( String prefix, String suffix, File directory ) static File createtempfile( String prefix, String suffix) static File createtempfile( String prefix, String suffix, null ) 在某個目錄中建立暫存檔, 若明指名, 則會使用系統的暫存檔案目錄 prefix: 檔案名稱的開頭, 至少需要 3 chars. suffix: 檔案的副檔名, 若沒指明, 內定為.tmp 暫存檔不會在程式執行完後自動刪除 boolean delete() 要先刪除所有目錄內的檔案 子目錄之後, 方能刪除之 deleteonexit() 指明當程式執行完後, 刪除之 只能這樣用 File.createTempFile( list, null).deleteonexit(); listxxxx.tmp (c:\temp in windows seires) ( /tmp under Unix) Byte Input Streams InputStream InputStream 抽象類別 Java.lang.Object - java.io.inputstream InputStream 抽象類別中宣告了幾個基本的方法, 是 Java 主要用來處理位元組的類別 不能直接使用, 必須透過繼承它的子類別, 實作出內部的抽象方法後, 方能用之 所有屬於 InputStream 的類別, 都會具有共通的使用方法, 共有九個基本的抽象方法, 以下介紹 : abstract int read() 一定被實作到的方法會從 stream 中讀取一個位元組 (byte), 並以 int 型態傳回來 ; 如果傳回來的值是 -1, 表示已經讀到檔案結尾 (End of File) int read( byte [] buffer) 讀取一串位元組, 並存放到位元組的陣列之中, 傳回值表示實際讀到的位元組數 InputStream InputStream int read(byte [] buffer, int offset, int length ) 第二參數, 指定位元組陣列中的起始位置 (offset), 第三個參數是指要讀入 len 長度的位元資料並存於陣列中 傳回值表示實際讀到的位元組數 這三個 method 是 InputStream 最主要的功能, 提供了讀取資料的能力 void close() 當我們不再使用一個 InputStream 時, 使用 close() method 來關閉 stream 如果你串接了許多個 stream 一起運作, 當要關閉這些 stream 時, 只需要關閉最後的那一個 stream 就可以了, 其他底下的 stream 都會被自動的關閉 若有錯誤發生, 會丟出 IOException int available() 這會傳回從目前 stream 中立即可一次讀取到 ( 而不會被 blocking) 的位元組數量

9 InputStream (optional) InputStream long skip( long n ) 略過 stream 中指定數量的位元組 它會傳回真正略過的位元組數 有時我們會想要 重讀 之前讀過的位元組 boolean marksupported() marksupported() 會傳回一個 boolean 值, 表示是否支援 mark() 和 reset() void mark( int readlimit ) mark() 會在目前的輸入串流的位置做一個標示, 作為下次呼叫 reset() 時重新讀取的位置 mark() 的參數則說明這個標示的有效範圍為何, 一旦你讀超過指定的位元組數, 就無法 reset 到該位置了 void reset() 呼叫 reset() 會讓讀取的位置回到最近依次有效的 mark 處 若先前沒有 mark() 過, 使用 reset() 時會丟出 IOException Java 中沒有 open() 這方法, 任何一個資料串流, 只要一建立, 就可立即使用 InputStream 的子類別 FileInputStream 這類別提供了讀取檔案的低階工具 InputStream ByteArrayInputStream 這類別提供從一位元組陣列來讀取資料的方法 PipedInputStream 這類別可以讓程式讀取從 FilterInputStream 另一個 PipedOutputStream 物件一個過濾輸入串流的基本類別所輸出的位元組資料 SequenceInputStream 這類別可以連接多個輸入串流 Byte Output Streams OutputStream 抽象類別 Java.lang.Object - java.io.outputstream 輸出位元組的資料 與 InputStream 一樣,OutputStream 是一個抽象類別, 其中宣告了一些通用的方法, 只類別可以用來實作出內容 共有五個方法, 都不具有回傳值 : abstract write( int b ) 將一整數型態的參數以 bytecode 的方式輸出至串流 Output Streams OutputStream 的子類別 write( byte [] b ) 將一陣列輸出至串流 write( byte [] b, int offset, int length ) 從陣列 offset 的位置開始傳送 length 位元組的資料至輸出串流 flush() 這方法會強制 bufferred 的資料輸出至串流 close() 關閉輸出串流 當寫完資料之後, 用 close() 來關閉 OutputStream 類似 InputStream 的情況, 如果串接了許多個 stream, 只需要關閉最後那一個 stream, 就可以關閉所有的 stream 以上方法, 若出現錯誤都會丟出 IOException 53 OutputStream FilterOutputStream 一個過濾輸入串流的基本類別 FileOutputStream 這類別提供了讀取檔案的低階工具 ByteArrayOutputStream 這類別提供從一位元組陣列來讀取資料的方法 PipedOutputStream 這類別可以讓程式讀取從另一個 PipedOutputStream 物件所輸出的位元組資料 54 9

10 FileInputStream 透過 FileInputStream 與 FileOutputStream 這兩個 stream, 我們可以對檔案的做循序性的讀取 或寫入 FileInputStream 的建構子 : FileOutputStream( String filename ) FileOutputStream( File fileobj ) FileOutputStream( FileDecriptor desc ) 一個物件的指示 : 表示到一個檔案實體位置的連接 FileDescriptor 類別, 定義了三個 public static 成員 : in out err 對應到標準系統的輸入 輸出與錯誤串流 ps: 這是 System 這個類別不一樣 FileOutputStream FileOutputStream 的建構子 : FileOutputStream( String filename ) FileOutputStream( File fileobj ) FileOutputStream( String filename, boolean append ) append = true, 新增的資料可以附加在原有檔案的內容之後 可使用 getfd() 來或的這項資訊 FileOutputStream( FileDecriptor desc ) try { FileOutputStream file1 = new FileOutputStream("myFile.txt"); catch( IOException e) { System.out.println( afile + " not found"); ByteArrayInputStream (optional) ByteArrayInputStream java.lang.object java.io.inputstream java.io.bytearrayinputstream Constructor: ByteArrayInputStream ByteArayInputStream( byte [] buf ) ByteArayInputStream( byte [] buf, int offset, int length) ByteArrayInputStream (optional) protected int count protected byte [] buf protected in mark protected in pos int available() 可以從位元陣列輸入串流讀取的位元總數 void close() void mark( int readajeadlimit ) boolean marksupported() int read() int read( byte [] b, int off, int len ) void reset() long skip( long n ) ByteArrayOutputStream (optional) ByteArrayOutputStream (option) ByteArrayOutputStream java.lang.object java.io.outputstream java.io.bytearrayoutputstream Constructor ByteArrayOutputStream() ByteArrayOutputStream( int size ) 內定的位元陣列大小是 32 bytes, 亦可自行指定 59 Fileds protected byte [] buf 儲存資料的暫存區 protected int count 暫存區內已儲存的資料個數 Methods void close void reset int size() 取得暫存區的大小 byte [] tobytearray() - 以位元陣列的方式回傳暫存區內的內容 60 10

11 ByteArrayOutputStream (option) String tostring() - 以字串物件的的方式回傳暫存區內的內容 String tostring( String enc ) 根據所指定的字串編碼方式, 以字串物件的的方式回傳暫存區內的內容 利用定義在 OutputStreamWriter 類別裡的 getencoding() 方法, 可獲知目前使用機器的字串編碼方式 void write( byte [] b, int offset, int length ) void write( int b ); void writeto( OutputStream out ) PipedInputStream (optional) PipedInputStream 與 PipedOutputStream 這兩個串流需要一起成對的使用 使用在兩個程式 ( 通常是執行緒程式 ) 之間, 當作其溝通的管線 Process A PipedOutputStrea m Process B PipedInputStream SequenceInputStream SequenceInputStream 將多個檔案串流依序整合成一個 當讀取一個整合多個檔案串流的 SequenceInputStream 時, 會依照整合的順序依序讀取, 讀完一個後會自動關閉它並讀取下一個串流 對 SequenceInputStream 做 close() 的動作, 會關閉所有的串流 Constructor SequenceInputStream( stream1, stream2 ) SequenceInputStream( Enumeration obj ) 可以一次整合多個串流 FileInputStream file1 = new FileInputStream( /filename1 ); start file1 streams are joined. file2 end FileInputStream file1 = new FileInputStream( /filename2 ); SequenceInputStream combined = new SequenceInputStream( file1, file2 ); SequenceInputStream Vector streams = new Vector(); // add the streams to Vector streams.addelement( new FileInputStream( file1 ) ); streams.addelement( new FileInputStream( file2 ) ); streams.addelement( new FileInputStream( file3 ) ); streams.addelement( new FileInputStream( file4 ) ); // create a stream combing all four file input streams SequenceInputStream allfour = new SequenceInputStream( streams.elements() ); FileInputStream file3 = new FileInputStream( filenname3 ); FileInputStream file4 = new FileInputStream( filenname4 ); SequenceInputStream allfour = new SequenceInputStream( combined, new SequenceInputStream( file3, file4 ) ); FilterInputStream & FilterOutputStream

12 FilterInputStream & FilterOutputStream InputStream OutputStream 所提供來處理位元資料的方法, 在功能上都很基本 ( 陽春 ) 使用上不是很方便 為此, Java 定義了許多的子串流類別 ( 繼承於基本的串流類別 ) InputStream 有九個 OutputStream 有十個 本課程僅對較常用的子類別做介紹 輸入過濾類別 (Input Filter Classes) FilterInputStream 一個過濾輸入串流的基本類別 PushBackInputStream 這類別能將將一字元推回輸入串流 DataInputStream 提供從串流讀進基本型態的資料 BufferedInputStream 這類別可以將資料先從輸入串流讀到 buffer 要使用時, 從 buffer 讀進來 可減少讀取串流的次數, 增快程式執行速度 LineNumberInputStream 這類別提供記錄讀取的行數的工具 輸出過濾類別 (Output Filter Classes) FilterOutputStream 一個過濾輸入串流的基本類別 PrintStream 這類別提供格式化輸出到串流的工具 System 的輸出成員例如 :monitor 等即是以此方法作輸出 DataOutputStream 提供工具寫入基本型態的資料到串流以 bytecode 方式寫入, 無須再轉換 BufferedOutputStream 這類別可以將資料先寫到 buffer, 然後在輸出到串流可減少直接輸出到串流的次數, 增快程式執行速度 DataInputStream & DataOutputSream (option) public class DataInputStream extends FilterInputStream implements DataInput public class DataOutputStream extends FilterOutputStream implements DataOutput DataInputStream 與 DataOutputStream 提供了讀取 或寫入 Java 的基本資料型別 (primitive data type) 的方法 處理位元型態的資料 這兩個 stream 都屬於過濾器 (filter)stream, 為其它的 stream 提供了存取基本資料型別的能力 建立 DataInput/OuputStream 物件 (optional) 我們有三種可能使用到 Data Input/Output Stream 的時機 : 把以下三種物件傳入 Data Input/Output Stream 的建構子 : Piped Input/Output Stream ByteArray Input/Output Stream File Input/Output Stream step 1. File afile = new File( data.txt ); step 2. FileOutputStream fpstream = new FileOutputStream( afile ); step 3. DataOutputStream mystream = new DataOutputStream( fpstream ); DataInputStream DataInputStream 具有以下的 read methods: boolean readboolean() byte readbyte() short readshort() int readint() long readlong() char readchar() float readfloat() double readdouble() String readline()

13 DataOutputStream (option) void writeboolean( boolean value ) 1 byte void writebyte( int value ) 1 bytes void writeshort( int value ) 2 bytes void writeint( int value ) 4 bytes of the int argument void writelong( log valeu ) 8 bytes void writechar( char value) 2 bytes void writefloat( float value ) 4 bytes void writedouble( double value ) 8 bytes writechars( String str ) int size() 所有的方法 : 若有錯誤發生, 都可以丟出 IOException BufferedInputStream BufferedInputStream 與 BufferedOutputStream 是屬於 filter 類型的 stream, 串接在其他的 stream 之後, 用來提供 buffer 的功能, 以提昇運作的效率 可用來移動記憶體緩衝區串流的標記位置 Constructor BufferedInputStream( InputStream in ) BufferedInputStream( InputStream in, int size ) BufferedOutputStream (option) 在 Windows 環境下使用 BufferedOutputStream 串流, 內定的緩衝區大小為 512 bytes Constructor BufferedOutputStream( OutputStream out ) BufferedOutputStream( OutputStream out, int size ) Fields protected byte [] buf protected int count Methods void flush() void write( byte [] b, int offset, int length ) void write( int b ) 75 PrintStream 我們一直使用的 println() 事實上是定義在 PrintStream 這類別中,System.out.println() 使用到的就是這類別的方法 早期的 Java 中, 這是唯一的方法 : 可以直接將資本型態的位元資料以字串輸出 在 PrintWriter 這類別出現之後, 漸漸取代 PrintStream 類別 原因是,PrintWriter 改進了 PrintStream, 能處理對於 Unicode 與的機器上字元編碼之間的轉換問題 76 Reader 與 Writer java.lang.object java.io.writer; java.io.writer 字元型態的輸入與輸出串流, Java 分別定義了兩個抽象類別 :Reader 與 Writer 提供的基本的方法, 以利爾後相關子類別的發展 它們也都具備類似 InputStream 和 OutputStream 的 read() write() 方法, 使用起來也差不多, 唯一的差別只是 它們讀寫的都是 char, 而不是 byte Reader 與 Writer 如果有讀寫 String 的需要, 由於牽涉到字元集的轉換, 因此建議使用 Reader 和 Writer Unicode Java 使用 unicode 來表示字元 (char) 和字串 (String), 而 unicode 是 16-bit 的資料, 不同於 InputStream 和 OutputStream 所處理的 byte(8-bit) Java 另外提供了處理 charcter stream 的類別, 叫做 Reader 和 Writer

14 StringReader 從一字串讀進資料從一字串讀進資料 CharArrayReader 從一字元陣列讀進資料從一字元陣列讀進資料 PipedReader 從 PipedWriter PipedWriter 讀進資料讀進資料 字元輸入串流 Reader Reader (abstract) (abstract) InputStreamReader 從 InputStream InputStream 讀進資料讀進資料 FileReader 從 File File 物件讀進資料物件讀進資料 BufferedReader 暫存從串流讀進的資料暫存從串流讀進的資料 FilterReader 過濾氣得抽象基底過濾氣得抽象基底 PushbackReader 過濾器過濾器可以將字元回填回串流可以將字元回填回串流 LineNumberReader 記錄行數記錄行數 79 Reader 抽象類別 Constructor: protected Reader() protected Reader( Object lock) Fields: protected Object lock 同步作業所需要的鎖定動握 Methods: int read() 從串流讀進一個字元, 並以 int 型態回傳, 若已經到串流的尾端, 回傳 -1 int read( char [] array ) abstract read( char [] array, int offset, int length ) 80 Reader 抽象類別 boolean marksupported() void mark( in readaheadlimit ) void reset() boolean ready() long skip( long charcount ) abstract void close() StringWriter 輸出一字串輸出一字串 CharArrayWriter 輸出一字元陣列輸出一字元陣列 PipedWriter 輸出資料至一個對應的輸出資料至一個對應的 PipedReader PipedReader 字元輸出串流 Writer Writer Writer (abstract) (abstract) OutputStreamWriter 輸出資料至一個輸出資料至一個 OutputStream OutputStream BufferedWriter 暫存要輸出至串流的資料暫存要輸出至串流的資料 FilterWriter 過濾氣得抽象基底過濾氣得抽象基底 PrintWriter 將字串輸出到將字串輸出到 Writer Writer 81 FileWriter 輸出至一個輸出至一個 File File 物件物件 82 Writer 抽象類別 InputStreamReader Constructor: protected Writer() protected Writer( Object lock ) Fields: protected Object lock 同步作業所需要的鎖定動握 Methods: void write( char c) void write( String str ) void write( String str, int offset, int length ) void write( char [] array ) abstract void write( char [] array, int offset, int length) abstract void flush() java.io.reader java.io.inputstreamreader 要從鍵盤輸入字元的話, 可利用 System.in 來建構一個 InputStreamReader 的字元串流, 接著使用 read() 來讀取輸入的字元 Constructors: InputStreamReader( InputStream in ) InputStreamReader( InputStream in, String encoding ) abstract void close()

15 FileWriter 以字元的方式寫入檔案串流 java.io.writer java.io.outputstreamwriter java.io.filewriter Constructor FileWriter( File afile ) FileWriter( FileDescriptor filedesc ) FileDescriptor FileWriter( String filename ) FileWriter( String filename, boolean append ) FileReader 以字元的方式讀取檔案串流 An Example to try FileReader import java.io.*; class TryFileReader { public static void main(string args[]) throws Exception { FileReader filereader = new FileReader("file.txt"); char data[] = new char[1024]; int charsread = filereader.read(data); System.out.println(new String(data, 0, charsread)); filereader.close(); BufferedReader BufferedReader BufferedReader 與 BufferedWriter 這兩個類別, 可以將 Unicode 的字元, 轉換成為目前本機器所採用的字元編碼方式, 還輸出 輸出 與 BufferedInputStream 和 BufferOutputStream 相似, 如果讀寫的動作是發生在適合區塊的裝置上 ( 像是檔案 ), 把 BufferedReader 或 BufferedWriter 串接在 Reader Writer 之後, 對效率有很大的幫助 從系統的標準輸入 ( 通常是鍵盤 ) 讀字串, 並自動成機器所使用的字元編碼 : BufferedReader in = new BufferedReader( new InputStreamReader( System.in ) ); String input = in.readline(); BufferedReader 的好處不只是提供 buffer, 還提供了一個方法可以用來一次讀取一行字串 : String readline() BufferedWriter PrintWriter Character Streams 從系統的標準輸出 ( 通常是螢幕 ) 印出字串, 並自動成機器所使用的字元編碼 : Writer out = new BufferedWriter( new OutputStreamWriter(System.out) ); Constructor BufferedWriter( Writer out ) BufferedWriter( Writer out, int initialsize) Method void close(), fluse(), newline() 寫入換行字元 void write( int c) void write( char [] buffer, int offset, int length ) void write( String s, int offset, int length ) 這串流很好用 : 可以將資本型態的資料轉成以字元的方式來輸出 ( 呼叫 char, char [], String, Object, boolean, int, long, double, float 這些型態的 tosting() 與 String 類別的 valueof()) Constructors PrintWriter( OutputStream stream ) PrintWriter( OutputStream stream, boolean flush ) PrintWriter( Writer writer ) PrintWriter( Writer writer, boolean flush ) methods: print() println()

16 Optional course RandomAccessFile 如果一個檔案要被用來充當作為資料庫的話, 我們會希望能夠存取檔案的任意一個地方, 而不只是循序地從頭讀到尾 RandomAccessFile 這類別提供了許多的方法來滿足需求 RandomAccessFile 串流與其他串流不一樣的地方 : 可以同時對一個檔案做資料的輸入 與輸出 RandomAccessFile 的定義了與 DataInputStream DataOutputStream 完全相同的方法 ( 因為他們都都實作了相同的介面 ) 所以可以使用相同名稱的 read write 等方法來讀寫 RandomAccessFile 類別 RandomAccessFile 類別 Constructor RandomAccessFile( String file_pathname, String mode ) RandomAccessFile( File file, String mode ) mode 只有兩種可能的值,"r" 或 "rw" "r" - read only mode "rw" - read/write mode File myprimes = new File( C:/te,p/MyData/Primes.txt ); RandomAccessFile myfile = new RandomAccessFile( myprimes, rw ); 改變檔案指標的位置 (offset),randomaccessfile 提供三個方法以進行隨機的存取 : long getfilepointer() 傳回檔案指標 ( 從檔案頭到目前 ) 的位置 void seek(long pos) 移動檔案指標到指定的位置, 接下來所有的讀寫動作, 都將從這個指定的位置開始 long length() 傳回檔案的長度 ( 以 Byte 計算 ) An Example to Try RandomAccessFile RandomAccessFile 類別 如果要在檔案的末端加入新的資料, 可以這麼用 : myrafile.seek(myrafile.length()); myrafile.writexxx(...); // xxx 對應到資本型態 import java.io.*; public class TryRandomAccessFile { public static void main(string args[]) throws Exception { String mystr = new String("Hello in, Hello out"); RandomAccessFile myrastream = new RandomAccessFile("C:/temp/MyData/temp.txt", "rw" ); myrastream.writechars("line 1: " + mystr + "\n"); myrastream.writechars("line 2: " + mystr + "\n" ); myrastream.writebytes("line 3: " + mystr + "\n"); myrastream.writebytes("line 4: " + mystr + "\n"); myrastream.close(); [next]

17 RandomAccessFile RAin = new RandomAccessFile("C:/temp/MyData/temp.txt", "rw"); String s; while((s = RAin.readLine())!= null) { System.out.println( s + " " +.length()); long pos = RAin.getFilePointer(); System.out.println( pos ); RAin.seek( pos - 56 ); while( (s = RAin.readLine())!= null ) { System.out.println( s ); RAin.close(); D:\My Documents\Java???????\code\lesson5>java test L i n e 1 : H e l l o i n, H e l l o o u t 55 L i n e 2 : H e l l o i n, H e l l o o u t 55 // writechars Line 3: Hello in, Hello out 27 Line 4: Hello in, Hello out 27 // writebytes 168 Line 3: Hello in, Hello out Line 4: Hello in, Hello out Object Serialization( 序列化 ) 從一個檔案輸入 或輸出一個物件的程序, 稱做 Serialization 一旦 Java 程式結束了, 所有在 JVM 中的 Java 物件都將隨之消失 為了讓物件的狀態可以繼續保存下來, 以便將來可以再度重新使用這個物件, 回覆到當時的狀態 Java 定義了 Object Serialization 的機制 如果一個物件是 serializable( 可以被序列化的 ), 那麼就可以藉由把序列化之後的物件, 以寫入串流的方式, 傳送或紀錄下這個物件的狀態 Serialization Serialization 一個物件要能被序列化, 有三個條件 : 第一個條件 : 物件的類別定義必須要實作 Serializable 介面 這個介面其實沒有任何需要被實現的 method, 純粹只是用來標示該物件是能被序列化的 ( 類似 cloneable) 第二個條件 : 被這類別直接 或間接所繼承的類別, 本身也需要是 Serializable; 若沒實作這介面, 則這些被繼承的類別中, 必須要有一個空的建構子在其中 第三個條件 : 物件的類別定義必須宣告為 public 否則會出現 InvalidClassException 對一個將被序列化的物件中, 不能含有不能被序列化的物件 有些物件由於本質上就是不斷在改變的, 因而不能被序列化, 例如 : java.lang.thread 等 或 java.awt.graphic Serialization Writing 與 Reading 序列化物件 只要含有這種不能被序列化的物件, 整個物件在序列化的過程就會失敗, 而發生 NotSerializableException 不過這個問題可以藉由宣告該物件為 transient 來解決 ObjectInputStream 和 ObjectOutputStream 分別衍生自 DataInputStream 與 DataOurputStream 透過 ObjectInputStream 和 ObjectOutputStream, 我們可以將序列化的物件輸入 輸出至 Stream public class TestClass implements Serializable { ObjectOutputStream objout = new ObjectOutputStream( public transient Thread mythread; private String data; public int amount; new FileOutputStream("date.ser")); objout.writeobject( new Date() ); writeobject() method 用來把物件序列化, 並寫入 stream 中 // 序列化的資料中將不會包含 mythread 這成員

18 Writing 與 Reading 序列化物件 Serialization 的問題 ObjectInputStream objin = new ObjectInputStream( new FileInputStream("date.ser") ); Date d = (Date) objin.readobject(); readobject() 可以從 stream 中讀回一個物件, 不過要記得做 casting ( 型態轉換 ) 的動作 回憶 : Object tempobj = objin.readobject(); if( tempobj.getclass().getname().equals( MyClass ) ) MyClass myobj = (MyClass) tempobj; 因為所有的物件都是參照型態, 所以當你已經把一個物件序列化輸出到一個檔案串流後, 若程式之後又更改了物件的內容, 想要再把它寫進去檔案串流時 : 先前已經寫進去的物件不會被取代, 後來的物件無法覆蓋先前的, 所以, 修改過的內容將不會被紀錄到 理由是 : 檔案裡頭只會對同一個名稱的物件指定一個參照 解決的方法 : reset(); // 使物件串流 忘記 先前的同名物件 An Example to Try Serialization import java.io.*; public class TrySerialization { public static void main(string args[]) { NewString inobject, outobject; inobject = new NewString(""); outobject = new NewString("Hello from Java!"); class NewString implements Serializable { String data; public NewString(String instring) { data = instring; public String tostring() { return data; try { FileOutputStream fout = new FileOutputStream("serialized.dat"); ObjectOutputStream objout = new ObjectOutputStream( fout ); objout.writeobject(outobject); objout.flush(); objout.close(); FileInputStream fin = new FileInputStream("serialized.dat"); ObjectInputStream objin = new ObjectInputStream( fin ); inobject = (NewString)objin.readObject(); objin.close(); catch(exception e) { System.out.println(inobject); 105 D:\My Documents\Java???????\code\lesson5>java TrySerialization Hello from Java!

Microsoft PowerPoint ppt

Microsoft PowerPoint ppt Java 程式設計基礎班 (6) 莊坤達台大電信所網路資料庫研究室 Email: doug@arbor.ee.ntu.edu.tw Class 6 1 回顧 Java Inner class Class/Object 基本使用方法 Class 6 2 Java Utilities 字元與字串 (String) StringBuffer Class 6 3 String 類別 java.lang.string

More information

Java Access 5-1 Server Client Client Server Server Client 5-2 DataInputStream Class java.io.datainptstream (extends) FilterInputStream InputStream Obj

Java Access 5-1 Server Client Client Server Server Client 5-2 DataInputStream Class java.io.datainptstream (extends) FilterInputStream InputStream Obj Message Transition 5-1 5-2 DataInputStream Class 5-3 DataOutputStream Class 5-4 PrintStream Class 5-5 (Message Transition) (Exercises) Java Access 5-1 Server Client Client Server Server Client 5-2 DataInputStream

More information

untitled

untitled Velocity 14 100061 315@pptph.com.cn http://www.pptph.com.cn 010-67129212 010-67129211 787 1092 1/16 22 535 1 0 000 2001 11 1 2001 11 1 ISBN 7-115-09828-X/TP 2577 32.00 01067129223 1 2 1 2 3 4 5 1 Velocity

More information

Microsoft Word - 投影片ch14

Microsoft Word - 投影片ch14 Java2 JDK5.0 教學手冊第三版洪維恩編著博碩文化出版書號 pg20210 第十四章檔案處理 本章學習目標認識串流學習檔案的開啟與關閉學習如何處理文字檔學習如何處理二進位檔 檔案處理 14-2 14.1 關於串流 串流可分為 輸入串流 (input stream) 與 輸出串流 (output stream) 兩種 下圖說明了串流如何做為檔案處理的橋樑 : stream 資料 input stream

More information

JavaIO.PDF

JavaIO.PDF O u t p u t S t ream j a v a. i o. O u t p u t S t r e a m w r i t e () f l u s h () c l o s e () public abstract void write(int b) throws IOException public void write(byte[] data) throws IOException

More information

OOP with Java 通知 Project 6: 5 月 30 日晚 9 点

OOP with Java 通知 Project 6: 5 月 30 日晚 9 点 OOP with Java Yuanbin Wu cs@ecnu OOP with Java 通知 Project 6: 5 月 30 日晚 9 点 复习 异常处理 语法 抛出异常 : throw 处理异常 : try, catch 异常对象 : Exception 类的子类 从方法中抛出异常 方法的异常说明 :throws 中断当前方法的执行, 返回抛出的异常对象, 在该方法的调用路径上寻找合适的

More information

OOP with Java 通知 Project 6: 6 月 6 日晚 9 点

OOP with Java 通知 Project 6: 6 月 6 日晚 9 点 OOP with Java Yuanbin Wu cs@ecnu OOP with Java 通知 Project 6: 6 月 6 日晚 9 点 复习 异常处理 语法 抛出异常 : throw 处理异常 : try, catch 异常对象 : Exception 类的子类 从方法中抛出异常 方法的异常说明 :throws 中断当前方法的执行, 返回抛出的异常对象, 在该方法的调用路径上寻找合适的

More information

3.1 num = 3 ch = 'C' 2

3.1 num = 3 ch = 'C' 2 Java 1 3.1 num = 3 ch = 'C' 2 final 3.1 final : final final double PI=3.1415926; 3 3.2 4 int 3.2 (long int) (int) (short int) (byte) short sum; // sum 5 3.2 Java int long num=32967359818l; C:\java\app3_2.java:6:

More information

Chapter 9: Objects and Classes

Chapter 9: Objects and Classes Fortran Algol Pascal Modula-2 BCPL C Simula SmallTalk C++ Ada Java C# C Fortran 5.1 message A B 5.2 1 class Vehicle subclass Car object mycar public class Vehicle extends Object{ public int WheelNum

More information

OOP with Java 通知 Project 6: 5 月 24 日晚 9 点

OOP with Java 通知 Project 6: 5 月 24 日晚 9 点 OOP with Java Yuanbin Wu cs@ecnu OOP with Java 通知 Project 6: 5 月 24 日晚 9 点 复习 异常处理 语法 抛出异常 : throw 处理异常 : try, catch 异常对象 : Exception 类的子类 从方法中抛出异常 方法的异常说明 :throws 中断当前方法的执行, 返回抛出的异常对象, 在该方法的调用路径上寻找合适的

More information

Microsoft Word - JAVA Programming Language Homework VI_ans.doc

Microsoft Word - JAVA Programming Language Homework VI_ans.doc JAVA Programming Language Homework VI: Threads & I/O ID: Name: 1. When comparing java.io.bufferedwriter to java.io.filewriter, which capability exists as a method in only one of the two? A. Closing the

More information

EJB-Programming-3.PDF

EJB-Programming-3.PDF :, JBuilder EJB 2.x CMP EJB Relationships JBuilder EJB Test Client EJB EJB Seminar CMP Entity Beans Value Object Design Pattern J2EE Design Patterns Value Object Value Object Factory J2EE EJB Test Client

More information

1: public class MyOutputStream implements AutoCloseable { 3: public void close() throws IOException { 4: throw new IOException(); 5: } 6:

1: public class MyOutputStream implements AutoCloseable { 3: public void close() throws IOException { 4: throw new IOException(); 5: } 6: Chapter 15. Suppressed Exception CH14 Finally Block Java SE 7 try-with-resources JVM cleanup try-with-resources JVM cleanup cleanup Java SE 7 Throwable getsuppressed Throwable[] getsuppressed() Suppressed

More information

KillTest 质量更高 服务更好 学习资料 半年免费更新服务

KillTest 质量更高 服务更好 学习资料   半年免费更新服务 KillTest 质量更高 服务更好 学习资料 http://www.killtest.cn 半年免费更新服务 Exam : 1Z0-854 Title : Java Standard Edition 5 Programmer Certified Professional Upgrade Exam Version : Demo 1 / 12 1.Given: 20. public class CreditCard

More information

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc References (Section 5.2) Hsuan-Tien Lin Deptartment of CSIE, NTU OOP Class, March 15-16, 2010 H.-T. Lin (NTU CSIE) References OOP 03/15-16/2010 0 / 22 Fun Time (1) What happens in memory? 1 i n t i ; 2

More information

D C 93 2

D C 93 2 D9223468 3C 93 2 Java Java -- Java UML Java API UML MVC Eclipse API JavadocUML Omendo PSPPersonal Software Programming [6] 56 8 2587 56% Java 1 epaper(2005 ) Java C C (function) C (reusability) eat(chess1,

More information

EJB-Programming-4-cn.doc

EJB-Programming-4-cn.doc EJB (4) : (Entity Bean Value Object ) JBuilder EJB 2.x CMP EJB Relationships JBuilder EJB Test Client EJB EJB Seminar CMP Entity Beans Session Bean J2EE Session Façade Design Pattern Session Bean Session

More information

Slide 1

Slide 1 Java 程式設計入門 講師 : 陳昭源 CSIE, NTU August 3, 2005 Outline Character & String Exercise August 3, 2005 Page 2 Character & String 處理字元資料時,Java 有三個類別可供使用 Character: 處理單一字元 String: 處理內容不改變 (immutable) 的字串 StringBuffer:

More information

投影片 1

投影片 1 資料庫管理程式 ( 補充教材 -Part2) 使用 ADO.NET 連結資料庫 ( 自行撰寫程式碼 以實現新增 刪除 修改等功能 ) Private Sub InsertButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InsertButton.Click ' 宣告相關的 Connection

More information

KillTest 质量更高 服务更好 学习资料 半年免费更新服务

KillTest 质量更高 服务更好 学习资料   半年免费更新服务 KillTest 质量更高 服务更好 学习资料 http://www.killtest.cn 半年免费更新服务 Exam : 310-055Big5 Title : Sun Certified Programmer for the Java 2 Platform.SE 5.0 Version : Demo 1 / 22 1. 11. public static void parse(string str)

More information

chp6.ppt

chp6.ppt Java 软 件 设 计 基 础 6. 异 常 处 理 编 程 时 会 遇 到 如 下 三 种 错 误 : 语 法 错 误 (syntax error) 没 有 遵 循 语 言 的 规 则, 出 现 语 法 格 式 上 的 错 误, 可 被 编 译 器 发 现 并 易 于 纠 正 ; 逻 辑 错 误 (logic error) 即 我 们 常 说 的 bug, 意 指 编 写 的 代 码 在 执 行

More information

主程式 : public class Main3Activity extends AppCompatActivity { ListView listview; // 先整理資料來源,listitem.xml 需要傳入三種資料 : 圖片 狗狗名字 狗狗生日 // 狗狗圖片 int[] pic =new

主程式 : public class Main3Activity extends AppCompatActivity { ListView listview; // 先整理資料來源,listitem.xml 需要傳入三種資料 : 圖片 狗狗名字 狗狗生日 // 狗狗圖片 int[] pic =new ListView 自訂排版 主程式 : public class Main3Activity extends AppCompatActivity { ListView listview; // 先整理資料來源,listitem.xml 需要傳入三種資料 : 圖片 狗狗名字 狗狗生日 // 狗狗圖片 int[] pic =new int[]{r.drawable.dog1, R.drawable.dog2,

More information

untitled

untitled 1 Outline 數 料 數 數 列 亂數 練 數 數 數 來 數 數 來 數 料 利 料 來 數 A-Z a-z _ () 不 數 0-9 數 不 數 SCHOOL School school 數 讀 school_name schoolname 易 不 C# my name 7_eleven B&Q new C# (1) public protected private params override

More information

雲端 Cloud Computing 技術指南 運算 應用 平台與架構 10/04/15 11:55:46 INFO 10/04/15 11:55:53 INFO 10/04/15 11:55:56 INFO 10/04/15 11:56:05 INFO 10/04/15 11:56:07 INFO

雲端 Cloud Computing 技術指南 運算 應用 平台與架構 10/04/15 11:55:46 INFO 10/04/15 11:55:53 INFO 10/04/15 11:55:56 INFO 10/04/15 11:56:05 INFO 10/04/15 11:56:07 INFO CHAPTER 使用 Hadoop 打造自己的雲 8 8.3 測試 Hadoop 雲端系統 4 Nodes Hadoop Map Reduce Hadoop WordCount 4 Nodes Hadoop Map/Reduce $HADOOP_HOME /home/ hadoop/hadoop-0.20.2 wordcount echo $ mkdir wordcount $ cd wordcount

More information

運算子多載 Operator Overloading

運算子多載 Operator Overloading 多型 Polymorphism 講師 : 洪安 1 多型 編譯時期多型 ( 靜態多型 ) function overloading 如何正確呼叫同名的函數? 利用參數個數與型態 operator overloading 其實同 function overloading 執行時期多型 ( 或動態多型 ) 如何正確呼叫不同物件的相同名稱的成員函數 利用繼承與多型 2 子類別與父類別物件間的指定 (assignment)

More information

Java java.lang.math Java Java.util.Random : ArithmeticException int zero = 0; try { int i= 72 / zero ; }catch (ArithmeticException e ) { // } 0,

Java java.lang.math Java Java.util.Random : ArithmeticException int zero = 0; try { int i= 72 / zero ; }catch (ArithmeticException e ) { // } 0, http://debut.cis.nctu.edu.tw/~chi Java java.lang.math Java Java.util.Random : ArithmeticException int zero = 0; try { int i= 72 / zero ; }catch (ArithmeticException e ) { // } 0, : POSITIVE_INFINITY NEGATIVE_INFINITY

More information

(TestFailure) JUnit Framework AssertionFailedError JUnit Composite TestSuite Test TestSuite run() run() JUnit

(TestFailure) JUnit Framework AssertionFailedError JUnit Composite TestSuite Test TestSuite run() run() JUnit Tomcat Web JUnit Cactus JUnit Java Cactus JUnit 26.1 JUnit Java JUnit JUnit Java JSP Servlet JUnit Java Erich Gamma Kent Beck xunit JUnit boolean JUnit Java JUnit Java JUnit Java 26.1.1 JUnit JUnit How

More information

JAVA String常用APi

JAVA String常用APi JAVA String 常 用API 2015 年 5 月13 日 星 期 三 ------------------------------------------ String 类 的 特 点 : 字 符 串 对 象 一 旦 被 初 始 化 就 不 会 被 改 变 abc 存 储 在 字 符 串 常 量 池 中 Java 的 核 心 类 包 是 java.lang eclipse:ctrl+ 方

More information

Chapter 9: Objects and Classes

Chapter 9: Objects and Classes Java application Java main applet Web applet Runnable Thread CPU Thread 1 Thread 2 Thread 3 CUP Thread 1 Thread 2 Thread 3 ,,. (new) Thread (runnable) start( ) CPU (running) run ( ) blocked CPU sleep(

More information

1.JasperReport ireport JasperReport ireport JDK JDK JDK JDK ant ant...6

1.JasperReport ireport JasperReport ireport JDK JDK JDK JDK ant ant...6 www.brainysoft.net 1.JasperReport ireport...4 1.1 JasperReport...4 1.2 ireport...4 2....4 2.1 JDK...4 2.1.1 JDK...4 2.1.2 JDK...5 2.1.3 JDK...5 2.2 ant...6 2.2.1 ant...6 2.2.2 ant...6 2.3 JasperReport...7

More information

while ((ch = fr.read())!= -1) { System.out.print((char) ch); fr.close(); 例 3: 用 BufferedReader 读 TXT 文件 public class FileReaderDemo3 { public static v

while ((ch = fr.read())!= -1) { System.out.print((char) ch); fr.close(); 例 3: 用 BufferedReader 读 TXT 文件 public class FileReaderDemo3 { public static v 第九章 Java I/O 流操作 实验目的 (1) 掌握文本文件的读写方法 (2) 掌握 InputStream OutputStream 的使用方法 (3) 熟悉 FileReader,BufferedReader,InputStreamReader 和 FileWriter, BufferedWriter, PrintWriter 的使用方法 ; 理解使用过滤流实现数据项的读写 :DataOutputStream,

More information

Microsoft Word - 01.DOC

Microsoft Word - 01.DOC 第 1 章 JavaScript 简 介 JavaScript 是 NetScape 公 司 为 Navigator 浏 览 器 开 发 的, 是 写 在 HTML 文 件 中 的 一 种 脚 本 语 言, 能 实 现 网 页 内 容 的 交 互 显 示 当 用 户 在 客 户 端 显 示 该 网 页 时, 浏 览 器 就 会 执 行 JavaScript 程 序, 用 户 通 过 交 互 式 的

More information

使 用 Java 语 言 模 拟 保 险 箱 容 量 门 板 厚 度 箱 体 厚 度 属 性 锁 具 类 型 开 保 险 箱 关 保 险 箱 动 作 存 取 款

使 用 Java 语 言 模 拟 保 险 箱 容 量 门 板 厚 度 箱 体 厚 度 属 性 锁 具 类 型 开 保 险 箱 关 保 险 箱 动 作 存 取 款 JAVA 程 序 设 计 ( 肆 ) 徐 东 / 数 学 系 使 用 Java 语 言 模 拟 保 险 箱 容 量 门 板 厚 度 箱 体 厚 度 属 性 锁 具 类 型 开 保 险 箱 关 保 险 箱 动 作 存 取 款 使 用 Java class 代 表 保 险 箱 public class SaveBox 类 名 类 类 体 实 现 封 装 性 使 用 class SaveBox 代 表 保

More information

Microsoft PowerPoint - ch7_1 DA class

Microsoft PowerPoint - ch7_1 DA class Quiz 1. Describe the similarities and differences of Tester class and GUI class 2. What is the function of GUI class? 3. What is the function of PD(problem domain) class? 4. How does a GUI class interact

More information

Python a p p l e b e a r c Fruit Animal a p p l e b e a r c 2-2

Python a p p l e b e a r c Fruit Animal a p p l e b e a r c 2-2 Chapter 02 變數與運算式 2.1 2.1.1 2.1.2 2.1.3 2.1.4 2.2 2.2.1 2.2.2 2.2.3 type 2.2.4 2.3 2.3.1 print 2.3.2 input 2.4 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 + 2.4.6 Python Python 2.1 2.1.1 a p p l e b e a r c 65438790

More information

Microsoft Word - newJavaA4.doc

Microsoft Word - newJavaA4.doc P74 拾壹. 基本輸入與輸出 一. 使用的物件 1.Java 的輸入與輸出會使用到 Java.lang 套件中的 System 類別與 Java.io 套件, 其中 Java.io 套件中以 Reader/Writer 與 InputStream/OutputStream 類別最 重要, 前者以字元 (Character) 為導向, 後者以位元組 (Byte) 為導向 2.System 類別中最主要宣告了三個類別物件,System.in

More information

chp7.ppt

chp7.ppt Java 软件设计基础 7. Java 的基本可重用类 1.Java 可重用类的结构 Java 语言中将功能相关的可重用类组织成包, 可重用类的继承层次和包的组织呈树形结构 M L L L L L Java 可重用类按功能可划分为 : java.lang 是 Java 语言的核心包, 主要含有与语言相关的类 ; 提供如基本数据类型处理 基本数值函数 字符串处理 线程 异常处理等基本功能 ; 由解释程序自动加载,

More information

CC213

CC213 : (Ken-Yi Lee), E-mail: feis.tw@gmail.com 9 [P.11] : Dev C++ [P.12] : http://c.feis.tw [P.13] [P.14] [P.15] [P.17] [P.23] Dev C++ [P.24] [P.27] [P.34] C / C++ [P.35] 10 C / C++ C C++ C C++ C++ C ( ) C++

More information

Microsoft Word - ch04三校.doc

Microsoft Word - ch04三校.doc 4-1 4-1-1 (Object) (State) (Behavior) ( ) ( ) ( method) ( properties) ( functions) 4-2 4-1-2 (Message) ( ) ( ) ( ) A B A ( ) ( ) ( YourCar) ( changegear) ( lowergear) 4-1-3 (Class) (Blueprint) 4-3 changegear

More information

The Embedded computing platform

The Embedded computing platform 嵌入式系統及實驗 Embedded System and Experiment 詹曉龍 長庚大學電機系 Java 的類別與物件 : 宣告類別 建構子 public class Customer { private String name; private String address; // Customer 類別宣告 // 成員資料 public int age; // 建構子 : 使用參數設定成員資料初始值

More information

概述

概述 OPC Version 1.6 build 0910 KOSRDK Knight OPC Server Rapid Development Toolkits Knight Workgroup, eehoo Technology 2002-9 OPC 1...4 2 API...5 2.1...5 2.2...5 2.2.1 KOS_Init...5 2.2.2 KOS_InitB...5 2.2.3

More information

2009年9月全国计算机等级考试二级Java真题及答案

2009年9月全国计算机等级考试二级Java真题及答案 2009 年 9 月 全 国 计 算 机 等 级 考 试 二 级 Java 真 题 及 答 案 [ 录 入 者 :NCRE100 时 间 :2009-10-08 19:41:34 作 者 : 来 源 :NCRE100.com 浏 览 :1421 次 ] 2009 年 9 月 全 国 计 算 机 等 级 考 试 二 级 笔 试 试 卷 Java 语 言 程 序 设 计 ( 考 试 时 间 90 分 钟,

More information

Microsoft PowerPoint - course2.ppt

Microsoft PowerPoint - course2.ppt Java 程 式 設 計 基 礎 班 (2) 莊 坤 達 台 大 電 信 所 網 路 資 料 庫 研 究 室 Email: doug@arbor.ee.ntu.edu.tw Class 2 1 回 顧 Eclipse 使 用 入 門 Class 2 2 Lesson 2 Java 程 式 語 言 介 紹 Class 2 3 Java 基 本 知 識 介 紹 大 小 寫 有 差 (Case Sensitive)

More information

1 4 1.1 4 1.2..4 2..4 2.1..4 3.4 3.1 Java.5 3.1.1..5 3.1.2 5 3.1.3 6 4.6 4.1 6 4.2.6 5 7 5.1..8 5.1.1 8 5.1.2..8 5.1.3..8 5.1.4..9 5.2..9 6.10 6.1.10

1 4 1.1 4 1.2..4 2..4 2.1..4 3.4 3.1 Java.5 3.1.1..5 3.1.2 5 3.1.3 6 4.6 4.1 6 4.2.6 5 7 5.1..8 5.1.1 8 5.1.2..8 5.1.3..8 5.1.4..9 5.2..9 6.10 6.1.10 Java V1.0.1 2007 4 10 1 4 1.1 4 1.2..4 2..4 2.1..4 3.4 3.1 Java.5 3.1.1..5 3.1.2 5 3.1.3 6 4.6 4.1 6 4.2.6 5 7 5.1..8 5.1.1 8 5.1.2..8 5.1.3..8 5.1.4..9 5.2..9 6.10 6.1.10 6.2.10 6.3..10 6.4 11 7.12 7.1

More information

x MapReduce A Italic URL Constant width Constant width bold Constant width italic 這個圖示代表提示或建議 這個圖示代表一般註解

x MapReduce A Italic URL Constant width Constant width bold Constant width italic 這個圖示代表提示或建議 這個圖示代表一般註解 Java R Python Java Java Java x MapReduce A Italic URL Constant width Constant width bold Constant width italic 這個圖示代表提示或建議 這個圖示代表一般註解 第一章 I/O double[][] int[] String[] List 2 Map JavaScript Object Notation

More information

[Short Essay:] 1. (5 points) Use state-of-memory diagram to describe the differences between x and y declared as follows: double[] x = new double[4];

[Short Essay:] 1. (5 points) Use state-of-memory diagram to describe the differences between x and y declared as follows: double[] x = new double[4]; Introduction to Programming (II) Spring 2008, Final Exam Name: ID Number: [True/False:] (5 points each) If your answer is "false", you have to provide correct reasons. Otherwise, no points will be given.

More information

第1章

第1章 第 12 章 資料檔案管理 1 本章提要 12.1 前言 12.2 資料讀取 Reader/InputStream 12.2.1. Reader/InputStream 12.2.2. System 類別 12.3 資料建檔 Writer/OutputStream 12.4 資料修改 RandomAccessFile 12.5 變更及移動檔案 12.6 檔案列表 12.7 後記 2 12.1 前言

More information

untitled

untitled 4.1AOP AOP Aspect-oriented programming AOP 來說 AOP 令 理 Cross-cutting concerns Aspect Weave 理 Spring AOP 來 AOP 念 4.1.1 理 AOP AOP 見 例 來 例 錄 Logging 錄 便 來 例 行 留 錄 import java.util.logging.*; public class HelloSpeaker

More information

0 0 = 1 0 = 0 1 = = 1 1 = 0 0 = 1

0 0 = 1 0 = 0 1 = = 1 1 = 0 0 = 1 0 0 = 1 0 = 0 1 = 0 1 1 = 1 1 = 0 0 = 1 : = {0, 1} : 3 (,, ) = + (,, ) = + + (, ) = + (,,, ) = ( + )( + ) + ( + )( + ) + = + = = + + = + = ( + ) + = + ( + ) () = () ( + ) = + + = ( + )( + ) + = = + 0

More information

<4D6963726F736F667420506F776572506F696E74202D20332D322E432B2BC3E6CFF2B6D4CFF3B3CCD0F2C9E8BCC6A1AAD6D8D4D8A1A2BCCCB3D0A1A2B6E0CCACBACDBEDBBACF2E707074>

<4D6963726F736F667420506F776572506F696E74202D20332D322E432B2BC3E6CFF2B6D4CFF3B3CCD0F2C9E8BCC6A1AAD6D8D4D8A1A2BCCCB3D0A1A2B6E0CCACBACDBEDBBACF2E707074> 程 序 设 计 实 习 INFO130048 3-2.C++ 面 向 对 象 程 序 设 计 重 载 继 承 多 态 和 聚 合 复 旦 大 学 计 算 机 科 学 与 工 程 系 彭 鑫 pengxin@fudan.edu.cn 内 容 摘 要 方 法 重 载 类 的 继 承 对 象 引 用 和 拷 贝 构 造 函 数 虚 函 数 和 多 态 性 类 的 聚 集 复 旦 大 学 计 算 机 科 学

More information

2009年3月全国计算机等级考试二级Java语言程序设计笔试试题

2009年3月全国计算机等级考试二级Java语言程序设计笔试试题 2009 年 3 月 全 国 计 算 机 等 级 考 试 笔 试 试 卷 二 级 Java 语 言 程 序 设 计 ( 考 试 时 间 90 分 钟, 满 分 100 分 ) 一 选 择 题 ( 每 题 2 分, 共 70 分 ) 下 列 各 题 A) B) C) D) 四 个 选 项 中, 只 有 一 个 选 项 是 正 确 的 请 将 正 确 选 项 填 涂 在 答 题 卡 相 应 位 置 上,

More information

Learning Java

Learning Java Java Introduction to Java Programming (Third Edition) Prentice-Hall,Inc. Y.Daniel Liang 2001 Java 2002.2 Java2 2001.10 Java2 Philip Heller & Simon Roberts 1999.4 Java2 2001.3 Java2 21 2002.4 Java UML 2002.10

More information

CC213

CC213 : (Ken-Yi Lee), E-mail: feis.tw@gmail.com 49 [P.51] C/C++ [P.52] [P.53] [P.55] (int) [P.57] (float/double) [P.58] printf scanf [P.59] [P.61] ( / ) [P.62] (char) [P.65] : +-*/% [P.67] : = [P.68] : ,

More information

任務二 : 產生 20 個有炸彈的磚塊, 放在隨機的位置編輯 Block 類別的程式碼 import greenfoot.; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) Write a description of class

任務二 : 產生 20 個有炸彈的磚塊, 放在隨機的位置編輯 Block 類別的程式碼 import greenfoot.; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) Write a description of class 踩地雷遊戲 高慧君南港高中 開啟專案 MineSweep 任務一 : 產生 30X20 個磚塊編輯 Table 類別的程式碼 import greenfoot.; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.util.arraylist; Write a description of class MyWorld

More information

目 录 实 验 一 : 熟 悉 Java 开 发 环 境... 1 实 验 二 : 类 与 面 向 对 象... 7 实 验 三 : 继 承 和 多 态... 13 实 验 四 : 异 常 处 理... 18 实 验 五 : 流 文 件 及 基 于 文 本 的 应 用... 23

目 录 实 验 一 : 熟 悉 Java 开 发 环 境... 1 实 验 二 : 类 与 面 向 对 象... 7 实 验 三 : 继 承 和 多 态... 13 实 验 四 : 异 常 处 理... 18 实 验 五 : 流 文 件 及 基 于 文 本 的 应 用... 23 Java 程 序 设 计 实 验 指 导 书 商 丘 学 院 计 算 机 科 学 与 技 术 学 院 张 艳 晓 目 录 实 验 一 : 熟 悉 Java 开 发 环 境... 1 实 验 二 : 类 与 面 向 对 象... 7 实 验 三 : 继 承 和 多 态... 13 实 验 四 : 异 常 处 理... 18 实 验 五 : 流 文 件 及 基 于 文 本 的 应 用... 23 实 验

More information

/ / (FC 3)...

/ / (FC 3)... Modbus/TCP 1.0 1999 3 29 Andy Swales Schneider aswales@modicon.com ... 2 1.... 3 2.... 3 2.1.. 3 2.2..4 2.3..4 2.4... 5 3.... 5 3.1 0... 5 3.2 1... 5 3.3 2... 6 3.4 / /... 7 4.... 7 5.... 8 5.1 0... 9

More information

untitled

untitled 1 行 行 行 行.NET 行 行 類 來 行 行 Thread 類 行 System.Threading 來 類 Thread 類 (1) public Thread(ThreadStart start ); Name 行 IsAlive 行 行狀 Start 行 行 Suspend 行 Resume 行 行 Thread 類 (2) Sleep 行 CurrentThread 行 ThreadStart

More information

javaexample-02.pdf

javaexample-02.pdf n e w. s t a t i c s t a t i c 3 1 3 2 p u b l i c p r i v a t e p r o t e c t e d j a v a. l a n g. O b j e c t O b j e c t Rect R e c t x 1 y 1 x 2 y 2 R e c t t o S t r i n g ( ) j a v a. l a n g. O

More information

用手機直接傳值不透過網頁連接, 來當作搖控器控制家電 ( 電視遙控器 ) 按下按鍵發送同時會回傳值來確定是否有送出 問題 :1. 應該是使用了太多 thread 導致在傳值上有問題 2. 一次按很多次按鈕沒辦法即時反應

用手機直接傳值不透過網頁連接, 來當作搖控器控制家電 ( 電視遙控器 ) 按下按鍵發送同時會回傳值來確定是否有送出 問題 :1. 應該是使用了太多 thread 導致在傳值上有問題 2. 一次按很多次按鈕沒辦法即時反應 專題進度 老師 : 趙啟時老師 學生 : 陳建廷 2013/10/13 用手機直接傳值不透過網頁連接, 來當作搖控器控制家電 ( 電視遙控器 ) 按下按鍵發送同時會回傳值來確定是否有送出 問題 :1. 應該是使用了太多 thread 導致在傳值上有問題 2. 一次按很多次按鈕沒辦法即時反應 程式碼 : package com.example.phone; import java.util.arraylist;

More information

Spyder Anaconda Spyder Python Spyder Python Spyder Spyder Spyder 開始 \ 所有程式 \ Anaconda3 (64-bit) \ Spyder Spyder IPython Python IPython Sp

Spyder Anaconda Spyder Python Spyder Python Spyder Spyder Spyder 開始 \ 所有程式 \ Anaconda3 (64-bit) \ Spyder Spyder IPython Python IPython Sp 01 1.6 Spyder Anaconda Spyder Python Spyder Python Spyder Spyder 1.6.1 Spyder 開始 \ 所有程式 \ Anaconda3 (64-bit) \ Spyder Spyder IPython Python IPython Spyder Python File

More information

untitled

untitled 1 Outline ArrayList 類 列類 串類 類 類 例 理 MSDN Library MSDN Library 量 例 參 列 [ 說 ] [] [ 索 ] [] 來 MSDN Library 了 類 類 利 F1 http://msdn.microsoft.com/library/ http://msdn.microsoft.com/library/cht/ Object object

More information

epub83-1

epub83-1 C++Builder 1 C + + B u i l d e r C + + B u i l d e r C + + B u i l d e r C + + B u i l d e r 1.1 1.1.1 1-1 1. 1-1 1 2. 1-1 2 A c c e s s P a r a d o x Visual FoxPro 3. / C / S 2 C + + B u i l d e r / C

More information

Guava学习之Resources

Guava学习之Resources Resources 提供提供操作 classpath 路径下所有资源的方法 除非另有说明, 否则类中所有方法的参数都不能为 null 虽然有些方法的参数是 URL 类型的, 但是这些方法实现通常不是以 HTTP 完成的 ; 同时这些资源也非 classpath 路径下的 下面两个函数都是根据资源的名称得到其绝对路径, 从函数里面可以看出,Resources 类中的 getresource 函数都是基于

More information

Mac Java import com.apple.mrj.*;... public class MyFirstApp extends JFrame implements ActionListener, MRJAboutHandler, MRJQuitHandler {... public MyFirstApp() {... MRJApplicationUtils.registerAboutHandler(this);

More information

White Sketchpad PowerPoint Presentation

White Sketchpad PowerPoint Presentation 第五章 檔案存取 電商三乙 4A355001 郭雅如 4A355063 周宛萱 5-1-1 取得檔案名稱 但排除副檔名 5-1-2 取得路徑資訊

More information

Microsoft Word - 投影片ch22

Microsoft Word - 投影片ch22 Java2 JDK5.0 教學手冊第三版洪維恩編著博碩文化出版書號 pg20210 第二十二章網路程式設計 本章學習目標認識網路學習如何取得文件的內容資訊學習如何建立 socket 連線學習如何建立 TCP 伺服程式與客戶程式 網路程式設計 22-2 22.1 網址與 InetAddress 類別的使用 IP 位址是以 4 個 8 bits 的數值, 以 10 進位來表示, 用來區分網路上的每一台電腦

More information

Microsoft Word - 11.doc

Microsoft Word - 11.doc 除 錯 技 巧 您 將 於 本 章 學 到 以 下 各 項 : 如 何 在 Visual C++ 2010 的 除 錯 工 具 控 制 下 執 行 程 式? 如 何 逐 步 地 執 行 程 式 的 敘 述? 如 何 監 看 或 改 變 程 式 中 的 變 數 值? 如 何 監 看 程 式 中 計 算 式 的 值? 何 謂 Call Stack? 何 謂 診 斷 器 (assertion)? 如 何

More information

Microsoft PowerPoint - string_kruse [兼容模式]

Microsoft PowerPoint - string_kruse [兼容模式] Strings Strings in C not encapsulated Every C-string has type char *. Hence, a C-string references an address in memory, the first of a contiguous set of bytes that store the characters making up the string.

More information

C H A P T E R 7 Windows Vista Windows Vista Windows Vista FAT16 FAT32 NTFS NTFS New Technology File System NTFS

C H A P T E R 7 Windows Vista Windows Vista Windows Vista FAT16 FAT32 NTFS NTFS New Technology File System NTFS C H P T E R 7 Windows Vista Windows Vista Windows VistaFT16 FT32NTFS NTFSNew Technology File System NTFS 247 6 7-1 Windows VistaTransactional NTFS TxFTxF Windows Vista MicrosoftTxF CIDatomicity - Consistency

More information

Microsoft Word - 投影片ch11

Microsoft Word - 投影片ch11 Java2 JDK5.0 教學手冊第三版洪維恩編著博碩文化出版書號 pg20210 第十一章抽象類別與介面 本章學習目標認識抽象類別學習介面的使用認識多重繼承與介面的延伸 抽象類別與介面 11-2 11.1 抽象類別 抽象類別的目的是要依據它的格式來修改並建立新的類別 11.1.1 定義抽象類別 定義抽象類別的語法如下 : abstract class 類別名稱 { 宣告資料成員 ; // 定義抽象類別

More information

untitled

untitled 1 MSDN Library MSDN Library 量 例 參 列 [ 說 ] [] [ 索 ] [] 來 MSDN Library 了 類 類 利 F1 http://msdn.microsoft.com/library/ http://msdn.microsoft.com/library/cht/ Object object 參 類 都 object 參 object Boxing 參 boxing

More information

<4D6963726F736F667420576F7264202D20C8EDC9E82DCFC2CEE7CCE22D3039C9CF>

<4D6963726F736F667420576F7264202D20C8EDC9E82DCFC2CEE7CCE22D3039C9CF> 全 国 计 算 机 技 术 与 软 件 专 业 技 术 资 格 ( 水 平 考 试 2009 年 上 半 年 软 件 设 计 师 下 午 试 卷 ( 考 试 时 间 14:00~16:30 共 150 分 钟 请 按 下 述 要 求 正 确 填 写 答 题 纸 1. 在 答 题 纸 的 指 定 位 置 填 写 你 所 在 的 省 自 治 区 直 辖 市 计 划 单 列 市 的 名 称 2. 在 答

More information

OOP with Java 通知 Project 4: 4 月 19 日晚 9 点

OOP with Java 通知 Project 4: 4 月 19 日晚 9 点 OOP with Java Yuanbin Wu cs@ecnu OOP with Java 通知 Project 4: 4 月 19 日晚 9 点 复习 类的复用 组合 (composition): has-a 关系 class MyType { public int i; public double d; public char c; public void set(double x) { d

More information

詞 彙 表 編 號 詞 彙 描 述 1 預 約 人 資 料 中 文 姓 名 英 文 姓 名 身 份 證 字 號 預 約 人 電 話 性 別 2 付 款 資 料 信 用 卡 別 信 用 卡 號 信 用 卡 有 效 日 期 3 住 房 條 件 入 住 日 期 退 房 日 期 人 數 房 間 數 量 入

詞 彙 表 編 號 詞 彙 描 述 1 預 約 人 資 料 中 文 姓 名 英 文 姓 名 身 份 證 字 號 預 約 人 電 話 性 別 2 付 款 資 料 信 用 卡 別 信 用 卡 號 信 用 卡 有 效 日 期 3 住 房 條 件 入 住 日 期 退 房 日 期 人 數 房 間 數 量 入 100 年 特 種 考 試 地 方 政 府 公 務 人 員 考 試 試 題 等 別 : 三 等 考 試 類 科 : 資 訊 處 理 科 目 : 系 統 分 析 與 設 計 一 請 參 考 下 列 旅 館 管 理 系 統 的 使 用 案 例 圖 (Use Case Diagram) 撰 寫 預 約 房 間 的 使 用 案 例 規 格 書 (Use Case Specification), 繪 出 入

More information

附录J:Eclipse教程

附录J:Eclipse教程 附 录 J:Eclipse 教 程 By Y.Daniel Liang 该 帮 助 文 档 包 括 以 下 内 容 : Eclipse 入 门 选 择 透 视 图 创 建 项 目 创 建 Java 程 序 编 译 和 运 行 Java 程 序 从 命 令 行 运 行 Java Application 在 Eclipse 中 调 试 提 示 : 在 学 习 完 第 一 章 后 使 用 本 教 程 第

More information

untitled

untitled 1 Outline 料 類 說 Tang, Shih-Hsuan 2006/07/26 ~ 2006/09/02 六 PM 7:00 ~ 9:30 聯 ives.net@gmail.com www.csie.ntu.edu.tw/~r93057/aspnet134 度 C# 力 度 C# Web SQL 料 DataGrid DataList 參 ASP.NET 1.0 C# 例 ASP.NET 立

More information

1 Framework.NET Framework Microsoft Windows.NET Framework.NET Framework NOTE.NET NET Framework.NET Framework 2.0 ( 3 ).NET Framework 2.0.NET F

1 Framework.NET Framework Microsoft Windows.NET Framework.NET Framework NOTE.NET NET Framework.NET Framework 2.0 ( 3 ).NET Framework 2.0.NET F 1 Framework.NET Framework Microsoft Windows.NET Framework.NET Framework NOTE.NET 2.0 2.0.NET Framework.NET Framework 2.0 ( 3).NET Framework 2.0.NET Framework ( System ) o o o o o o Boxing UnBoxing() o

More information

FY.DOC

FY.DOC 高 职 高 专 21 世 纪 规 划 教 材 C++ 程 序 设 计 邓 振 杰 主 编 贾 振 华 孟 庆 敏 副 主 编 人 民 邮 电 出 版 社 内 容 提 要 本 书 系 统 地 介 绍 C++ 语 言 的 基 本 概 念 基 本 语 法 和 编 程 方 法, 深 入 浅 出 地 讲 述 C++ 语 言 面 向 对 象 的 重 要 特 征 : 类 和 对 象 抽 象 封 装 继 承 等 主

More information

OOP with Java 通知 Project 4: 5 月 2 日晚 9 点

OOP with Java 通知 Project 4: 5 月 2 日晚 9 点 OOP with Java Yuanbin Wu cs@ecnu OOP with Java 通知 Project 4: 5 月 2 日晚 9 点 复习 类的复用 组合 (composition): has-a 关系 class MyType { public int i; public double d; public char c; public void set(double x) { d =

More information

OOP with Java 通知 Project 4: 4 月 18 日晚 9 点 关于抄袭 没有分数

OOP with Java 通知 Project 4: 4 月 18 日晚 9 点 关于抄袭 没有分数 OOP with Java Yuanbin Wu cs@ecnu OOP with Java 通知 Project 4: 4 月 18 日晚 9 点 关于抄袭 没有分数 复习 类的复用 组合 (composition): has-a 关系 class MyType { public int i; public double d; public char c; public void set(double

More information

Microsoft Word - 投影片ch03

Microsoft Word - 投影片ch03 Java2 JDK5.0 教學手冊第三版洪維恩編著博碩文化出版書號 pg20210 第三章變數與資料型態 本章學習目標認識變數與常數認識 Java 的基本資料型態學習如何進行資料型態轉換學習如何由鍵盤輸入資料 變數與資料型態 3-2 Java 的資料型態分為 : 與 原始資料型態 (primitive type) 非原始資料型態 (non-primitive type) 原始資料型態包括了整數與浮點數等型態

More information

Oracle 4

Oracle 4 Oracle 4 01 04 Oracle 07 Oracle Oracle Instance Oracle Instance Oracle Instance Oracle Database Oracle Database Instance Parameter File Pfile Instance Instance Instance Instance Oracle Instance System

More information

Microsoft PowerPoint - L17_Inheritance_v4.pptx

Microsoft PowerPoint - L17_Inheritance_v4.pptx C++ Programming Lecture 17 Wei Liu ( 刘 威 ) Dept. of Electronics and Information Eng. Huazhong University of Science and Technology May. 2015 Lecture 17 Chapter 20. Object-Oriented Programming: Inheritance

More information

, 7, Windows,,,, : ,,,, ;,, ( CIP) /,,. : ;, ( 21 ) ISBN : -. TP CIP ( 2005) 1

, 7, Windows,,,, : ,,,, ;,, ( CIP) /,,. : ;, ( 21 ) ISBN : -. TP CIP ( 2005) 1 21 , 7, Windows,,,, : 010-62782989 13501256678 13801310933,,,, ;,, ( CIP) /,,. : ;, 2005. 11 ( 21 ) ISBN 7-81082 - 634-4... - : -. TP316-44 CIP ( 2005) 123583 : : : : 100084 : 010-62776969 : 100044 : 010-51686414

More information

epub 33-8

epub 33-8 8 1) 2) 3) A S C I I 4 C I / O I / 8.1 8.1.1 1. ANSI C F I L E s t d i o. h typedef struct i n t _ f d ; i n t _ c l e f t ; i n t _ m o d e ; c h a r *_ n e x t ; char *_buff; /* /* /* /* /* 1 5 4 C FILE

More information

使用MapReduce读取XML文件

使用MapReduce读取XML文件 使用 MapReduce 读取 XML 文件 XML( 可扩展标记语言, 英语 :extensible Markup Language, 简称 : XML) 是一种标记语言, 也是行业标准数据交换交换格式, 它很适合在系统之间进行数据存储和交换 ( 话说 Hadoop H ive 等的配置文件就是 XML 格式的 ) 本文将介绍如何使用 MapReduce 来读取 XML 文件 但是 Had oop

More information

《面向对象程序设计A》课程教学大纲Ⅱ4

《面向对象程序设计A》课程教学大纲Ⅱ4 Java 程 序 设 计 课 程 教 学 大 纲 Ⅱ5 课 程 代 码 : 课 程 名 称 :Java 程 序 设 计 Java Programming 学 分 :5 总 学 时 :80 ( 其 中 : 理 论 学 时 :48 实 验 ( 上 机 ) 学 时 :32) 先 修 课 程 : 2106010190 大 学 计 算 机 信 息 技 术 基 础 适 用 对 象 : 本 二 工 科 非 计 算

More information

Java 1 Java String Date

Java 1 Java String Date JAVA SCJP Java 1 Java String Date 1Java 01 Java Java 1995 Java Java 21 Java Java 5 1-1 Java Java 1990 12 Patrick Naughton C++ C (Application Programming Interface API Library) Patrick Naughton NeXT Stealth

More information

51 C 51 isp 10 C PCB C C C C KEIL

51 C 51 isp 10   C   PCB C C C C KEIL http://wwwispdowncom 51 C " + + " 51 AT89S51 In-System-Programming ISP 10 io 244 CPLD ATMEL PIC CPLD/FPGA ARM9 ISP http://wwwispdowncom/showoneproductasp?productid=15 51 C C C C C ispdown http://wwwispdowncom

More information

c_cpp

c_cpp C C++ C C++ C++ (object oriented) C C++.cpp C C++ C C++ : for (int i=0;i

More information

Swing-02.pdf

Swing-02.pdf 2 J B u t t o n J T e x t F i e l d J L i s t B u t t o n T e x t F i e l d L i s t J F r a m e 21 2 2 Swing C a n v a s C o m p o n e n t J B u t t o n AWT // ToolbarFrame1.java // java.awt.button //

More information

Bus Hound 5

Bus Hound 5 Bus Hound 5.0 ( 1.0) 21IC 2007 7 BusHound perisoft PC hound Bus Hound 6.0 5.0 5.0 Bus Hound, IDE SCSI USB 1394 DVD Windows9X,WindowsMe,NT4.0,2000,2003,XP XP IRP Html ZIP SCSI sense USB Bus Hound 1 Bus

More information

9, : Java 19., [4 ]. 3 Apla2Java Apla PAR,Apla2Java Apla Java.,Apla,,, 1. 1 Apla Apla A[J ] Get elem (set A) A J A B Intersection(set A,set B) A B A B

9, : Java 19., [4 ]. 3 Apla2Java Apla PAR,Apla2Java Apla Java.,Apla,,, 1. 1 Apla Apla A[J ] Get elem (set A) A J A B Intersection(set A,set B) A B A B 25 9 2008 9 M ICROEL ECTRON ICS & COMPU TER Vol. 25 No. 9 September 2008 J ava 1,2, 1,2, 1,2 (1, 330022 ; 2, 330022) :,. Apla - Java,,.. : PAR ;Apla - Java ; ;CMP ; : TP311 : A : 1000-7180 (2008) 09-0018

More information

AL-M200 Series

AL-M200 Series NPD4754-00 TC ( ) Windows 7 1. [Start ( )] [Control Panel ()] [Network and Internet ( )] 2. [Network and Sharing Center ( )] 3. [Change adapter settings ( )] 4. 3 Windows XP 1. [Start ( )] [Control Panel

More information

《计算概论》课程 第十九讲 C 程序设计语言应用

《计算概论》课程 第十九讲  C 程序设计语言应用 Java 高级技术 课程 Java 语言的高级特性 李戈 北京大学信息科学技术学院软件研究所 2009 年 4 月 11 日 输入 / 输出流 输入 / 输出流 为输入 / 输出数据,Java 程序与数据的发送者或接收者要建立一个数据通道, 这个通道被抽象为流 (stream); Java 语言本身不包含输入 / 输出语句, 而是通过 Java API 提供的程序包 java.io 完成的 ; 输入

More information

Microsoft PowerPoint - Class5.pptx

Microsoft PowerPoint - Class5.pptx C++ 程式初探 V 2015 暑期 ver. 1.0.1 C++ 程式語言 大綱 1. 大量檔案讀取 & 計算 2. 指標 3. 動態記憶體 & 動態陣列 4. 標準函式庫 (STL) vector, algorithm 5. 結構與類別 2 大量檔案讀取 & 計算 若目前有一個程式將讀取純文字文件 (.txt) 中的整數, 並將該文件中的整數有小到大排序後, 儲存到另外一個新的純文字件中 假設有

More information

C/C++ 语言 - 循环

C/C++ 语言 - 循环 C/C++ Table of contents 7. 1. 2. while 3. 4. 5. for 6. 8. (do while) 9. 10. (nested loop) 11. 12. 13. 1 // summing.c: # include int main ( void ) { long num ; long sum = 0L; int status ; printf

More information

FileMaker 16 ODBC 和 JDBC 指南

FileMaker 16 ODBC 和 JDBC 指南 FileMaker 16 ODBC JDBC 2004-2017 FileMaker, Inc. FileMaker, Inc. 5201 Patrick Henry Drive Santa Clara, California 95054 FileMaker FileMaker Go FileMaker, Inc. FileMaker WebDirect FileMaker Cloud FileMaker,

More information

《大话设计模式》第一章

《大话设计模式》第一章 第 1 章 代 码 无 错 就 是 优? 简 单 工 厂 模 式 1.1 面 试 受 挫 小 菜 今 年 计 算 机 专 业 大 四 了, 学 了 不 少 软 件 开 发 方 面 的 东 西, 也 学 着 编 了 些 小 程 序, 踌 躇 满 志, 一 心 要 找 一 个 好 单 位 当 投 递 了 无 数 份 简 历 后, 终 于 收 到 了 一 个 单 位 的 面 试 通 知, 小 菜 欣 喜

More information