1. 程式人生 > >命名規則及資料型別小結

命名規則及資料型別小結

一:命名規則:

package:字母均小寫,點分格式,分項級,一級與二級域名組成,例:com.ccc或java.ccc。

class:首字母大寫。

屬性/欄位名:首字母小寫,後大寫。例:userName.

識別符號:不能以數字開頭,不能關鍵字,保留字。

二:資料型別:

1、

型別 中文名 位元組數
boolean 布林 1
byte 位元組 1
short 短整型 2
int 整型 4
long 長整型 8
float 浮點 4
double 雙精度 8
char 字元 2

注:long:123456789L,當位元組數大於八則其後必須加L。剛好為八位,可加可不加,若小於八位,則不用加L。

float:後必須加f,例:float a=1.2f;

float 型可在其後加f,也可省,

2、資料型別優先順序

double>float>long>int>char>short>byte

3、資料的強制轉換

(低階向高階會自動轉化,無需人為,反之需用以下方法轉化)

package lu; public class wanglu { public static void main(String[] args) { { int a=2; double b=3.22; System.out.println("a+b="+((int)(a+b))); System.out.println("資料型別強制轉化"); }
} }