2012年1月1日星期日

第11天第5,6,7节: Java重用类库一二三

==StringBuffer: 修改文本
1. StringBuffer append(String)
2. StringBuffer insert(int start, String)
3. StringBuffer delete(int start, int end)
4. StringBuffer reverse();
5. String toString();

==Runtime:系统信息
1. Runtime getRuntime()
2. Process exec(String); destroy() in Process
3. long freeMemory(), long maxMemory(), long totalMemory()


==System: 计算时间
1. static long currentTimeMillis();
2. static void gc(),   the same as Rumtime gc();

==Difference final, finally, finalize
1. final: can not inhert
2. finally: always run in try...catch...finally
3. finalize: protected void finalize() throws Throwable: run before a object being distroyed

==国际化
a. Local
1. static Local getDefault();
2. Local(String language, String contry);

b. ResourceBundle
1. ResourceBundle getBundle(String baseName);
2. ResourceBundle getBundle(String baseName, Local local);
3. bin\native2ascii.exe





c. dyanmic text
   Adding place holder in the properties file
   Message_zh_CN.preoperties:
        info = \u4f60\u597d\uff01~~~~~{0},{1}
  String zhValue = chRb.getString("info");
   MessageFormat.format(zhValue, "Hi", "haha");

d. use class to replace property file to save text
public class Message_zh_CN extends ListResourceBundle {...}

e. Priority:
Message.properties<Message_zh_CN.preoperties<Message.java<Message_zh_CN.java
1. but usually use properties file
2. There is tools for creating propertie files

==日期操作
a Date ( import java.util.Date; )
   System.out.println(new Date()) ==> Mon Mar 02 16:12:21 CST 2009
b Calender (import java.util.Calendar; import java.util.GregoreianCalander;)
   1. 它是抽象类,用子类
   Calander calender = new GregorianCalender();

   System.out.println("YEAR: " + calender.get(Calendar.YEAR);
   Options:
   YEAR, MONTH+1,DAY_OF_MONTH,
   HOUR,HOUR_OF_DAY,MINUTE,SECOND,MILLISECOND
c DateFormat
c SimpleDateFormat










没有评论: