Variable ဆိုတာ data သိမ်းဖို့အသုံးပြုတဲ့ နာမည်ပေးထားသော storage လေးပါ။ Java က statically typed language ဖြစ်လို့ variable တစ်ခုကိုမသုံးခင် data type ကို ကြိုပြောရပါတယ်။ Java ကို “ဒီ box ထဲမှာ ဘာအမျိုးအစားထည့်မလဲ?” လို့ကြိုတင်ပြောပေးရတာပါ။
java
public class Main {
public static void main(String[] args) {
String name = "Aung";
int age = 30;
double height = 5.8;
boolean isStudent = false;
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Height: " + height);
System.out.println("Student: " + isStudent);
}
}String က စာသားသိမ်းပါတယ်။ int က ကိန်းပြည့်၊ double က ဒသမကိန်း၊ boolean က true/false တန်ဖိုးသိမ်းပါတယ်။ + operator ကို String နဲ့တွဲသုံးတဲ့အခါ text တွေကိုဆက်ပေးပါတယ်။
You should see
Name: Aung Age: 30 Height: 5.8 Student: falseလက်တွေ့အသုံးချမှု
User profile, product price, login status, score, inventory quantity စတဲ့ app data အားလုံးကို variable concept နဲ့ပဲစတင်ထိန်းချုပ်ပါတယ်။