CodeIEB
Theory Notes/🗄️ Topic 4: Data & Information Management, Solution Development/10.4.3
10.4.3Grade 10

Simple Data Types & Data Typing

The foundational vocabulary for every variable you'll ever declare in Java — get the types, operators, and conversions locked down here.

TypeStoresJava keywordExample
String / textA sequence of charactersString"Hello World"
CharA single characterchar'A'
IntegerWhole numbersint42
Floating point / realNumbers with decimalsdouble3.14
BooleanTrue or false onlybooleantrue

Arithmetic operators and how they apply to each numeric type:

OperatorMeaningExample (int)Result
+Addition5 + 27
-Subtraction5 - 23
*Multiplication5 * 210
/Real division5.0 / 22.5
div (integer division)Whole number division, discards remainder5 / 2 (both ints in Java)2
modRemainder after division5 % 21

Order of precedence follows standard maths rules (brackets first, then *, /, mod/div, then + and -) — use brackets to force a specific order when needed.

Choosing the right type matters: a telephone number or ID number should be stored as a String, not an integer/number type — because you'll never do arithmetic on it, and a leading zero (e.g. '011...') would be silently lost if stored as a number.

Data type range
The minimum and maximum values a given type can hold, determined by how many bits are used to store it.
Constant
A named value that cannot change once set, e.g. `final double VAT_RATE = 0.15;`
Variable
A named value that can change during program execution.
Naming convention
A consistent style for naming variables/constants, e.g. camelCase for variables (totalPrice), UPPER_SNAKE_CASE for constants (VAT_RATE) — improves readability.

Type conversion (casting):

ConversionExampleNotes
String ↔ numericInteger.parseInt("5"), String.valueOf(5)Needed because user input is normally read as a String
String ↔ char"A".charAt(0)Get a single character from a String
char ↔ int(int) 'A' → 65Each char has an underlying numeric (ASCII/Unicode) value
real ↔ integer(int) 3.9 → 3Converting a real to an int truncates (cuts off) the decimal part, it does not round
Widening conversion
Converting a smaller/less precise type to a larger/more precise one (e.g. int → double) — always safe, no data is lost.
Narrowing conversion
Converting a larger/more precise type to a smaller one (e.g. double → int) — can lose data/precision, and must usually be done explicitly (an explicit cast).

String operations you must know:

  • Length of a string — e.g. "Hello".length() returns 5.
  • Concatenation — joining strings together, e.g. "Hello" + " " + "World".
  • Changing case — converting to upper/lower case, e.g. .toUpperCase(), .toLowerCase().
  • Comparing strings — using .equals() to check if two strings have the same content (never use == to compare String content in Java).

💡 Exam Tip

Java trap: never compare Strings with ==. Two Strings with identical text can be different objects in memory, so == checks object identity, not content. Always use .equals().