Thuta Learning
ရှာဖွေရန်
BasicProgrammingbeginner

Data Types

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

Java data types ကို အဓိကအားဖြင့် Primitive Types နဲ့ Reference Types ဆိုပြီးခွဲနိုင်ပါတယ်။ Primitive type တွေက value ကိုတိုက်ရိုက်သိမ်းပြီး reference type တွေက object/location ကိုရည်ညွှန်းပါတယ်။ Beginner အတွက် အရင်ဆုံး သိသင့်တာက data အမျိုးအစားမှန်မှ operation မှန်မှာဖြစ်ပါတယ်။ ဥပမာ phone number ကို math တွက်ချင်တာမဟုတ်ရင် String နဲ့သိမ်းတာက ပိုသင့်တော်နိုင်ပါတယ်။

java
public class Main {
  public static void main(String[] args) {
    int quantity = 3;
    double price = 19.99;
    char grade = 'A';
    boolean isAvailable = true;
    String productName = "Keyboard";

    System.out.println(productName + " x " + quantity);
    System.out.println("Total: " + (quantity * price));
    System.out.println("Grade: " + grade);
    System.out.println("Available: " + isAvailable);
  }
}

ဒီ example မှာ product order တစ်ခုလို data တွေကို type အမျိုးမျိုးနဲ့သိမ်းထားပါတယ်။ quantity * price က numeric types နှစ်ခုကို multiplication လုပ်ပြီး total price ထုတ်ပါတယ်။

You should see
Keyboard x 3 Total: 59.97 Grade: A Available: true

လက်တွေ့အသုံးချမှု

E-commerce order, school grading, booking status, payment amount စတဲ့ real app data model တွေမှာ data type ရွေးချယ်မှုက အရေးကြီးပါတယ်။

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • Decimal number ကို int ထဲထည့်တာ၊ char ထဲမှာ စာလုံးများစွာထည့်တာ၊ quotes မှားသုံးတာတွေကိုရှောင်ပါ။
Data Types | Thuta Learning