Java Identifiers
Java variables အားလုံးသည် မတူကွဲပြားသောနာမည်များ (unique names) ပေးခြင်းဖြင့် identified လုပ်ရန်လိုအပ်သည်။ ထိုကဲ့သို ကွဲပြားစွာသတ်မှတ်ပေးထားသော variable name များအား identifiers ဟုခေါ်သည်။
Identifiers များသည် (x, y) ကဲ့သို့ အတိုကောက်များ ဖြစ်နိုင်သည် သို့မဟုတ် (age, sum, totalVolume) များကဲ့သို့ ပို၍ အဓိပ္ပါယ်အားဖော်ပြနိုင်သော အမည်များ လည်း ပေးနိုင်သည်။
မှတ်ချက်။ ။ အဓိပ္ပါယ်အားဖော်ပြနိုင်သော အမည်များ (descriptive names) ပေးခြင်းအားဖြင့် နားလည်ရလွယ်ကူသော၊ ပြုပြင်ရလွယ်ကူသော code များ အဖြစ်ရေးသားခြင်းအား ပို၍အားပေးသည်။
ဥပမာ။
// Good
int minutesPerHour = 60;
// OK, but not so easy to understand what m actually is
int m = 60;ယေဘုယျ အားဖြင့် variable name ပေးခြင်းဆိုင်ရာ စည်းမျဥ်းများ (naming rules) မှာ -
- Variable Name များပေးရာတွင် letters, digits, underscores နှင့် dollar signs($) များပါဝင်နိုင်သည်။
- အစ စာလုံးသည် letter ဖြစ်ရမည်။
- အစ စာလုံးသည် အက္ခရာစာလုံး (lowercase letter) အသေးဖြစ်သင့်ပြီး wihtespce မပါရပေ။
- အစ စာလုံးသည် $ (dollar sign) နှင့် _ (underscore) တို့ဖြင့်လည်း စနိုင်သည်။
- Variable Name တွင် case sensitive အက္ခရာ အကြီးအသေးအလိုက် ကွဲ့ပြားခြင်းရှိသည်။ (ဥပမာ- "myVar" နှင့် "myvar" သည် မတူညီကွဲပြားသည့် variable များဖြစ်ကြသည်။)
- Reserved words များ ဖြစ်သည့် Java တွင် သတ်မှတ်ထားပြီးသော Java ၏ keywords များ အား အသုံးပြု၍ မရပေ။ (ဥပမာ - "int" or "boolean")
No comments:
Post a Comment