标签:
1、 java注释:单行注释、多行注释、文档注释
文档注释:执行javadoc,生成HTML格式的代码报告;
多行注释不允许嵌套。
2、 标识符命名规范
包名:所有单词小写;
类名接口名:所有单词首字母大写;
变量名和函数名:第一个单词小写,其后每个单词首字母大写;
常量名:所有单词大写,各单词以下划线’_’连接。
注意:关键字不能为标识符;
关键字所有字母小写。
3、 负数的二进制:取反加一
4、 数据类型
基本数据类型: byte、short、int(整数默认)、long、float、double(小数默认)
char;
boolean
引用数据类型:class、interface、[]
注意:数据类型转换
short num = 9; num = num + 10;
编译报错,10默认为int型,’=’左右数据类型不一致,需强制转换
num = (short)(num + 10);
注意:
short num = 9; num += 10;
编译成功,因为进行了自动转换。
《Programing in Java》解释:
Q. Is there any difference between a += b and a = a + b, where a and b are primitive types?
A. Possibly, if a and b are of different types. The assignment statement a += b is equivalent to a = (int) (a + b) if a is of type int. Thus, if b is of type double, a += b is legal, but a = a + b is a compile-time error.
5、 字符串连接符、加法运算符
注意:字符串数据和任何数据用’+’都是相连接
1 public class Hello 2 { 3 public static void main(String[] args) 4 { 5 int a = 4, b; 6 b = a++; 7 System.out.println("a = " + a +", b = " + b); 8 System.out.println( "ab = " + a + b ); 9 System.out.println( "a + b = " + ( a + b ) ); 10 } 11 }
6、 移位
>> :用符号位补空位
>>> :用0补空位
标签:
原文地址:http://www.cnblogs.com/corykang/p/4563445.html