java語言定義的變量包含一下四種類型html
實例變量(Instance Variables),非靜態變量,在Class中聲明的field,未使用static聲明; java
類變量(Class Variables ),靜態變量,在Class中使用static標識; express
本地變量(Local Variables),在一個方法中聲明的變量; oracle
參數(Parameters),方法定義的形參; jvm
命名 this
大小寫敏感; spa
不限長度; .net
以字母、數字、下劃線和「$」符號組成,不能夠以數字開頭; code
不能夠是Java保留字 orm
保留字參考:
abstract | continue | for | new | switch |
assert*** | default | goto* | package | synchronized |
boolean | do | if | private | this |
break | double | implements | protected | throw |
byte | else | import | public | throws |
case | enum**** | instanceof | return | transient |
catch | extends | int | short | try |
char | final | interface | static | void |
class | finally | long | strictfp** | volatile |
const* | float | native | super | while |
注: * not used
** java 1.2 後添加
*** java 1.4 後添加
**** java 5.0 後添加
約定
變量命名以小寫字母開頭,單詞全拼,多個單詞以駝峯形式命名,eg:String currentRatio。若是是常量,全大寫,多個單詞以「_」下劃線分隔。eg:static final double PI = 3.1415926,static final String BAIDU_URL="xxx";
Java基本數據類型表
類型 | 長度(bit) | 範圍 |
byte | 8 | -128 ~ 127 |
short | 16 | -32,768 ~ 32,767 |
int | 32 | -231 ~ 231-1 |
long | 64 | -263 ~ 263-1 |
float | 32 | 有點複雜,繼續往下看... |
double | 64 | 同上 |
boolean | - |
取值:ture或者false,官方說法佔1bit,大小不精肯定義 |
char | 16 | Unicode:'\u0000'~'\uffff' |
float、double的範圍和浮點數的定義有關,先參考specification來看看:https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.2.3
浮點數範圍能夠用 s · m · 2(e - N + 1) 這個公式來表達
s:+1或-1
m是小於2N 的正整數
e是個整數,範圍 between Emin = -(2K-1-2) and Emax = 2K-1-1
NKE取值參考表:
Parameter | float | float-extended-exponent | double | double-extended-exponent |
N | 24 | 24 | 53 | 53 |
K | 8 | ≥ 11 | 11 | ≥ 15 |
Emax | +127 | ≥ +1023 | +1023 | ≥ +16383 |
Emin | -127 | ≤ -1022 | -1022 | ≤ -16382 |
也就是說一般狀況下,浮點的範圍是由以上表達式和表格(float列和double列)決定,我暫且叫他float值集和double值集。
這時你可能注意到了 float-extended-exponent 或double-extended-exponent東西,這個我我的理解成是①float-extended-exponent值集和②double-extended-exponent值集。
①②這兩個值集是Java語言有實現的另外兩個值集,在必定狀況下會使用這類值集(原文「 These extended-exponent value sets may, under certain circumstances, be used instead of the standard value sets to represent the values of expressions of type float or double」,參考:https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.2.3)。
這就引出了一個問題,在不一樣JVM環境中,會因爲浮點範圍致使運算結果有差別。爲了解決程序可移植性,在不一樣平臺浮點運算能有相同的結果,官方提供了一個Java關鍵字「strictfp」,使用這個關鍵字聲明類、接口或方法java編譯器已經jvm會按照IEEE-754標準來執行,這樣就能夠保證浮點運算一致性。(原文「Within an FP-strict expression, all intermediate values must be elements of the float value set or the double value set, implying that the results of all FP-strict expressions must be those predicted by IEEE 754 arithmetic on operands represented using single and double formats.」參考:https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.4 )