CSCI A202 - Introduction to Programming (II)

Final Exam Information

Possible Final Exam Short Answer Items

  1. What is the difference between a Java applet and a Java application?

    A Java applet is a Java program that is executed using a Web browser. Usually, the bytecode form of the Java applet is pulled across the Internet from another computer and executed locally. A Java application is a Java program that can stand alone. It does not require a Web browser in order to execute.

  2. What is the relationship between a high-level language and machine language?
    What is Java bytecode?

    High-level languages allow a programmer to express a series of program instructions in English-like terms that are relatively easy to read and use. However, in order to execute, a program must be expressed in a particular computer's machine language, which consists of a series of bits basically unreadable by humans. A high-level language program must be translated into machine language before it can be run.

    Java bytecode is a low-level representation of a Java source code program. The Java compiler translates the source code into bytecode, which can then be executed using the Java interpreter. The bytecode might be transported across the Web prior to being executed by a Java interpreter that is part of a Web browser.

  3. What is a variable?

    A variable is a place to store a value. It is the name we give to a memory location. When we refer to the variable name, we are referencing the value stored at the corresponding memory location.

  4. Name two specific purposes of the + operator.

    The + operator can be used for arithmetic addition and for string concatenation.

  5. What is a Java constant? How is it different from a Java variable?

    A Java constant is declared like a variable, except the final modifier is used. The value of a constant cannot be changed, unlike a variable whose value can be changed as needed.

  6. Explain the concept of operator precedence.

    Operator precedence determines how an expression gets evaluated. It is a set of rules that establishes which operators get evaluated first and how operators within the same precedence level evaluate.

  7. What is an infinite loop? Specifically what causes it?

    An infinite loop is a repetition statement that never terminates. Specifically, the body of the loop never causes the condition to become false.

  8. What is the difference between an object and a class?

    A class is a blueprint of an object. It defines the variables (instance variables, that is) and methods that will be a part of every object that is instantiated from it. But a class reserves no memory space for instance variables. Each object has its own data space, and therefore its own state.

  9. What are constructors used for? How are they defined?

    Constructors are special methods in an object that are used to initialize the object when it is instantiated. A constructor has the same name as its class, and it does not return a value.

  10. Explain the difference between an actual parameter and a formal parameter.

    An actual parameter is the value or variable sent to a method when it is invoked. A formal parameter is the corresponding variable in the definition of the method; it takes on the value of the actual parameter so that it can be used inside the method.

  11. How is information passed back from a method?

    An explicit return statement can be used to define the value that is returned from a method. The type of the return value must match the type specified in the method definition.

  12. How are overloaded methods distinguished from each other?

    Overloaded methods are distinguished by having their own signature, which includes the number, order, and type of the parameters. The return type is not part of the distinguishing signature.

  13. Describe the following:

  14. What is the difference between break and continue statements?
    When should they be used?

    A break statement will terminate the execution of the body of the switch or loop. A continue statement begins the next iteration of the loop in which it is contained.

  15. Explain the concept of array bounds checking. What happens when a Java array reference has an index value that is not valid?

    Whenever a reference is made to a particular array element, the index operator ensures that the value of the index is greater than or equal to zero and less than the size of the array. If it is not within the valid range, an ArrayIndexOutOfBounds exception is thrown.

  16. How is an array of objects created?

    An array of objects holds references to the object type specified as the array element. The array of object references and the element objects are instantiated separately.

  17. What are the advantages of using a Vector as opposed to an array? What are the disadvantages?

    A Vector object can dynamically grow and shrink as needed. A disadvantage of the Vector class is that it copies a significant amount of data in order to insert and delete elements, and this process is inefficient.

  18. Describe the Java coordinate system.

    The Java coordinate system is used to reference any drawing surface. The top-left corner represents coordinate (0, 0). The x axis increases to the right and the y axis increases down.

  19. Describe the relationship between a parent class and a child class.

    A child class is derived from a parent class using inheritance. The methods and variables of the parent class automatically become a part of the child class, subject to the rules of the visibility modifiers used to declare them.

  20. How does inheritance support software reuse?

    Because a new class can be derived from an existing one, the characteristics of the parent class can be reused without the error-prone process of copying and modifying code.

  21. Why would a child class override one or more of the methods of its parent class?

    A child class may prefer its own definition of a method in favor of the definition provided for it by its parent. In this case, the child overrides the parent's definition with its own.

  22. What is the super reference important to a child class?

    The super reference can be used to call the parent's constructor, which cannot be invoked directly by name.

  23. What is the defining characteristic of a class hierarchy?

    Any derivation in a class hierarchy should represent an is-a relationship. That is, the child is a more specific version of the parent. If this relationship does not hold, then inheritance is used improperly.

  24. What is polymorphism?

    Polymorphism is the ability for a reference of one class to refer to an object of another. In Java, a reference to a parent class can be used to refer to an object of the child class.

  25. How is overriding related to polymorphism?

    When a child class overrides the definition of a parent's method, two versions of that method exist. If a polymorphic reference is used to invoke the method, the specific version of the method that gets invoked is determined by the type of the object being referred to, not by the type of the reference variable.

  26. What is the difference between a class and an abstract class?

    A class can be instantiated; an abstract class cannot. Abstract classes often contain abstract methods that do not have implementations.

  27. What is the difference between a class and an interface?

    A class can be instantiated; an interface cannot. A class implements an interface by giving a definition for each method defined in the interface.

  28. What is the difference between an abstract class and an interface?

    An abstract class may have some methods defined. An interface contains no defined methods. Neither can be instantiated. A class can implement many interfaces, but can only be derived from a single abstract class.

  29. What is the purpose of an interface?

    An interface is used to define a common set of methods and constants for classes that are often contained in different class hierarchies.

  30. What is a package?

    A package is a language construct used for grouping classes with interdependent or similar characteristics. A package can be imported into a program as a unit.

  31. What is the primary difference between a window and a panel?

    A window is not attached to another container while a panel must be. The user can move a window from one point to another on the screen.

  32. What is an event?

    An event is a situation that arises in software, often in response to a user action such as a mouse button click. A program can be written to process and respond to particular events.

  33. What is a container?

    A container is a Java component that can contain other components. It is used to organize and display a graphical user interface.

  34. What is a layout manager?

    A layout manager controls the format and relative positions of the components in a GUI. Each Java container is governed by a layout manager.

  35. What is the component hierarchy?

    The order in which you put components in containers defines a component hierarchy. Careful planning of the component hierarchy can facilitate high-quality GUI development.

  36. Why would you use a Label instead of a TextField?

    A Label cannot be modified by the user by typing over it, whereas the contents of a TextField can be modified if it is made editable. If you don't want the user to change a value, you don't even want to hint that there may be a possibility. Using a TextField could give the user the wrong idea.

  37. What is the basic model for GUI programs?

    There are three elements: the GUI with its components presented in a particular manner, the listeners that are ready to respond to events, and the rest of the program code that handles the rest of the processing for your particular application.

  38. Why are there many different GUI components?

    There are many GUI components because there are many ways to interact with a system. Some components are particularly well suited to certain types of interactions. It is the challenge of the interface developer to design the user interface for maximum ease and functionality.

  39. Write a recursive definition of a valid Java identifier.

    Left as an exercise to the reader...

  40. What is recursion? What is recursive programming?

    Recursion is the act of defining something in terms of itself. Recursive programming allows a method to call itself, solving a smaller version of the problem each time, until the terminating condition is reached.

  41. Write a recursive definition of xy (x to the power of y), where x and y are integers and y > 0.

    See problem 39.

  42. What is infinite recursion?

    Infinite recursion has no terminating condition or one that is improperly specified. The recursive path is followed forever. In a recursive program, infinite recursion will often result in an error that indicates that available memory has been exhausted.

  43. When is a base case needed for recursion?

    A base case is always required to terminate recursion and begin the process of returning through the calling hierarchy. Without the base case, infinte recursion would result.

  44. Is recursion necessary?

    Recursion is not necessary. Every recursive algorithm can be written in an iterative manner. However, many problem solutions are much more elegant and straightforward when written recursively.

  45. When should recursion be avoided?

    Avoid recursion when the iterative solution is simpler and more easily understood. Recursion has the overhead of multiple method calls and is sometimes (altough very rarely) not entirely intuitive.