Time of Update: 2018-12-06
作者:gnuhpc 出處:http://www.cnblogs.com/gnuhpc/用戶端:import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; import java.net.SocketException; import java.net.UnknownHostException; import
Time of Update: 2018-12-06
作者:gnuhpc 出處:http://www.cnblogs.com/gnuhpc/import java.util.ArrayList;public class Autoboxing { public static void main(String[] args) {// 手動打包,解決容器類無法放置基礎資料型別 (Elementary Data Type)的問題 Integer intvalue = new
Time of Update: 2018-12-06
作者:gnuhpc 出處:http://www.cnblogs.com/gnuhpc/public class DynamicParameters { public static void main(String[] args) { add(1,2,3); add(1,2,3,4); } public static void add(int... arr) {//支援可變數目的參數,實際就是一個數組,自動構建,
Time of Update: 2018-12-06
作者:gnuhpc 出處:http://www.cnblogs.com/gnuhpc/JAR檔案是一種具有特定構造的zip檔案1.JAR檔案的建立:import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; import java.util.jar.Manifest; import java.io.File; import java.io.FileOutputStream;
Time of Update: 2018-12-06
作者:gnuhpc 出處:http://www.cnblogs.com/gnuhpc/檔案路徑:import java.io.File; public class FilePath { public static void main(String arg[]) { String pname1 = File.separator + "stuff" + File.separator +
Time of Update: 2018-12-06
作者:gnuhpc 出處:http://www.cnblogs.com/gnuhpc/public class GotchaString { public static void main(String arg[]) { System.out.println("string + twenty + thirty: " + 20 + 30); System.out.println("string + (twenty + thirty):
Time of Update: 2018-12-06
作者:gnuhpc 出處:http://www.cnblogs.com/gnuhpc/方法可以採用正則表達在想要搜尋的字串前邊構造(?i),表示大小寫不敏感。例如,要搜尋here,則構造(?i)here,表示here,Here,HERE等。但是這還會匹配there,我們還可以加上字元間隔符來表示一個單獨的here單詞, /b(?i)here/b。 使用String的matches( )
Time of Update: 2018-12-06
作者:gnuhpc 出處:http://www.cnblogs.com/gnuhpc/import java.util.ArrayList;import java.util.Iterator;public class Practice { public static void main(String[] args) { int[] ary=new int [6]; ary[0] = 3; ary[1] = 4; ary[2]
Time of Update: 2018-12-06
作者:gnuhpc 出處:http://www.cnblogs.com/gnuhpc/先介紹幾個術語:i18n: 就是internationalization, 國際化,由於首字母"i"和末尾字母"n"間有18個字元,所以簡稱i18n. internationalization指為了使應用程式能適應不同的語言和地區間的變化而不作系統性的變化所採取的設計措施。 l10n: 就是localization, 本地化,由於首字母"l"和末尾字母"n"間有10個字母,所以簡稱l10n.
Time of Update: 2018-12-06
作者:gnuhpc 出處:http://www.cnblogs.com/gnuhpc/import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;public class CopyText { public static void main(String arg[]) { if(arg.length != 2) {
Time of Update: 2018-12-06
作者:gnuhpc 出處:http://www.cnblogs.com/gnuhpc/1.簡介: 以前你想讓程式記住使用者自訂的習慣,比如介面字型等,你使用一個設定檔,但是在維護多個使用者或出現誤拼字時還是力不從心。而java.util.prefs包則提供了便利。線上文檔寫的非常糟糕,將java.util.prefs這個類描述為“a node in a hierarchical collection of preference data”,還說“there are two
Time of Update: 2018-12-06
作者:gnuhpc 出處:http://www.cnblogs.com/gnuhpc/1.使用方法 package tips; public interface Constants { public static final int PORT_NUMBER = 90; public static final String APP_NAME = "DOOLY"; public static class StaticNestedClass
Time of Update: 2018-12-06
作者:gnuhpc 出處:http://www.cnblogs.com/gnuhpc/定義了各種通道,這些通道表示到能夠執行 I/O 操作的實體(如檔案 和通訊端)的串連;定義了用於多工、非阻塞 I/O 操作的選取器。寫檔案import java.io.FileOutputStream; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.CharBuffer;
Time of Update: 2018-12-06
作者:gnuhpc 出處:http://www.cnblogs.com/gnuhpc/1.簡介:Regex是Java 處理字串、文本的重要工具。java.util.regex.Pattern 匹配類:用模式比對一個字串所表達的抽象結果。java.util.regex.Matcher 模式類:用來表示一個編譯過的Regex。 2.例子import java.util.regex.Pattern; public class RegexDemo1 {
Time of Update: 2018-12-06
作者:gnuhpc 出處:http://www.cnblogs.com/gnuhpc/你若是不使用泛型,則會這樣處理資料類型不確定的問題:class Stash { private Object x; void set(Object x) { this.x = x; } Object get() { return(x); } } public class
Time of Update: 2018-12-06
作者:gnuhpc 出處:http://www.cnblogs.com/gnuhpc/// Use split() to extract substrings from a string.class SplitDemo { static void showSplit(String[] strs) { for(String str : strs) System.out.print(str + "|"); System.out.println("/n"); } /
Time of Update: 2018-12-06
作者:gnuhpc 出處:http://www.cnblogs.com/gnuhpc/import java.util.Vector; public class CollectionOne { public static void main(String arg[]) { new CollectionOne(); } CollectionOne() { Vector<Object>
Time of Update: 2018-12-06
作者:gnuhpc 出處:http://www.cnblogs.com/gnuhpc/1.ASCII碼 上個世紀60年代,美國制定了一套字元編碼,對英語字元與二進位位之間的關係,做了統一規定。這被稱為ASCII碼,一直沿用至今。 ASCII碼一共規定了128個字元的編碼,比如空格“SPACE”是32(二進位00100000),大寫的字母A是65(二進位01000001)。這128個符號(包括32個不能列印出來的控制符號),只佔用了一個位元組的後面7位,最前面的1位統一規定為0
Time of Update: 2018-12-06
作者:gnuhpc 出處:http://www.cnblogs.com/gnuhpc/使用BufferedReader對象的readLine()方法必須處理java.io.IOException異常(Exception).一次可以讀一行:import java.io.FileReader; import java.io.FileWriter; import java.io.BufferedReader; import java.io.BufferedWriter;
Time of Update: 2018-12-06
作者:gnuhpc 出處:http://www.cnblogs.com/gnuhpc/package info.gnuhpc;/** * @author gnuhpc email: warmbupt@gmail.com blog: http://gnuhpc.info * @date 2010-1-22 * @bugs 不支援多音文書處理 */public class PinyinConv { // 簡體中文的編碼範圍從B0A1(45217)一直到F7FE(63486)