Repository navigation
Expand file tree
/
Copy pathJavaSe8_1_1.java
More file actions
46 lines (40 loc) · 1.75 KB
/
Copy pathJavaSe8_1_1.java
File metadata and controls
46 lines (40 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
public class JavaSe8_1_1 {
// 這{}為class scope,類別內容可以放 欄位(fields / instance variables)方法(methods)
int x = 10; // 欄位(instance variable)
String msg = "Hello Java";
public static void main(String args[]){
// main 方法的 {} 就是 method scope
int y = 20; //區域變數
System.out.println(y);
// System.out.println(x); 靜態方法不能直接用非靜態欄位,x 是「物件的欄位」還沒產生物件
JavaSe8_1_1 obj = new JavaSe8_1_1(); //建立物件
System.out.println(obj.x); //透過物件存取
//==============================================================================================
byte b = 0b0001_0001;
short s = (short) 0b1001_0001_0100_0101;
int i1 = 0B1001_0001_0100_0101_1010_0001_0100_0101;
// java 7 之後可以在數字常量numeric literals內使用"_" 提高數字常量的可讀性
long creditCardNumber = 1234_5678_9012_3456L;
long secialSecurityNumber = 999_99_9999L;
long hexBytes = 0xFF_EC_DE_5E;
long hexWords = 0xCAFE_BABE;
long maxLong = 0x7fff_ffff_ffff_ffffL;
byte nybbles = 0b0010_0101;
long bytes = 0b11010010_01101001_10010100_10010010;
// 不能放在數字前後 ;鄰近小數點 ;在F或L前 ;預期數字該出現的地方
// float pi1 = 3_.1415F;
// float pi2 = 3._1415F;
// long 1 = 999_99_9999_L;
// int x1 = _52;
int x2 = 5_2;
// int x3 = 52_;
int x4 = 5__________2;
// int x5 = 0_x52;
// int x6 = 0x_52;
int x7 = 0x5_2;
// int x8 = 0x52_;
int x9 = 0_52;
int x10 = 05_2;
// int x11 = 052_;
}
}