Questions You Should Be Able To Answer Already (Reference: Data Structures and Abstractions with Java, 5th Edition, by Carrano and Henry) See code from this text here and Power Points from the text here and here.

The topics covered by this "Q and A" page is material with which you are assumed to be already familiar from prior experience. For many, this prior experence will have been the CSCI 1226/1228 course sequence here at Saint Mary's but you may have received equivalent experience elsewhere. A summary of the prerequisite material as presented in the Savitch text used in CSCI 1226/1228 is given under the Savitch link on the course home page menu. This page contains much of the same material, but with appropriate references to the Carrano and Henry text used in CSCI 2341.

In addtion to knowing this material, it will be important that you become familar, as soon as possible, with our style rules and guidelines, which we will discuss and emphasize in class and lab, and which will be available on the course website as well as via a convenient handout.

Text Supplement 1 (on-line): Java Basics

Miscellaneous

  1. What is the difference between a Java identifier and a Java reserved word?
  2. How do you use each of the following commands at the command line: java, javac, javadoc?

Simple Data Values and Data Types

  1. What is meant by a literal value, such as an integer literal value, a character literal value, or a string literal value, for example?
  2. What are the eight simple (or primitive) data types in Java (give a literal value example of each type), what are their corresponding wrapper class types, and what are automatic boxing and unboxing?
  3. What is meant by type casting (also called just casting), what happens when we cast between char and int values, and how does casting vs. assignment compatibility relate to the following "diagram"?
    byte -> short -> int -> long -> float -> double

Variables, Expressions and Operators

  1. What is the difference between a variable declaration, a variable initialization, and a variable assignment?
  2. How does a variable of a class type differ from a variable of a primitive type?
  3. Are you aware that when we use the term expression we can actually be referring to a single constant, a single variable, or something more complicated involving constants, variables, operators and even functions?
  4. Do you know how to use (properly) all of the arithmetic operators (+, -, *, / and %), the increment and decrement operators (++ and --), and the special assignment operators (+=, -+, *=, and so on)?
  5. What is a boolean expression and what are its possible values?
  6. Do you know how to use (properly) the six relational operators (==, !=, <, <=, >, >=) and the three logical operators (!, &&, ||, also called boolean operators)?
  7. What is meant by short-circuit evaluation, and can you give two examples: one using the && operator and another using the || operator?
  8. Why should you not use the == or != operators when comparing floating-point values or strings?
  9. How does the conditional operator (? :) work?
  10. What is the precedence of the various operators mentioned above (arithmetic, relational, logical, conditional, assignment), and what are the two uses of parentheses in this context?

Simple Output to the Standard Output Stream (the screen) and
Simple Input from the Standard Input Stream (the keyboard)

  1. How do you use System.out.print(), System.out.println(), and System.out.printf()?
  2. How do you use a Scanner object (usually called keyboard) to read input from the standard input?
  3. How would you set up an object called screen to write output to the standard output in a manner analogous to the way keyboard reads input? [Hint: Make screen an object of the class java.io.PrintWriter.]

Decision-Making Control Structures

  1. How are boolean expressions used in decision-making control structures?
  2. What is the syntax of an if-statement, an if..else-statement, a multi-way if-statement, a switch-statement; and what are the typical scenarios where each is used?
  3. What is a nested decision-making control structure, and when would you use one?

Loop Control Structures

  1. How are boolean expressions used in loop control structures?
  2. What is the syntax of a while-loop, a do..while-loop, a for-loop (including the "range for-loop", also called a "for-each loop") and what are the typical scenarios where each is used?
  3. What is a nested loop control structure, and when would you use one?
  4. Are you aware of the typical "gotchas" when using loops (infinite loops, empty loops, off-by-one errors, declaring a for-loop control variable in the wrong place)?
  5. How do the break-statement and the continue-statement work?

Arrays

  1. When and why would you use an array rather than just a bunch of "ordinary" variables?
  2. Can you draw and properly label a "picture" of an array?
  3. How do you declare a variable of an array type?
  4. How do you create an array object of a particular size?
  5. How do you initialize an array object when you declare it?
  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?
  9. Which, if any, of the following can be an array: a class data member, a function parameter, a function return-value?
  10. What do you, as a programmer, have to keep track of if you are dealing with a partially filled array?
  11. What is the easiest way to sort all or part of an array in Java?
  12. How do you define, and access the elements of, a multidimensional array in Java?

Strings

  1. Why can you use the String class in a Java program without an import statement?
  2. What are two ways of initializing a String variable?
  3. What are the Java escape characters, which ones are most often used, and for what purpose?
  4. What is the relationship between Java and Unicode, and between ASCII and Unicode?
  5. What does it mean that the value of a Java String variable is immutable?
  6. What is the simplest way to concatenate (put together) 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?
  7. How do you compare strings for equality or inequality?
  8. Do you know how to use the following basic Java String class methods: charAt(), compareTo(), concat(), equals(), equalsIgnoreCase(), indexOf(), lastIndexOf(), length(), toLower(), toUpper(), replace(), substring() (two versions), trim()?

Command-Line Parameters

  1. How is the array String[] args that is always the sole parameter in the main() method of any class used?
  2. If you want to use a value input at the command line as a number (integer or real), what do you have to do and how do you do it?

Text Supplement 2 (on-line): File Input and Output

  1. What is a stream in Java (in the context of file I/O and/or standard I/O)?
  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?
  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?
  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?
  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?
  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?

Text Appendix A: Documentation and Programming Style

  1. What are the three kinds of comments you will find in Java, and how is each used?
  2. What is the Java tool used to produce "automatic documentation" based on certain types of comments, and which tags are we likely to use most often with this tool??
  3. Are you familiar with the conventions you should be observing, in your particular situation, for each of the following?

Text Appendix B: Java Classes

  1. Could you explain (briefly) to someone what the following terms mean and how the concepts they represent relate to one another, in the context of Java classes: encapsulation, information hiding, implementation details, class interface (API), abstract data type (ADT)?
  2. 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 class in the first file uses, what happens to those other source code files?
  3. What is the syntax for a typical Java class definition?
  4. Typically, in a class definition, what should be private and what should be public, and what is the syntax for using these modifiers, or access qualifiers?
  5. What does the Java keyword this refer to?
  6. What are two uses of the Java keyword this?

Variables in a Class

  1. What is an instance variable (or data member)?
  2. What is a local variable?
  3. What is a static variable?

Methods in a Class

  1. What are two differences (with respect to return-type, and choice of name) between a value-returning method and one that does not return a value?
  2. What is a static method?
  3. How is any class method called from within its own class?
  4. How must a (public) non-static class method be called from outside its own class?
  5. What are the two ways a (public) static class method may be called from outside its own class?
  6. What is a block (of code), and what is the scope of a variable declared inside such a block?

Method Parameters

  1. What is the name of the default parameter passing mechanism in Java?
  2. So ... what happens when you pass a value of any type to a Java method?
  3. But ... what is the difference between passing a variable of primitive type and passing a variable of class type to a method?
  4. What is the distinction between the terms parameter and argument (or, as these are sometimes called as well, formal parameter and actual parameter)?
  5. What happens to parameter values and local variable values when a method finishes executing?
  6. How does "automatic type casting" work in the context of parameter passing?
  7. What are accessor methods and mutator methods (also called getters and setters) for a class?

Testing Your Classes

  1. What are you doing when you compare two variables of class type with the == operator or the != operator?
  2. 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?
  3. What are unit testing and regression testing?
  4. How do you use Java's assert statement to help you with debugging?
  5. Under what circumstances might you want to use exit(0)?
  6. 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" about which main() to use when you run your program?

Class Constructors

  1. What is a class constructor?
  2. What is the syntax of a 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. 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?
  6. When does Java provide a class constructor for you?
  7. What happens to class instance variables that you do not explicitly initialize when the class is created?
  8. How would you describe any similarities, differences and/or connections between class constructors and class setters?
  9. 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?
  10. If you call another class method from a constructor (a "helper" method to help with the construction, for example) what should the access modifier of that other method be, and why? (Hint: Both a constructor and a setter might want to call the same method to do some setup, so think what potential problems inheritance might open up if both used the same (public) helper method.)
  11. Why would you call one constructor from another, and how is it done?

More on Static vs. Non-Static Variables and Methods

  1. What are static variables/constants (also called class variables/constants) and static methods (also, but perhaps less frequently, called class methods)?
  2. How would you explain the distinction between a class variable (also called a static variable) and a variable of class type?
  3. How do we access a public static variable or or public static method of a class if we don't have an object of that class? What if we do have an object of that class?
  4. Can you think of a class variable that you have been using since your first Java program?
  5. Can you explain the difference between instance variables, local variables, and class (static) variables?
  6. Can a static method reference an instance variable of its class?
  7. Can a static method call any method of its class?
  8. Can a non-static method reference an instance variable of its class?
  9. Can a non-static method call any method of its class?

Method Overloading and Method Signatures

  1. What is meant by method overloading?
  2. What is a method signature, and why is a method's return-type not part of its signature?
  3. Can you fill in the blanks in the following statement? When one method overloads another, both must have the same _______________ , but they must have different ____________________ .

Packages

  1. What is a package, and how should a package be named?
  2. What is the only package from the Java standard library that is automatically imported into every Java program?
  3. Where must a package statement appear?
  4. What is the connection between package names, directory paths, and the Java classpath?
  5. What do you do so that you can use in your program a class from a particular package?

Some Particular Useful Classes or Kinds of Classes

  1. Do you know what Math.E and Math.PI are, even if they're not often useful for computing folks?
  2. Do you know how to use the following static methods of the Math class: pow(), sqrt(), cbrt(), hypot()?
  3. Do you know how to use the following static methods of the Math class: exp(), log(), log10()?
  4. Do you know how to use the following static methods of the Math class: ceil(), floor()?
  5. Do you know how to use the static method round() of the Math class? [Note: float -> int, but double -> long.]
  6. Do you know how to use the following static methods of the Math class: abs(), max(), min()? [Note: Argument and return-value have the same type: int, long, float or double.]
  7. Do you know how to use the static method random() of the Math class? [Note: Returned value is >= 0 and < 1.]
  8. What are two useful named static constants found in each of the wrapper classes Integer, Long, Float, and Double?
  9. What are the names of the static class methods that can be used to convert a String value that contains a number into the actual corresponding number (found in Integer, Long, Float, Double)?
  10. Do you know how to use the following methods of the Character wrapper class: toUpperCase(), toLowerCase(), isUpperCase(), isLowerCase(), isLetter(), isDigit(), isLetterOrDigit(), isWhiteSpace()?
  11. What is an enumeration, and do you know how to use each of the following methods of any enumeration: toString(), equals(), compareTo(), ordinal(), and valueOf()?

Text Appendix C: Creating Classes from Other Classes

  1. What is inheritance?
  2. What is a base/parent/super class?
  3. What is a derived/child/sub class?
  4. What is the syntax for class inheritance?
  5. What is meant by the is-a relationship (also called the may-be-replaced-by-a relationship)?
  6. What is meant by the has-a relationship (also called the composition relationship)?
  7. 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?
  8. What is meant by method overriding (not to be confused with method overloading)?
  9. Can you fill in the blanks in the following statement? When one method overrides another, both must have the same _______________ , the same ____________________ and the same ____________________ .
  10. What does it mean if a method or a class has the final modifier?
  11. What is the keyword super used for in a derived class constructor, and what happens if you don't use it?
  12. Can you explain the use of the keywords this and super for calling constructors?
  13. 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?
  14. Is it possible to use "repeated supers", as in super.super.foo()?
  15. Can an object of a derived class serve as an object of its base class?
  16. Can an object of a base class serve as an object of one of its derived classes?
  17. What is the Object class?
  18. Can a Java class extend two or more classes? In other words, does Java have multiple inheritance?
  19. What methods of the Object class do you think we should "always" override in our own classes?
  20. How do you use the instanceof operator to help you write a "good" equals() method for one of your classes?
  21. What is polymorphism?
  22. What is dynamic binding (also called late binding or runtime binding)?
  23. 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, using a loop, on each object in the array.]

Text Prelude: Designing Classes [and using interfaces]

  1. What are the three main "pillars" of Object Oriented Programming (OOP), and can you briefly describe each?
  2. What is an interface?
  3. What are three things an interface does not have? [How might this question be answered before, and after, Java 8?]
  4. How is an interface used, and what is its general syntax?
  5. What is the syntax that indicates a class is going make use of a single interface?
  6. What is the syntax that indicates a class is going make use of two or more interfaces?
  7. If two or more classes implement the same interface, do they both have to implement it in the same way?
  8. How do we use an interface as a type?
  9. 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.
  10. Can interfaces be extended like classes?
  11. Can one interface extend two or more other interfaces?
  12. How is the built-in Comparable interface used? [In this context, note that the Java API shows interfaces in italic text, classes in normal text.]
  13. What is an abstract method?
  14. What is an abstract class?
  15. Can you create an object of an abstract class type?
  16. How is an abstract class generally used?
  17. Can an abstract class be a type?
  18. What does the acronym UML stand for?
  19. How do you draw a simple UML class diagram, and for what are the symbols + and - used in such a diagram?
  20. Should you show constructors in a UML class diagram?
  21. What does a UML inheritance diagram look like?

Text Java Interlude 2: Exceptions

  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. How many specifically exception-related keywords does Java have, and what are they?
  4. 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?
  5. What should you always supply when you create an Exception object, and how should this be retrieved later and used?
  6. What is a "catch-block parameter", and why is this terminology potentially misleading?
  7. 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?
  8. If you define your own exception class (which you can do), how does inheritance come into play?
  9. Typically, what is minimum number of constructors should you have in an exception class that you define yourself?
  10. What does it mean to "declare" an exception (informally known as "passing the buck"), and what is the syntax for doing so?
  11. What happens if an exception is thrown but not caught and handled?
  12. Where do the various exception classes live (that is, in what packages are they located)?
  13. Could you draw a (small) UML diagram illustrating how Java exceptions fit into the Java class hierarchy?
  14. What is the difference between an error and an exception in Java?
  15. What is the difference between a checked exception and an unchecked exception?
  16. 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?
  17. Can you offer some good advice about when and where to use exceptions?
  18. Can you nest try-catch blocks? Should you?
  19. Can you re-throw an exception? Should you?
  20. What is the purpose of a finally-block?

Text Chapter 9: 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. What must every recursive method call?
  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 recursive binary search works? (discussed in Savitch)
  10. Do you understand how recursive merge sort works? (discussed in Savitch)

Some Generics and Containers (discussed briefly in Savitch and in the previous course)

  1. What is meant by a dynamic data structure?
  2. What is an ArrayList and how does it differ from an "ordinary" array?
  3. What can you not put into an ArrayList?
  4. How does a constructor for a parameterized class type differ from a constructor for a non-parameterized class type?
  5. What are two different constructors for the ArrayList?
  6. What is meant by type inference, and how would you use it in the context of the ArrayList?
  7. What are some useful methods of the ArrayList class?
  8. What is the most convenient kind of loop to use if you wish to process all the elements in an ArrayList object?
  9. What is mean by saying the ArrayList is a "parameterized" type?
  10. What is a HashSet and what are some of its methods?
  11. What is a HashMap and what are some of its methods?