B2.1 Programming fundamentals: notes and practice
B2.1 covers the basics every program needs: variables and data types, scope, operators, type conversion, string handling, exceptions, input validation, debugging and testing.
What you need to know
Our summary of the topic in our own words, not the IB guide.
- Declare and assign variables of the common primitive types
- Choose an appropriate data type for a given value and explain why
- Distinguish local from global scope and predict which value a name refers to
- Trace a program by hand and record variable values at each step in a trace table
- Apply arithmetic, comparison and logical operators correctly, including operator precedence
- Convert between data types explicitly and explain when conversion loses information
- Extract a substring from a string by position
- Manipulate strings by concatenating, searching, replacing and changing case
- Split a string on a delimiter and rejoin parts
- Explain what an exception is and when a program should handle one
- Write code that catches an exception and recovers, rather than crashing
- Validate input so that bad data is rejected before it causes an error
- Distinguish syntax, runtime and logic errors and identify which one a described failure is
- Debug a program using tracing, test output and breakpoints, and explain the fix
- Design test cases including normal, boundary and invalid inputs
Learn it
- Join text with +
Lesson with 2 exercises
- A variable holds one value; assigning again replaces it
Lesson with 3 exercises
- Four basic types
Lesson with 1 exercise
- Turn typed text into a number
Lesson with 4 exercises
- Operators and precedence
Lesson with 3 exercises
- Whole-number division and remainder
Lesson with 3 exercises
- Keeping the fraction; when conversion loses information
Lesson with 2 exercises
- Comparison operators
Lesson with 2 exercises
- Remainder inside a condition
Lesson with 2 exercises
- Comparing text
Lesson with 2 exercises
- and, or, not
Lesson with 3 exercises
- Every loop needs an update; find the infinite loop
Lesson with 2 exercises
- Local and global scope
Lesson with 5 exercises
- Length and one character by position
Lesson with 4 exercises
- Substring by position
Lesson with 3 exercises
- Search, replace, change case
Lesson with 5 exercises
- Loop over the characters
Lesson with 5 exercises
- Split a line into parts; join parts
Lesson with 3 exercises
- Capstone: read record lines, split, report
Lesson with 1 exercise
- Syntax, run-time and logic errors
Lesson with 2 exercises
- Find a bug by tracing and printing
Lesson with 3 exercises
- What an exception is
Lesson with 1 exercise
- Catch and recover
Lesson with 2 exercises
- Validate before use
Lesson with 4 exercises
- Design test cases: normal, boundary, invalid
Lesson with 2 exercises
Practice questions
Original questions written for the 2027 course, marked as you go. Easiest first.
- Add agesCoding · Warm-up
- Bike hire test dataWritten · Warm-up
- Closed signCoding · Warm-up
- Data lossWritten · Warm-up
- Data typesWritten · Warm-up
- Double itCoding · Warm-up
- Exception ageWritten · Warm-up
- First characterCoding · Warm-up
- First N charactersCoding · Warm-up
- Fizz checkCoding · Warm-up
- Minutes to hoursCoding · Warm-up
- Name tagCoding · Warm-up
- Repeat lineCoding · Warm-up
- Same wordCoding · Warm-up
- Snack orderCoding · Warm-up
- Ticket costCoding · Warm-up
- Trace: div modTrace table · Warm-up
- Trace: precedenceTrace table · Warm-up
- Trace: replace valueTrace table · Warm-up
- Trace: two variablesTrace table · Warm-up
- Check a nicknameCoding · Warm-up
- Which kind of errorWritten · Warm-up
- Bill share errorsWritten · Core
- Booking boundary bugWritten · Core
- Coin changeCoding · Core
- Count a letterCoding · Core
- Characters at even indexesCoding · Core
- Ask until it is a numberCoding · Core
- Last characterCoding · Core
- Leap year checkCoding · Core
- Fix the dry spell counterCoding · Core
- The longest wordCoding · Core
- Mark checkerCoding · Core
- Copies leftCoding · Core
- Trace table: finding freezing hoursTrace table · Core
- RectangleCoding · Core
- Remove first and lastCoding · Core
- Reverse the wordsCoding · Core
- Scope shadowWritten · Core
- Scores on one lineCoding · Core
- Split billCoding · Core
- Swap halvesCoding · Core
- Tidy a product codeCoding · Core
- Total priceCoding · Core
- Trace: case and replaceTrace table · Core
- Trace: case and replace (Java)Trace table · Core
- Trace: char atTrace table · Core
- Trace: char at (Java)Trace table · Core
- Trace: count in a wordTrace table · Core
- Trace: count in a word (Java)Trace table · Core
- Trace: find skipped valueTrace table · Core
- Trace: find skipped value (Java)Trace table · Core
- Trace: Java reverseTrace table · Core
- Trace: local scopeTrace table · Core
- Trace: local scope (Java)Trace table · Core
- Trace: param scopeTrace table · Core
- Trace: param scope (Java)Trace table · Core
- Type lineCoding · Core
- Before the @Coding · Core
- Is it an hour?Coding · Core
- Validate percentageWritten · Core
- Sports day reportCoding · Stretch
Exam tips for B2.1
- Trace tables are a common Paper 2 skill. Practise them until each row is automatic.
- Know the difference between syntax, runtime and logic errors, with an example of each.
- When designing tests, include normal, boundary and invalid inputs.
Updated 24 October 2026. Topic codes are used as labels. Everything on this page is written by ExamSpine and is not endorsed by the IB.