COMP 1510 · Flashcards

COMP 1510 Exam Review: Programming Fundamentals, Testing, Error Handling and OOP Design

32 termsBritish Columbia Institute of Technologyby @studyboardUpdated October 2026

A study set written by the Studyboard team for the topics in this course's published outline. It isn't official course material from British Columbia Institute of Technology and doesn't contain real exam questions.

Terms in this set (32)

  1. Name the three basic control structures every algorithm can be built from.Sequence (steps run in order), selection (if/else decisions) and iteration (loops).
  2. What is a variable's scope?The region of the program where the name can be used. A variable declared inside a function or block is usually not accessible outside it.
  3. What is a common pitfall with dividing two integers?In many languages (e.g., Java, C), integer / integer truncates: 7 / 2 gives 3, not 3.5. Convert one operand to floating point if you need the fractional part.
  4. Primitive values vs references to objectsA primitive variable stores the value itself (e.g., an int). A reference variable stores the address of an object, so two variables can refer to the same object and both see changes to it.
  5. Identity vs equality when comparing objectsIdentity asks whether two references point to the same object. Equality asks whether two objects have the same contents. Two separate strings can be equal in content but not identical.
  6. What is decomposition?Breaking a large problem into smaller, independent pieces (functions, classes, modules), each with a clear purpose and interface, that can be built and tested separately.
  7. What is encapsulation?Bundling an object's data together with the methods that operate on it, so the data is managed through those methods instead of being changed directly from outside.
  8. What is information hiding, and why does it help?Keeping internal details private and exposing only a public interface. Callers depend only on the interface, so the internals can change without breaking other code.
  9. What is message passing in object-oriented programming?Objects interact by calling each other's public methods (sending messages) instead of reaching into each other's data.
  10. Class vs objectA class is a blueprint defining data (fields or attributes) and behaviour (methods). An object is a specific instance created from that class, with its own values.
  11. What is a constructor?A special method that runs when an object is created. It sets the object's initial state, typically by assigning its fields from the arguments.
  12. Instance variables vs class (static) variablesEach object has its own copy of an instance variable. A class variable is shared by all instances of the class, e.g., a counter of how many objects have been created.
  13. Accessor vs mutator methodsAn accessor (getter) returns information about an object's state without changing it. A mutator (setter) changes the state, ideally validating the new value first.
  14. What is an API, and why is it valuable?An application programming interface is the set of documented operations a module or library offers. It lets you use code without knowing how it works inside, which supports reuse and teamwork.
  15. What are preconditions and postconditions?A precondition is what must be true before a function is called (e.g., the list is not empty). A postcondition is what the function guarantees afterwards if the precondition held.
  16. Why write automated unit tests?They check small pieces of code in isolation, run quickly and repeatably, catch regressions when code changes, and document the expected behaviour.
  17. A function accepts whole numbers from 1 to 100. Which inputs should you test?A typical value (e.g., 50), the boundaries (1 and 100), just outside them (0 and 101), and invalid input of the wrong type or format. Bugs cluster at boundaries.
  18. Describe the test-driven development cycle.Red: write a failing test for the next small behaviour. Green: write just enough code to make it pass. Refactor: clean up the code while keeping all tests passing.
  19. Why use exceptions instead of special error return values?Exceptions separate error-handling code from normal logic, cannot be silently ignored the way an unchecked return code can, and carry information about what went wrong.
  20. What is the role of a finally block (or equivalent cleanup)?Its code runs whether or not an exception occurred. It is used to release resources such as open files or network connections.
  21. What is a common mistake when handling exceptions?Catching every exception and doing nothing (swallowing it). The program keeps running in a bad state and the real cause becomes hard to find. Catch only what you can handle.
  22. An array has n elements. What are the valid indices, and what happens outside them?0 to n − 1 with zero-based indexing. Accessing index n or a negative index (where not supported) raises an out-of-bounds or index error.
  23. What does it mean that strings are immutable in languages like Java and Python?A string object's characters cannot be changed. Operations like concatenation or replace create a new string, which also makes repeated concatenation in a loop inefficient.
  24. Why design before coding?Planning with pseudocode, diagrams or test cases clarifies requirements and structure first, which reduces wasted effort and costly rewrites.
  25. Syntax error vs runtime error vs logic errorSyntax: code violates the language rules and won't compile or run. Runtime: it crashes while executing (e.g., division by zero). Logic: it runs but produces wrong results.
  26. Name a systematic debugging process.Reproduce the bug reliably, narrow down where it happens (prints, breakpoints, stepping through), form a hypothesis, fix it, then add a test so it doesn't come back.
  27. What usually causes an infinite loop?The loop condition never becomes false, often because the loop variable is never updated or is updated in the wrong direction.
  28. What is an off-by-one error? Give an example.A boundary mistake that makes a loop run one time too many or too few, such as looping i from 0 through n inclusive over an array of length n.
  29. What is a side effect, and why prefer functions without unnecessary ones?A side effect is any change outside the function's return value (changing globals, printing, modifying arguments). Functions without them are easier to reason about and test.
  30. What does the DRY principle mean?Don't Repeat Yourself: put each piece of logic in one place, such as a function, instead of copying it, so a fix or change is made once.
  31. High cohesion and low couplingCohesion: how focused a module is on a single job (aim high). Coupling: how much modules depend on each other's internals (aim low). Together they make code easier to change and test.
  32. Trace: total = 0; for i from 1 to 5 inclusive: total = total + i. What is total?15, since 1 + 2 + 3 + 4 + 5 = 15.

Something wrong with this flashcard set? Open it in Studyboard and choose Report.