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
- Who is regarded as the "father of Java"?
- How does Java achieve its cross-platform portability?
- How do compilers and interpreters fit
into the Java scheme of things?
- What is the connection between a Java class and the
file which contains that class?
- What are the three main "pillars" of Object Oriented
Programming (OOP), and can you briefly describe
each?
- What are the three main kinds of programming errors?
- What is the connection between "software reuse" (one
goal of pretty much all software development) and the Java
API (Application Programming Interface)?
- What does the acronym JVM stand for?
- 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
- What is meant by a literal value, such as an
integer literal or a String literal value, for example?
- 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)
- What is the difference between a variable declaration a
variable initialization, and a variable assignment?
- What is meant by a strongly-typed programming
language, and is Java such a language or not?
- What constitutes a valid identifier in Java (a variable
name, for example)?
- What style do we insist you use for naming variables,
constants, methods, classes?
- What do we mean to imply with the following
"diagram"?
byte -> short -> int
-> long -> float ->
double
- 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?
- How are the arithmetic operators +, -, *, / and % used?
In particular, why do we have to be careful about the / and
% operators?
- How do the increment operator (++) and the
decrement operator (--) work?
- How do the special assignment operators +=,
-=, *=, and other similar such operators
work?
- What are two ways of initializing a String variable?
- What does it mean that the value of a Java String
variable is immutable?
- 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?
- What are the basic Java String class methods, and how
does each of them work? (p88, slides 72-73)
- What are the Java escape characters, which ones
are most often used, and for what purpose? (p91, slide 76)
- What is the relationship between Java and Unicode, and between
ASCII and Unicode? (slide 78)
- What do we use to display a line of output on the
screen, with and without the line being "terminated"?
- 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?
- What are some of the most useful and commonly used
methods of the keyboard object referred to in the
previous item? (slides 86-87)
- What are the three kinds of comments you will find in
Java, and how is each used?
- How can we use "self-documenting code" to help reduce
the need for separate comments?
Chapter 3: Flow of Control: Branching
- What is the typical syntax of an if-statement, an
if..else-statement, and a nested if-statement.
- 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?
- What are the six relational operators and how are they
used to form "relational expressions" that are also simple
boolean expressions?
- 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.
- What is meant by short-circuit evaluation? (p174)
- Why should you not use the == or !=
operators when comparing floating-point values?
- Why should you not use the == or !=
operators when comparing strings?
- How do you compare strings for equality or inequality?
- How does the conditional operator ? : work?
- What is the precedence of the various operators
mentioned above (arithmetic, relational, logical,
conditional)? (p172, slide 52)
- What is the syntax of a switch-statement? (pp179-180, slide 63)
- What is an Enumeration and how can it be used with a
switch-statement? (slides 66-68)
- Under what circumstances might you want to use
exit(0)?
Chapter 4: Flow of Control: Loops
- What is the syntax of a
while
-loop,
do..while
-loop, for
-loop?
- What is the syntax of a
for-each
loop? (slide 30)
- What is a nested loop structure, and why might you want
to use one?
- 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?
- What are the typical scenarios in which each of the
above-mentioned three loops would be used?
- How do the
break
-statement and the
continue
-statement work, in the context of loops?
- What is the difference between declaring a
for
-loop
control variable before the loop and declaring it within
the for
-loop header?
- 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)?
- How do you use the Java
assert
statement?
Chapter 5: Defining Classes and Methods
- What is the syntax for a typical Java class definition?
- Typically, in a class definition, what should be
private and what should be public, and
how are these modifiers, or access
qualifiers, used?
- What does the acronym UML stand for?
- How do you draw a simple UML class diagram, and
for what are the symbols + and - used in
such a diagram? (slide 8)
- 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?
- What is an instance variable?
- What is a local variable?
- 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)?
- How is a method called (inside its class and outside
its class)?
- What does the Java keyword this refer to?
- What is a block and what is the scope of
a variable declared inside a block?
- What is the default "parameter passing mechanism" in
Java?
- 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?
- What is the distinction between the terms
parameter and argument (or, as these are sometimes
called as well, formal parameter and actual parameter)?
- What happens to parameter values and local variable
values when a method finishes executing?
- How does "automatic type casting" work in the context
of parameter passing?
- 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)?
- What are accessor methods and mutator
methods (also called getters and setters)
for a class?
- What are method pre-conditions and
post-conditions?
- How would you comment a class, and what is the Java
tool used to produce "automatic documentation" based on
certain types of comments?
- How does a variable of a class type differ from a
variable of a primitive type?
- How does a method parameter of a class type differ
from a method parameter of a primitive type?
- What are you doing when you compare two variables of
class type with the == operator or the !=
operator?
- 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?
- What are unit testing and regression
testing?
- How do you use Java's assert to help you with
debugging? (See TestAssertions.java in SimpleTestPrograms.)
Chapter 6: More About Objects and Methods
- What is a class constructor?
- What is the syntax of the default class constructor?
- What is the syntax of a non-default class constructor?
- How do you create a new instance of a class (that is, a
new object of that class) using a class constructor?
- When does Java provide a class constructor for you?
- Should you show constructors in a UML class diagram?
- How would you describe any similarities, differences
and/or connections between class constructors and class
setters?
- 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?
- 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.)
- Can you call one constructor from another, and if so,
how is it done?
- 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?
- What are static variables/constants (also called class
variables/constants) and static methods (also called class methods)?
- How would you explain the distinction between a
class variable and a variable of class type?
- 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?
- Can you think of a class variable that you have been
using since your first Java program?
- 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?
- 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?
- Can you now explain the difference between instance
variables, local variables, and class (static) variables?
- 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?
- If a static method wants to call another method of its
class, what must be true of that other method?
- Can a non-static method of a class reference any (private or
public, static or non-static) data member (variable) of its class?
- Can a non-static method of a class call any other (private or
public, static or non-static) method of its class?
- If a method can be classified as a "helper method",
what should its access qualifier be?
- Do you know about at least two useful static constants (p411) and
nine static methods (p412) of the Math class (Slides 21-23)?
- 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.
- Which two wrapper classes do not have a name
that is just the capitalized version of the corresponding
primitive type?
- What is meant by (automatic) boxing and
unboxing (p414)?
- What are two useful named static constants (p415) found
in each of the wrapper classes Byte, Short, Integer, Long, Float, and
Double?
- 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?
- Can you name seven useful methods of the Character
wrapper class (two "to-methods" and five "is-methods")?
(p417, slides 26-27)
- What is meant by method overloading? (slide 37)
- What is a method signature?
- Why is a method's return-type not part of its
signature?
- What is an enumeration, and can you list five of its
methods? (pp449-451, slide 45)
- What is a package, and how should a package be
named?
- Where should a package statement appear?
- What is the connection between package names, directory
paths, and the Java classpath? (pp453-456, slides 47-51)
- 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
- Why and when would we use an array rather than just a
bunch of "ordinary" variables?
- Can you draw and properly label a "picture" of an
array?
- What is the syntax of an array type?
- How do you create an array object of a particular size?
- How do you initialize an array object?
- How do you find the length of an array?
- What happens if you try to use an invalid array index
value?
- 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.)
- Which, if any, of the following can be an array: a
class data member, a method parameter, a method return
value?
- How is the String array args that is always the
parameter in the main() method of any class used? (See
TestCLP.java in SimpleTestPrograms.)
- What do you, as a programmer, have to keep track of if
you are dealing with a partially filled array?
- How do you define a multidimensional array in Java?
- 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.
- 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
- What is inheritance?
- What is a derived/child/sub class (slide 5)?
- What is a base/parent/super class (slide 5)?
- What does a UML inheritance diagram look like? (text p601 is correct,
but Power Point slide 12 has the wrong kind of arrow)
- What is the syntax for class inheritance?
- What is meant by the is-a relationship (also
called the may-be-replaced-by-a relationship)?
- What is meant by the has-a relationship (also
called the composition relationship)?
- 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?
- What is meant by method overriding (not to be
confused with method overloading)?
- 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.
- What does it mean if a method or a class has the
final modifier?
- What is the keyword super used for in a
derived class constructor, and what happens if you don't
use it?
- 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.
- 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?
- Is it possible to use "repeated supers"? (p607)
- Can an object of a derived class serve as an object of
its base class?
- Can an object of a base class serve as an object of one
of its derived classes?
- What is the Object class? (p612)
- Can a Java class extend two or more classes? In other
words, does Java have multiple inheritance?
- What methods of the Object class do you think
we should "always" override in our own classes?
- How do you use the instanceof operator to help
you write a "good" equals() method for one of your
classes? (pp614-616)
- What is polymorphism? (p616)
- What is dynamic binding (also called late
binding)? (p617)
- 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)
- What is an interface? (p623)
- What are two things an interface does not
have? (Note: The second marginal comment on page 622 is no longer
completely true.)
- How is an interface used, and what is its general
syntax?
- What is the syntax that indicates a class is going
make use of a single interface?
- What is the syntax that indicates a class is going
make use of two or more interfaces?
- If two or more classes implement the same interface, do
they both have to implement it in the same way?
- How do we use an interface as a type? (p625)
- 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)
- Can interfaces be extended like classes? (p628)
- Can one interface extend two or more other interfaces?
- How is the Comparable interface used? [Note that the Java API
shows interfaces in italic text, classes in normal text.]
- What is an abstract method? (p646)
- What is an abstract class? (p646)
- Can you create an object of an abstract class type?
- How is an abstract class generally used?
- Can an abstract class be a type? (p648)
Chapter 9: Exception Handling
- 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?
- What is meant by a Java exception?
- 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?
- What should you always supply when you create an Exception object, and
how should this be retrieved later and used? (p679)
- What is a "catch-block parameter", and why is this terminology
potentially misleading? (p679)
- 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)
- If you define your own exception class (which you can do), how
does inheritance come into play?
- Typically, how many constructors should you have in an exception
class that you define yourself?
- What does it mean to "declare" an exception (informally known as
"passing the buck"), and what is the syntax for doing so? (pp697-698)
- What happens if an exception is thrown but not caught and handled?
- Where do the various exception classes live (that is, in what packages
are they located)?
- Could you draw a (small) UML diagram illustrating how Java exceptions
fit into the Java class hierarchy? (p701, slide 23)
- What is the difference between a checked exception and an unchecked
exception? (pp700-701)
- What is the difference between an error and an exception
in Java? (p702)
- 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)
- Can you offer some good advice about when and where to use
exceptions? (p708)
- Can you nest
try-catch
blocks? Should you? (p709)
- What is the purpose of a
finally
-block? (p709)
- Can you re-throw an exception? Should you? (p710)
- So, how many specifically exception-related keywords does Java have,
and what are they?
Chapter 10: Streams and File I/O
- What is a stream in Java?
- What are the two types of files, and how would you describe each?
- Are you clear about the meanings of input and output in the context
of files and your program?
- How do you set up a textfile as an output stream and write to it?
- What can you say about exception handling in this context?
- What are the useful methods of the PrintWriter class?
- What do we mean when we say that "a file has two names" in a program?
- What happens if there is already an output file with the same name
as the one we want to use?
- How do we append to an already existing file?
- How do you set up a textfile as an input stream and read from it?
- What can you say about exception handling in this context?
- 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)
- 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?
- And so ... what class do we have to use as an "intermediate" class
with the Scanner class when setting up an input stream?
- What are some useful methods of the File class? (slide 23)
- Can you explain the difference between a "file" and a "File object"?
- 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?
- Do you know what the acronym CSV stands for, and how to process the
kind of data referred to by this acronym?
- How do you set up a binary file as an output stream and write to it?
- What can you say about exception handling in this context?
- How is the FileOutputStream class used?
- What are some useful methods of the ObjectOutputStream class? (slides 32-34)
- What does UTF stand for, and what is perhaps surprising about its use
in the context of binary file output?
- How do you set up a binary file as an input stream and read from it?
- What can you say about exception handling in this context?
- How is the FileInputStream class used?
- What are some useful methods of the ObjectInputStream class? (slides 37-41)
- How is the EOFException class used?
- What interface must a class implement if we are to write out
objects of that class to a binary file?
- What must we remember to do when reading in objects from a binary
file?
- Have you checked out the I/O Related Java Classes page
under the Java References link on the course home page?
Chapter 11: Recursion
- What is recursion?
- What is the more general problem-solving approach of which recursion
is a special case?
- What are the main features of a recursive solution?
- Every recursive method must call what?
- What happens if a recursive method does not include a "stopping
condition"?
- Which one of the standard control structures is often used as
the basic structure of a recursive solution?
- Can you compare and contrast a recursive solution and an iterative
solution of the same problem?
- Can a recursive method be either void or value-returning?
- Do you understand how our version of recursive binary search works?
- Do you understand how our version of recursive merge sort works?
Chapter 12: Dynamic Data Structures and Generics
- What is meant by a dynamic data structure? (p884)
- What is an ArrayList and how does it differ from an "ordinary"
array? (p886)
- What can you not put into an ArrayList? (p886)
- How does a constructor for a parameterized class type differ from a
constructor for a non-parameterized class type? (pp886-887)
- What are two different constructors for the ArrayList? (p887)
- What is meant by type inference, and how would you explain its
use in the context of the ArrayList? (p888)
- What are some useful methods of the ArrayList class? (p891, slides
7-8)
- Why do some parameters of ArrayList methods have the ArrayList
base type and others have type
Object
? (p890)
- When might you use the ArrayList
trimToSize()
method?
- What is the most convenient kind of loop to use if you wish to
process all the elements in an ArrayList object? (p895)
- What is mean by saying the ArrayList is a "parameterized" type?
(p881)
- What is the Java Collections Framework? (p895)
- What are some of the more important methods in the Java Collection
interface? (p896)
- What is a HashSet? Is it a class or an interface? (p897)
- What is a Map? Is it a class or an interface? (p898)
- What are some of the more important methods in the Java Map
interface? (p899)
- What is a HashMap? Is it a class or an interface? (p898)
- What is a linked data structure? (p901)
- What is a "linked list" and when would you use a Java LinkedList
rather than a Java ArrayList?
- A very important question: Can you draw correct pictures to
illustrate situations involving Java code that creates and manipulates
linked structures?