CS 18000 · Flashcards

CS 18000 Exam Review: Java Basics, OOP, Exceptions, Recursion and Data Structures

30 termsPurdue Universityby @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 Purdue University and doesn't contain real exam questions.

Terms in this set (30)

  1. Primitive types vs reference types in JavaPrimitives (int, double, boolean, char, etc.) hold values directly. Reference types (String, arrays, objects) hold a reference to an object on the heap; the default is null.
  2. What does 7 / 2 evaluate to in Java, and how do you get 3.5?7 / 2 is 3 because integer division truncates. Use 7 / 2.0 or (double) 7 / 2 to get 3.5.
  3. What does 17 % 5 evaluate to?2. The % operator gives the remainder after integer division.
  4. == vs .equals() for Strings== checks whether two references point to the same object. .equals() compares the characters. Use .equals() to compare String contents.
  5. Why are Java Strings called immutable?A String object cannot be changed after creation. Methods like toUpperCase() return a new String; the original is unchanged.
  6. Short-circuit evaluationWith && Java skips the right side if the left is false; with || it skips the right side if the left is true. This lets you write if (x != null && x.length() > 0) safely.
  7. while vs do-while loopA while loop checks its condition before each iteration and may run zero times. A do-while runs the body once before checking, so it runs at least once.
  8. Valid indexes of an array of length n0 to n - 1. Accessing index n or a negative index throws ArrayIndexOutOfBoundsException.
  9. Array vs ArrayListAn array has a fixed length and can hold primitives. An ArrayList resizes automatically, holds only objects (with autoboxing for primitives) and uses get, set, add and remove.
  10. Pass-by-value in JavaJava always passes a copy of the value. For objects, the copy is the reference, so a method can modify the object's state but reassigning the parameter does not affect the caller's variable.
  11. Class vs objectA class is a blueprint defining fields and methods. An object is a specific instance of a class created with new.
  12. What is a constructor?A special method with the class's name and no return type that initializes a new object. If you write none, Java provides a default no-argument constructor.
  13. Static vs instance membersStatic fields and methods belong to the class and are shared by all instances. Instance members belong to each object. A static method cannot directly use instance fields.
  14. EncapsulationHiding an object's internal data by making fields private and exposing controlled access through public methods such as getters and setters.
  15. Access modifiers from most to least restrictiveprivate (class only), default/package-private (same package), protected (package plus subclasses), public (everywhere).
  16. Inheritance and the super keywordA subclass extends a superclass and inherits its non-private members. super(...) calls the superclass constructor and must be the first statement; super.method() calls the parent's version.
  17. Overloading vs overridingOverloading: same method name with different parameter lists in the same class, chosen at compile time. Overriding: a subclass redefines an inherited method with the same signature, chosen at run time.
  18. Polymorphism with dynamic bindingA superclass reference can point to a subclass object, e.g. Animal a = new Dog(). Calling a.speak() runs Dog's overridden speak() at run time.
  19. Abstract class vs interfaceAn abstract class can have fields, constructors and implemented methods, and a class extends only one. An interface defines a contract of methods (mostly abstract), and a class can implement many.
  20. Checked vs unchecked exceptionsChecked exceptions (like IOException) must be caught or declared with throws. Unchecked exceptions (RuntimeException subclasses like NullPointerException) do not have to be.
  21. What does a finally block do?Code in finally runs after the try and any matching catch, whether or not an exception was thrown. It is used for cleanup like closing files.
  22. Two essential parts of a recursive methodA base case that returns without recursing, and a recursive case that moves toward the base case. Missing a base case causes StackOverflowError.
  23. Write a recursive factorial in plain wordsIf n <= 1 return 1; otherwise return n * factorial(n - 1). factorial(4) = 4*3*2*1 = 24.
  24. Linear search vs binary searchLinear search checks each element: O(n), works on unsorted data. Binary search halves a sorted array each step: O(log n), requires sorted data.
  25. Selection sort vs insertion sortSelection sort repeatedly finds the smallest remaining item and swaps it into place. Insertion sort inserts each item into the sorted part on its left. Both are O(n^2) in the worst case.
  26. Big-O of nested loops each running n timesO(n^2), since the inner body runs n*n times.
  27. Stack vs queueA stack is last-in, first-out (push and pop at the top). A queue is first-in, first-out (add at the back, remove from the front).
  28. Singly linked list vs array: access and insertion costArray: O(1) access by index but O(n) insertion in the middle. Linked list: O(n) access by position but O(1) insertion once you hold a reference to the node.
  29. What are generics and why use them?Type parameters like ArrayList<String> let classes and methods work with any type while the compiler checks types, avoiding casts and ClassCastException.
  30. What is a race condition in multithreaded code?When two threads access shared data at the same time and at least one writes, so the result depends on timing. Prevent it with synchronized blocks or locks.

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