Questions You Should Be Able To Answer
(Reference: Java An Introduction to Problem Solving
and Programming, 8th Edition, by Savitch)

All the code from the above text can be found here.

Chapter 1: Introduction to Computers and Java

  1. Who is regarded as the "father of Java"?
  2. How does Java achieve its cross-platform portability?
  3. How do compilers and interpreters fit into the Java scheme of things?
  4. What is the connection between a Java class and the file which contains that class?
  5. What are the three main "pillars" of Object Oriented Programming (OOP), and can you briefly describe each?
  6. What are the three main kinds of programming errors?
  7. What is the connection between "software reuse" (one goal of pretty much all software development) and the Java API (Application Programming Interface)?
  8. What does the acronym JVM stand for?
  9. Why do we need an import statement for standard input (to get the Scanner class, for example) but no import statement for standard output (to get the System class, for example)?

Chapter 2: Basic Computation

  1. What is meant by a literal value, such as an integer literal or a String literal value, for example?
  2. What are the eight simple data types in Java, can you give a literal value example of each type, and, given a range of values, could you tell which data type the range belonged to? (p54, slide 13)
  3. What is the difference between a variable declaration a variable initialization, and a variable assignment?
  4. What is meant by a strongly-typed programming language, and is Java such a language or not?
  5. What constitutes a valid identifier in Java (a variable name, for example)?
  6. What style do we insist you use for naming variables, constants, methods, classes?
  7. What do we mean to imply with the following "diagram"?
    byte -> short -> int -> long -> float -> double
  8. What is meant by "type casting" (also called just "casting"), and how do we use it? In particular, what happens when we cast a char value to an int value, and vice versa?
  9. How are the arithmetic operators +, -, *, / and % used? In particular, why do we have to be careful about the / and % operators?
  10. How do the increment operator (++) and the decrement operator (--) work?
  11. How do the special assignment operators +=, -=, *=, and other similar such operators work?
  12. What are two ways of initializing a String variable?
  13. What does it mean that the value of a Java String variable is immutable?
  14. What is the simplest way to concatenate (put together, for output) two Java strings (two literals, two variables, or a literal and a variable), and can we use the same way to concatenate a string and a number?
  15. What are the basic Java String class methods, and how does each of them work? (p88, slides 72-73)
  16. What are the Java escape characters, which ones are most often used, and for what purpose? (p91, slide 76)
  17. What is the relationship between Java and Unicode, and between ASCII and Unicode? (slide 78)
  18. What do we use to display a line of output on the screen, with and without the line being "terminated"?
  19. To read input from the keyboard into our programs we use a class object (often conveniently named keyboard) of what class, and how do we make this class available to one of our programs and then create the necessary keyboard object?
  20. What are some of the most useful and commonly used methods of the keyboard object referred to in the previous item? (slides 86-87)
  21. What are the three kinds of comments you will find in Java, and how is each used?
  22. How can we use "self-documenting code" to help reduce the need for separate comments?

Chapter 3: Flow of Control: Branching

  1. What is the typical syntax of an if-statement, an if..else-statement, and a nested if-statement.
  2. What is a "boolean expression" and how is it used as the condition in a decision-making construct such as any of those listed in the previous item?
  3. What are the six relational operators and how are they used to form "relational expressions" that are also simple boolean expressions?
  4. What are the three "logical operators" (also called "boolean operators) used to negate a single boolean expression or join together two or more boolean expressions.
  5. What is meant by short-circuit evaluation? (p174)
  6. Why should you not use the == or != operators when comparing floating-point values?
  7. Why should you not use the == or != operators when comparing strings?
  8. How do you compare strings for equality or inequality?
  9. How does the conditional operator ? : work?
  10. What is the precedence of the various operators mentioned above (arithmetic, relational, logical, conditional)? (p172, slide 52)
  11. What is the syntax of a switch-statement? (pp179-180, slide 63)
  12. What is an Enumeration and how can it be used with a switch-statement? (slides 66-68)
  13. Under what circumstances might you want to use exit(0)?

Chapter 4: Flow of Control: Loops

  1. What is the syntax of a while-loop, do..while-loop, for-loop?
  2. What is the syntax of a for-each loop? (slide 30)
  3. What is a nested loop structure, and why might you want to use one?
  4. Can you explain some typical (and depressingly common) loop errors, such as the "infinite loop", the "off-by-one error", or the error caused by placing a semi-colon immediately after a for-loop or while-loop header and thus creating an empty loop body?
  5. What are the typical scenarios in which each of the above-mentioned three loops would be used?
  6. How do the break-statement and the continue-statement work, in the context of loops?
  7. What is the difference between declaring a for-loop control variable before the loop and declaring it within the for-loop header?
  8. How would you use a boolean constant (DEBUGGING, say) and the if-statement to help you with debugging loops (or debugging in general, for that matter)?
  9. How do you use the Java assert statement?

Chapter 5: Defining Classes and Methods

  1. What is the syntax for a typical Java class definition?
  2. Typically, in a class definition, what should be private and what should be public, and how are these modifiers, or access qualifiers, used?
  3. What does the acronym UML stand for?
  4. How do you draw a simple UML class diagram, and for what are the symbols + and - used in such a diagram? (slide 8)
  5. If you compile a Java source code file in a directory and in that same directory there are other Java source code files that contain classes that the first file uses, what happens to those other source code files?
  6. What is an instance variable?
  7. What is a local variable?
  8. What are two differences between a value-returning method and one that does not return a value (with respect to return-type, and choice of name)?
  9. How is a method called (inside its class and outside its class)?
  10. What does the Java keyword this refer to?
  11. What is a block and what is the scope of a variable declared inside a block?
  12. What is the default "parameter passing mechanism" in Java?
  13. What happens when you pass a value of primitive type to a Java method, and how is that different from passing an object reference to a method?
  14. What is the distinction between the terms parameter and argument (or, as these are sometimes called as well, formal parameter and actual parameter)?
  15. What happens to parameter values and local variable values when a method finishes executing?
  16. How does "automatic type casting" work in the context of parameter passing?
  17. Could you explain (briefly) to someone what the following terms mean and how the concepts they represent relate to one another: encapsulation, information hiding, implementation details, class interface (API), abstract data type (ADT)?
  18. What are accessor methods and mutator methods (also called getters and setters) for a class?
  19. What are method pre-conditions and post-conditions?
  20. How would you comment a class, and what is the Java tool used to produce "automatic documentation" based on certain types of comments?
  21. How does a variable of a class type differ from a variable of a primitive type?
  22. How does a method parameter of a class type differ from a method parameter of a primitive type?
  23. What are you doing when you compare two variables of class type with the == operator or the != operator?
  24. If you intend to compare two objects of your class to see if they are equal in the sense of "having the same content", what method should you define for your class?
  25. What are unit testing and regression testing?
  26. How do you use Java's assert to help you with debugging? (See TestAssertions.java in SimpleTestPrograms.)

Chapter 6: More About Objects and Methods

  1. What is a class constructor?
  2. What is the syntax of the default class constructor?
  3. What is the syntax of a non-default class constructor?
  4. How do you create a new instance of a class (that is, a new object of that class) using a class constructor?
  5. When does Java provide a class constructor for you?
  6. Should you show constructors in a UML class diagram?
  7. How would you describe any similarities, differences and/or connections between class constructors and class setters?
  8. A constructor is a class method, so can you use a class object to call a constructor like you would call any other class method?
  9. If you call another class method from a constructor (to help with the construction, for example) what should the access modifier of that other method be? (Hint: See page 394.)
  10. Can you call one constructor from another, and if so, how is it done?
  11. In Java every class can have a main() method, so can you explain why this is very useful, and also why Java does not get "confused" when you run your program?
  12. What are static variables/constants (also called class variables/constants) and static methods (also called class methods)?
  13. How would you explain the distinction between a class variable and a variable of class type?
  14. How do we access a static variable or method if we don't have an object of that class? What if we do have an object of that class?
  15. Can you think of a class variable that you have been using since your first Java program?
  16. What value do you give to a variable of class type to indicate explicitly that it does not refer to any class object, and how do you test if the variable contains that value?
  17. What happens to class instance variables that you do not explicitly initialize when an object of the class is created, and how does this differ from the behavior of local variables?
  18. Can you now explain the difference between instance variables, local variables, and class (static) variables?
  19. If a static method wants to reference a (private or public) data member (variable) of its class, what must be true of that data member?
  20. If a static method wants to call another method of its class, what must be true of that other method?
  21. Can a non-static method of a class reference any (private or public, static or non-static) data member (variable) of its class?
  22. Can a non-static method of a class call any other (private or public, static or non-static) method of its class?
  23. If a method can be classified as a "helper method", what should its access qualifier be?
  24. Do you know about at least two useful static constants (p411) and nine static methods (p412) of the Math class (Slides 21-23)?
  25. What are the eight wrapper classes corresponding to the eight primitive types? Answer: Byte, Short, Integer, Long, Float, Double, Character and Boolean corrsponding, respectively, to byte, short, int, long, float, double, char and boolean.
  26. Which two wrapper classes do not have a name that is just the capitalized version of the corresponding primitive type?
  27. What is meant by (automatic) boxing and unboxing (p414)?
  28. What are two useful named static constants (p415) found in each of the wrapper classes Byte, Short, Integer, Long, Float, and Double?
  29. What are the names of the static class methods (p415) that can be used to convert a String value that contains a number into the actual corresponding number (found in Byte, Short, Integer, Long, Float, Double)? And what is the single method that converts in the other direction?
  30. Can you name seven useful methods of the Character wrapper class (two "to-methods" and five "is-methods")? (p417, slides 26-27)
  31. What is meant by method overloading? (slide 37)
  32. What is a method signature?
  33. Why is a method's return-type not part of its signature?
  34. What is an enumeration, and can you list five of its methods? (pp449-451, slide 45)
  35. What is a package, and how should a package be named?
  36. Where should a package statement appear?
  37. What is the connection between package names, directory paths, and the Java classpath? (pp453-456, slides 47-51)
  38. What do you do so that you can use in your program a class from a particular package?

Once you have reviewed this chapter, you should study (and experiment with) the program in SimpleTestPrograms/TestVariableAccess.java.

Chapter 7: Arrays

  1. Why and when would we use an array rather than just a bunch of "ordinary" variables?
  2. Can you draw and properly label a "picture" of an array?
  3. What is the syntax of an array type?
  4. How do you create an array object of a particular size?
  5. How do you initialize an array object?
  6. How do you find the length of an array?
  7. What happens if you try to use an invalid array index value?
  8. What are the two kinds of for-loops you can use to process an array, and can you use either one in any situation where you want to process some or all of the elements in an array? (See TestArrays.java in SimpleTestPrograms.)
  9. Which, if any, of the following can be an array: a class data member, a method parameter, a method return value?
  10. How is the String array args that is always the parameter in the main() method of any class used? (See TestCLP.java in SimpleTestPrograms.)
  11. What do you, as a programmer, have to keep track of if you are dealing with a partially filled array?
  12. How do you define a multidimensional array in Java?
  13. How does the selection sort algorithm work (slides 38-42)? See also SelectionSortDemo.java and ArraySorter.java under Course Text and Associated Files | Course Text Code | ch07.
  14. What is the easiest way to sort all or part of an array in Java? (See TestArraySorting.java in SimpleTestPrograms, and see also Appendix 8 of the Savitch text for an introduction to "functional programming" illustrated in this sample program.)

Chapter 8: Inheritance, Polymorphism and Interfaces

  1. What is inheritance?
  2. What is a derived/child/sub class (slide 5)?
  3. What is a base/parent/super class (slide 5)?
  4. What does a UML inheritance diagram look like? (text p601 is correct, but Power Point slide 12 has the wrong kind of arrow)
  5. What is the syntax for class inheritance?
  6. What is meant by the is-a relationship (also called the may-be-replaced-by-a relationship)?
  7. What is meant by the has-a relationship (also called the composition relationship)?
  8. Why do you suppose the Java language prevents you from accessing the private data members and/or the private methods in a base class from a derived class?
  9. What is meant by method overriding (not to be confused with method overloading)?
  10. When one method overrides another, both must have the same header, that is, the same signature and return type. Do not confuse overriding with overloading.
  11. What does it mean if a method or a class has the final modifier?
  12. What is the keyword super used for in a derived class constructor, and what happens if you don't use it?
  13. Note that both of the keywords this and super are used for calling constructors, this for calling another constructor of the same class, and super for calling a constructor of the parent class. Each of this and super has to be the first call in the body where it is called, so if you need to call both you should use this to call a constructor that has super as its first action.
  14. If you're in a derived class, and there is a method in that class that has been overridden, but you want to call the version of that method that is in the base class, how do you do it?
  15. Is it possible to use "repeated supers"? (p607)
  16. Can an object of a derived class serve as an object of its base class?
  17. Can an object of a base class serve as an object of one of its derived classes?
  18. What is the Object class? (p612)
  19. Can a Java class extend two or more classes? In other words, does Java have multiple inheritance?
  20. What methods of the Object class do you think we should "always" override in our own classes?
  21. How do you use the instanceof operator to help you write a "good" equals() method for one of your classes? (pp614-616)
  22. What is polymorphism? (p616)
  23. What is dynamic binding (also called late binding)? (p617)
  24. What is the relationship between dynamic binding, inheritance and polymorphism? [Hint: Think of this in the context of an array of some base object type that may contain both base objects and derived objects, and a method that has been overridden is called on each object in the array.] (p619)
  25. What is an interface? (p623)
  26. What are two things an interface does not have? (Note: The second marginal comment on page 622 is no longer completely true.)
  27. How is an interface used, and what is its general syntax?
  28. What is the syntax that indicates a class is going make use of a single interface?
  29. What is the syntax that indicates a class is going make use of two or more interfaces?
  30. If two or more classes implement the same interface, do they both have to implement it in the same way?
  31. How do we use an interface as a type? (p625)
  32. Do you understand the following statement: A variable's type determines what methods can be used, but the actual type referenced by the variable determines which definition of any particular method will be used. (p627)
  33. Can interfaces be extended like classes? (p628)
  34. Can one interface extend two or more other interfaces?
  35. How is the Comparable interface used? [Note that the Java API shows interfaces in italic text, classes in normal text.]
  36. What is an abstract method? (p646)
  37. What is an abstract class? (p646)
  38. Can you create an object of an abstract class type?
  39. How is an abstract class generally used?
  40. Can an abstract class be a type? (p648)

Chapter 9: Exception Handling

  1. What is the "old-fashioned" way of dealing with run-time errors that occur in our programs, and can you give a reason why this approach has fallen out of favor over the years?
  2. What is meant by a Java exception?
  3. What is meant by the try-throw-catch keyword sequence that we use to deal with Java exceptions, and can you explain the ideas of "throwing", "catching", and "handling" an exception?
  4. What should you always supply when you create an Exception object, and how should this be retrieved later and used? (p679)
  5. What is a "catch-block parameter", and why is this terminology potentially misleading? (p679)
  6. Can you explain the typical "flow of control" in a simple program when an exception is thrown, as well as when it's not thrown? (pp680-681)
  7. If you define your own exception class (which you can do), how does inheritance come into play?
  8. Typically, how many constructors should you have in an exception class that you define yourself?
  9. What does it mean to "declare" an exception (informally known as "passing the buck"), and what is the syntax for doing so? (pp697-698)
  10. What happens if an exception is thrown but not caught and handled?
  11. Where do the various exception classes live (that is, in what packages are they located)?
  12. Could you draw a (small) UML diagram illustrating how Java exceptions fit into the Java class hierarchy? (p701, slide 23)
  13. What is the difference between a checked exception and an unchecked exception? (pp700-701)
  14. What is the difference between an error and an exception in Java? (p702)
  15. If you have more than one catch-block (which you can have), what do you have to remember about the order of those catch-blocks? (p705)
  16. Can you offer some good advice about when and where to use exceptions? (p708)
  17. Can you nest try-catch blocks? Should you? (p709)
  18. What is the purpose of a finally-block? (p709)
  19. Can you re-throw an exception? Should you? (p710)
  20. So, how many specifically exception-related keywords does Java have, and what are they?

Chapter 10: Streams and File I/O

  1. What is a stream in Java?
  2. What are the two types of files, and how would you describe each?
  3. Are you clear about the meanings of input and output in the context of files and your program?

  4. How do you set up a textfile as an output stream and write to it?
  5. What can you say about exception handling in this context?
  6. What are the useful methods of the PrintWriter class?
  7. What do we mean when we say that "a file has two names" in a program?
  8. What happens if there is already an output file with the same name as the one we want to use?
  9. How do we append to an already existing file?
  10. How do you set up a textfile as an input stream and read from it?
  11. What can you say about exception handling in this context?
  12. What are some Scanner methods you can use to determine if there is more data of a specific type available to be read? (slide 17)
  13. Can you explain why there is a one-parameter constructor for the PrintWriter class that takes a string as its parameter and sets up the file whose name is in that string as an output stream, but there is no corresponding one-parameter constructor for the Scanner class that takes a string as its parameter and sets up the file whose name is in that string as an input stream?
  14. And so ... what class do we have to use as an "intermediate" class with the Scanner class when setting up an input stream?
  15. What are some useful methods of the File class? (slide 23)
  16. Can you explain the difference between a "file" and a "File object"?
  17. Do you understand why we have to be careful when using Windows path names to specify the location of a file in our Java programs?
  18. Do you know what the acronym CSV stands for, and how to process the kind of data referred to by this acronym?

  19. How do you set up a binary file as an output stream and write to it?
  20. What can you say about exception handling in this context?
  21. How is the FileOutputStream class used?
  22. What are some useful methods of the ObjectOutputStream class? (slides 32-34)
  23. What does UTF stand for, and what is perhaps surprising about its use in the context of binary file output?
  24. How do you set up a binary file as an input stream and read from it?
  25. What can you say about exception handling in this context?
  26. How is the FileInputStream class used?
  27. What are some useful methods of the ObjectInputStream class? (slides 37-41)
  28. How is the EOFException class used?
  29. What interface must a class implement if we are to write out objects of that class to a binary file?
  30. What must we remember to do when reading in objects from a binary file?
  31. Have you checked out the I/O Related Java Classes page under the Java References link on the course home page?

Chapter 11: Recursion

  1. What is recursion?
  2. What is the more general problem-solving approach of which recursion is a special case?
  3. What are the main features of a recursive solution?
  4. Every recursive method must call what?
  5. What happens if a recursive method does not include a "stopping condition"?
  6. Which one of the standard control structures is often used as the basic structure of a recursive solution?
  7. Can you compare and contrast a recursive solution and an iterative solution of the same problem?
  8. Can a recursive method be either void or value-returning?
  9. Do you understand how our version of recursive binary search works?
  10. Do you understand how our version of recursive merge sort works?

Chapter 12: Dynamic Data Structures and Generics

  1. What is meant by a dynamic data structure? (p884)
  2. What is an ArrayList and how does it differ from an "ordinary" array? (p886)
  3. What can you not put into an ArrayList? (p886)
  4. How does a constructor for a parameterized class type differ from a constructor for a non-parameterized class type? (pp886-887)
  5. What are two different constructors for the ArrayList? (p887)
  6. What is meant by type inference, and how would you explain its use in the context of the ArrayList? (p888)
  7. What are some useful methods of the ArrayList class? (p891, slides 7-8)
  8. Why do some parameters of ArrayList methods have the ArrayList base type and others have type Object? (p890)
  9. When might you use the ArrayList trimToSize() method?
  10. What is the most convenient kind of loop to use if you wish to process all the elements in an ArrayList object? (p895)
  11. What is mean by saying the ArrayList is a "parameterized" type? (p881)
  12. What is the Java Collections Framework? (p895)
  13. What are some of the more important methods in the Java Collection interface? (p896)
  14. What is a HashSet? Is it a class or an interface? (p897)
  15. What is a Map? Is it a class or an interface? (p898)
  16. What are some of the more important methods in the Java Map interface? (p899)
  17. What is a HashMap? Is it a class or an interface? (p898)
  18. What is a linked data structure? (p901)
  19. What is a "linked list" and when would you use a Java LinkedList rather than a Java ArrayList?
  20. A very important question: Can you draw correct pictures to illustrate situations involving Java code that creates and manipulates linked structures?