Java語法基礎

型態、變數、運算子

流程控制

型態

類別型態
Class Type

又稱參考型態
Reference Type

基本型態
Primitive Type

位元組
byte

浮點數

字元
char

布林
boolean

true and false

float

double

32bits

64bits

-128~127

Unicode 6.2

UTF-16 Big Endian

2個位元組,中英文都是

整數

int

long

click to edit

short

8 bytes

4 bytes

2 bytes

變數

不可數字開頭

不可用 *&^% 字元

不可用保留字

Camel case

ageOfStudent
ageOfTeacher

final

宣告並給值後,就不能修改

運算子

算術`

比較

條件

邏輯

condition ? A : B

位元

遞增、遞減

指定

i++

--

+=
=
*=
/=
%=
&=
|=
^=
<<=
>>=

&&
||
!

&
|
~
^

>>
<<

>
>=
==
<
<=
!=

+
-
*
/
%

型態轉換

float

3.14F

long

2147483648L

(float) 3.14

提升

int a = 10;
double b = a * 3.14;

short

需要明確轉型

short a = 1;

short b = 2;

short c = (short) (a + b);

其它例子

short a = 1;

long b = 2;

int c = (int) a + b;

System.out.println(10 / 3)

3

if..else
switch

for
while

break
continue

switch

jdk 7

before jdk7

integer
char
enum
string

integer
enum
char

default is not necessary

label

break label
離開整個區塊

conintue label

label只能在for之前