Class每个单词首字母大写﹐Abstract Class以Abstract开头
Interface每个单词首字母大写
Method第1个单词为动词﹑小写﹐后大写每个单词的首字母
Variables第1个单词小写﹐且其名称应不与Class相同
Finally Variables大写﹐且每个单词以下划线分隔
2.Variables and Scope
Method中的Variables必须被宣告和初始化
Class中的Variables必须被宣告
3.Operators
&&(AND)和||(OR) are Short-Circuit Logical Operators
B1 && B2---当B1为false时﹐则B2不运算
B1 || B2---当B1为true时﹐则B2不运算
Operator为&﹑| 时﹐两边表达式都会运算
4.String and StringBuffer
String的长度限制:Integer.MAX_VALUE﹐但jvm的内存很难达到这个gb级的大小,所以大多会报
OutOfMemoryError
StringBuffer的默认大小是16﹐当赋值超过StringBuffer当前长度时,StringBuffer会将自己的长度
加1乘2,得到新的char数组。
String不允许被修改
StringBuffer可以被修改
进行 + 运算时﹐用StringBuffer代替String﹐运算结束后再StringBuffer.toString()得到
String object.
5.Switch…Case
Case后data type必须为byte,short,int,char中的一种
Case后data type为char时﹐应写为 ’char’ 形式﹐不可为双引号
6.Interface
implements一个Interface时﹐必须实作Interface中的所有method﹐除非该Class为Abstract
Class
7. BufferedReader
BufferedReader in = new BufferedReader(new FileReader("foo.in"));
8.String
String line = new String(bytes[], "Big5" ); //根据指定的编码用bytes[]构建
String
line.getBytes( System.getProperty("file.encoding") );//根据系统编码从
String得到bytes[]
9.使用JPanel或Panel组件可以很轻易地将窗口划分成数据个独立的区域且每个区域都拥有各自的坐标系统﹐可以为每个Panel或JPanel
组件设置不同的布局方式(setLayout())
10.GridLayout类允许用户使用指定的"行列数"来将窗口分割成彼此"大小相等"的区域﹐每个区域可以放置一个组件
构造方法﹕
GridLayout(int rows,int cols)
GridLayout(int rows,int cols,int hg,int vg) //hg,vg分为水平与垂直间距
例:
(1)JFrame JF=new JFrame("^_^");
Container c = JF.getContentPane();
JPanel JP = new JPanel();
JP.setLayout( new GridLayout( 4, 1 ) );//4行1列
JP.add( 组件 );
c.add( new JScrollPane( JP ), BorderLayout.CENTER );
11.操纵 Access 数据库
String query1 = "SELECT...";
String query2 = "UPDATE/INSERT INO/DELETE...";
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
Connection connect =
DriverManager.getConnection( "jdbc:odbc:DatabaseName" );
Statement statement = connect.createStatement();
ResultSet result = statement.executeQuery( query1 );
int rs = statement.executeUpdate( query2 );
//executeUpdate返回一个int值(更新计数),即为受到影响的行数。对于CREATE TABLE,DROP TABLE,
//ALTER TABLE之类操作行的语句﹐它返回0值。
12.Vector
Vector中只能存放Object﹐不可存放基本型态(Primitive type)﹐如果一定要用基本型态的话﹐应先把它转为相
对应的Object﹐如﹕int Integer, charCharacter…
Vector支持synchronized﹐所以可以做到Thread-safe
13.HashTable
KeyValue
Key不能重复﹔
若要添加的Key已经存在于HashTable中﹐则会用当前Key的Value覆盖原Value
remove method只移除掉Key﹐对应的Value还会存在
HashMap与HashTable类似
14.Properties
多国语言的核心之一
本身是一个HashTable
用load method读取.properties档后﹐所有的值都变为HashTable
用store method回存设定后的HashTable到原properties檔
15.ResourceBundle
多国语言的核心之一
16.native2ascii
转码﹕native2ascii old_file_name ascii_file_name
17.测试程序执行时间
long start = System.currentTimeMillis();
// 要计时的运算代码放在这儿
long time = System.currentTimeMillis() - start;
System.out.println(time);
18.在Java中执行其它可执行程序
Runtime.getRuntime().exec("notepad.exe")
19.何时该创建static method
当该method没有用到本class中的member和method时就可将其声明为static method(即该method可以独立存在﹐没
有与外界的任何耦合关系)