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.
Student FinanceWeb Platform

Pocketly — Personal Finance for Students

Keep your hostel and college expenses under control. Track accounts, log spending in seconds, and stay within your monthly budget.

← All Introduction to Java Programming modules