Real World Example

Choosing Types for a Bank Account

Choosing the right type matters in production. A banking app such as SBI YONO or HDFC MobileBanking stores account data with careful types: long for account numbers and paise, boolean for flags, char for codes and String for text.

Example

public class Main {
    public static void main(String[] args) {
        long accountNumber = 50100234567891L;   // too big for int
        String holder = "Meera Iyer";
        char accountType = 'S';                 // S = savings, C = current
        long balancePaise = 12_545_075L;        // Rs. 1,25,450.75 stored in paise
        boolean kycDone = true;
        byte branchZone = 4;

        System.out.println("Account : " + accountNumber);
        System.out.println("Holder  : " + holder);
        System.out.println("Type    : " + (accountType == 'S' ? "Savings" : "Current"));
        System.out.println("Balance : Rs. " + balancePaise / 100 + "." + balancePaise % 100);
        System.out.println("KYC     : " + kycDone + ", Zone " + branchZone);
    }
}

Output

Account : 50100234567891
Holder  : Meera Iyer
Type    : Savings
Balance : Rs. 125450.75
KYC     : true, Zone 4