Arrays and Strings · Introduction to Java Programming

Number Class

Watch lectures

Number Class

1. What It Is (beginner)

Number = abstract parent of all numeric wrappers (Integer, Double, Long, ...). Lets you treat any number uniformly: pass Integer or Double where Number expected, then ask .intValue() / .doubleValue().

Number (abstract)
├── Integer, Long, Short, Byte (integers)
└── Double, Float (decimals) + BigInteger/BigDecimal

4. Traps

  • Number is abstract: new Number() ERROR (use concrete Integer etc.).
  • .intValue() on Double(3.99) cuts → 3 (narrowing!).
  • instanceof to check kind: if (n instanceof Integer) before int-only ops.

5. Exam Points

  • Hierarchy + doubleValue program — 3-5 marks, frequent.
  • Abstract (no new) + conversion cut — 2-3 marks.
Budget AppAndroid App

Pocketly on Android

Log daily food, travel, and hostel expenses instantly. Set monthly spending limits and see where your money goes without complex spreadsheets.

← All Introduction to Java Programming modules