Learn Java - Chapter 1 變數(Variables)

來源:互聯網
上載者:User

標籤:

java語言定義的變數包含一下四種類型

  1. 執行個體變數(Instance Variables),非靜態變數,在Class中聲明的field,未使用static聲明; 

  2. 類變數(Class Variables ),靜態變數,在Class中使用static標識; 

  3. 本地變數(Local Variables),在一個方法中聲明的變數; 

  4. 參數(Parameters),方法定義的形參; 

命名 

  1. 大小寫敏感; 

  2. 不限長度; 

  3. 以字母、數字、底線和“$”符號組成,不可以以數字開頭; 

  4. 不可以是Java保留字 

保留字參考: 

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";


參考:http://docs.oracle.com/javase/tutorial/java/nutsandbolts/variables.html

Learn Java - Chapter 1 變數(Variables)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.