1.数据类型之定义
long l1 =13456789L;
float f1 = 2.32f;
float f2 = 2.3F;
//写成这样都可以
2.默认值
boolean的默认值为false (且不参与任何数据转换)
byte, short, int, long 都为0
char为 “\u0000”
3.变量种类
-
局部变量: 方法体内部定义的变量 见变量a
-
成员变量: 类中没有被static修饰的变量 见变量i
-
静态变量: 类中被static修饰的变量 见变量c
public class test {
static int c = 2;
int i = 1;
public static void main(String[]args){
char a = 'A';
}
}
4.变量调用方法
- 局部变量 : 当前方法中,声明之后,直接写变量名调用即可 见变量a
- 静态变量 : 类名.静态变量名/当前类中调用当前类的静态变量时,类名可以省略,编译之后,JVM会自动补齐为类名调用 见变量c
- 成员变量 : 对象引用.成员变量名 见变量i
public class test {
static int c = 2;
int i = 1;
public static void main(String[]args){
char a = 'A';
//局部变量调用
System.out.println(a);
}
}
class test1{
public static void main(String[] args) {
//静态变量调用
System.out.println(test.c);
//成员变量调用
test t1 = new test();
System.out.println(t1.i);
}
}
5.单目运算符的运算
int i = 1;
i = i++ + (++i - ++i);
输出: i = 0
括号不属于运算符, 他属于语法, 在进行运算符优先级运算时, 先不管括号, 以上题为例:
因为++为单目运算符, 所以首先运算++, 变成:
i = 1 + (3 - 4);
i = 0
6.位运算符
& 位与 , 两边都是true 结果才是true,也可以两边是数字
| 位或一边为true 结果就为true
! 位非,取反 !true 就是false , !false 就是true
^ 异或 ,两边不一样就是true
~ 按位非,转换为二进制,然后每位取反