Java Basics and Data Types

Harry · 16 Sep 2026 · 13 views
Log in to track your progress and mark lessons complete.

Primitives and literals

Java has eight primitives: byte, short, int, long, float, double, char, boolean. Know their sizes and default values, and watch literal forms:

int hex = 0xFF;       // 255
int bin = 0b1010;     // 10
long big = 1_000_000L;
double d = 1.5e3;     // 1500.0

Wrappers and autoboxing

Each primitive has a wrapper class (Integer, Double…). Java auto-converts between them, which the exam probes with caching gotchas:

Integer a = 127, b = 127;
System.out.println(a == b);   // true  (cached -128..127)
Integer c = 200, d = 200;
System.out.println(c == d);   // false (new objects)
System.out.println(c.equals(d)); // true

Operators and promotion

  • Integer division truncates: 7 / 2 == 3.
  • Mixed arithmetic promotes to the wider type: int + double is a double.
  • && / || short-circuit; & / | do not.

Key points

  • Know the eight primitives, their sizes and defaults.
  • Use equals() not == to compare wrapper values.
  • Integer division truncates; arithmetic promotes to the wider type.
  • Understand short-circuit vs non-short-circuit operators.
Share this post:

Comments (0)

Please login or register to comment.

Create a free account to keep reading

You've enjoyed a free tutorial! Register (it's free) to unlock every tutorial, track your progress and save code.

Already have an account? Log in