Cs 142 Final Review

43 Questions

Settings
Please wait...
Web Application Quizzes & Trivia

CS 142 Finals Review


Questions and Answers
  • 1. 
    The programs that computer executes are called
    • A. 

      Programming languages

    • B. 

      Software

    • C. 

      Integrated development environment

    • D. 

      Browsers

  • 2. 
    The ENIAC computer was build from which components:
    • A. 

      Integrated circuits

    • B. 

      Flash memory

    • C. 

      Transistors

    • D. 

      Vacuum tubes

  • 3. 
    The Java code on the Internet and that are run by Web browsers are called:
    • A. 

      Scripts

    • B. 

      Applets

    • C. 

      Databases

    • D. 

      Style sheets

  • 4. 
    The free Java modules that perform various specific tasks and that make Java arich and portable language are called:
    • A. 

      Library packages

    • B. 

      Portlets

    • C. 

      Servlets

    • D. 

      Style sheets

  • 5. 
    Which one of the following statements is true about a Java compiler?
    • A. 

      It translates the object code into the source code.

    • B. 

      It translates the library code into the virtual machine code.

    • C. 

      It translates the source code into the virtual machine code.

    • D. 

      It translates the virtual machine code into the source code.

  • 6. 
    Which one of the following programs can execute Java class files?
    • A. 

      Assembler

    • B. 

      Linker

    • C. 

      Editor

    • D. 

      Virtual machine

  • 7. 
    Is there anything wrong with this code?System.out.print("3 + 3 =")System.out.println(3 + 3);
    • A. 

      Compile-time error

    • B. 

      Run-time error

    • C. 

      Programming error

    • D. 

      No error

  • 8. 
    Java can be used to develop rich applications for the Web that are called
    • A. 

      Operating systems

    • B. 

      Applets

    • C. 

      Libraries

    • D. 

      Cookies

  • 9. 
    A major difference between C++ and Java is that:
    • A. 

      C++ is a high-level, while Java is a low-level language

    • B. 

      C++ is designed for consumers, while Java is designed for commerce

    • C. 

      C++ is object-oriented, while Java is not

    • D. 

      C++ is not portable, while Java is portable

  • 10. 
    An example of a Java integrated development environment is:
    • A. 

      NetBeans

    • B. 

      Turbo Pascal

    • C. 

      Visual Studio .NET

    • D. 

      PHP

  • 11. 
    A Java class with the name Printer has to be saved using the source file name:
    • A. 

      Printer.java

    • B. 

      Printer.java

    • C. 

      Printer.txt

    • D. 

      Printer.java

  • 12. 
    This statement starts the declaration of a class in Java:
    • A. 

      Public static void main(String[] args)

    • B. 

      Public class Classname

    • C. 

      System.out.println("Hello, World!");

    • D. 

      Java class

  • 13. 
    This Java statement prints a blank line:
    • A. 

      Public static void main(String[] args)

    • B. 

      System.out.print();

    • C. 

      System.out.println();

    • D. 

      System.out.Println();

  • 14. 
    Which Java statement does not contain an error?
    • A. 

      System.out.print(;

    • B. 

      System.out.print()

    • C. 

      System.out.printl();

    • D. 

      System.out.printl();

  • 15. 
    In order to run Java programs on a computer, the computer needs to have softwarecalled a(n):
    • A. 

      Assembler

    • B. 

      Virtual machine

    • C. 

      Windows

    • D. 

      Debugger

  • 16. 
    The Java statement "public static void main(String[] args)" declares a :
    • A. 

      Class

    • B. 

      Variable

    • C. 

      Constant

    • D. 

      Method

  • 17. 
    What is the output of the following code snippet?System.out.print("Hello");System.out.println("Good Day!");
    • A. 

      Hello Good Day!

    • B. 

      Hello Good Day!

    • C. 

      HelloGood Day!

    • D. 

      No output due to compilation errors

  • 18. 
    What is the purpose of the following algorithm?num = 0Repeat the following steps for 100 timesinput var1if var1 > numnum = var1print num
    • A. 

      To find the highest among 100 numbers

    • B. 

      To print out the 100 numbers

    • C. 

      To find the smallest among 100 numbers

    • D. 

      To search for a particular number among 100 numbers

  • 19. 
    Consider the following pseudocode. What does it produce?Create a list of consecutive integers from two to n: (2, 3, 4, ..., n).Initially, let p equal 2.Repeat following steps until p2 is greater than n.Strike from the list all multiples of p less than or equal to n.Find the first number remaining on the list greater than p; replace p with thisnumber.
    • A. 

      All even numbers from 2 to n

    • B. 

      All Fibonacci numbers from 2 to n

    • C. 

      All prime numbers from 2 to n

    • D. 

      All factorial numbers from 2 to n

  • 20. 
    What operation is least efficient in an ArrayList?
    • A. 

      Add element to the middle of the list

    • B. 

      Linear traversal step

    • C. 

      Read element

    • D. 

      Modify element

  • 21. 
    Which data structure would best be used for keeping track of bank customerswaiting for a teller?
    • A. 

      Queue

    • B. 

      Stack

    • C. 

      List

    • D. 

      Array

  • 22. 
    What must be included in a LinkedList class node?I a reference to the next nodeII a reference to the previous nodeIII a data element
    • A. 

      I

    • B. 

      I and II

    • C. 

      III

    • D. 

      I, II, and III

  • 23. 
    Assuming that staff is a LinkedList object, what is the content and iteratorposition in the staff object?public static void main(String[] args){LinkedList staff = new LinkedList();staff.addLast("Diana");staff.addLast("Tom");staff.addLast("Harry");staff.addLast("Romeo");// | in the comments indicates the iterator positionListIterator iterator = staff.listIterator(); // |DTHRiterator.next();iterator.next();iterator.add("Juliet");iterator.add("Nina");iterator.previous();iterator.remove();…}
    • A. 

      DTJNHJ

    • B. 

      DTN|HR

    • C. 

      DT|JHR

    • D. 

      DTJ|HR

  • 24. 
    Which method in the ListIterator class cannot be called twice in a row?
    • A. 

      Previous

    • B. 

      Remove

    • C. 

      Next

    • D. 

      There is no restriction

  • 25. 
    Why is it important to understand the underlying implementations of data structuretypes?(e.g. HashSet, TreeSet, ArrayList, LinkedList, etc.)
    • A. 

      It helps you choose a better coding implementation

    • B. 

      It helps you choose a data structure with best efficiency in all operations

    • C. 

      It helps you choose a data structure with best efficiency in operations you need most

    • D. 

      Nothing, because we do not know about implementation details

  • 26. 
    What operation is least efficient in a LinkedList?
    • A. 

      Add element

    • B. 

      Linear traversal step

    • C. 

      Remove element

    • D. 

      Read element

  • 27. 
     In a linked list data structure, when does the reference to the first node need to beupdated?I inserting into an empty listII deleting from a list with one nodeIII deleting an inner node
    • A. 

      I

    • B. 

      II

    • C. 

      I and II

    • D. 

      III

  • 28. 
    What is the result of this code?Queue q = new LinkedList();q.add("C");q.add("B");q.add("A");while (q.size() > 0) { System.out.print(q.remove() + " "); }
    • A. 

      Q will contain a single element, "A"

    • B. 

      A B C will be printed

    • C. 

      C B A will be printed

    • D. 

      The code does not compile because q is not a LinkedList type

  • 29. 
    Which operations from the list data structure could be used to implement the addand remove operations of a FIFO queue structure?I addLastII add FirstIII removeFirst
    • A. 

      I

    • B. 

      II

    • C. 

      I and III

    • D. 

      II and III

  • 30. 
    Suppose you push integer elements 1,2,3,4 on the stack in that order, then pop offthe stack and add them to a queue, and repeat that three more times, shifting he elementsfrom the queue to the stack each time. In what order will you remove the elements from thequeue on the fourth time?
    • A. 

      1,2,3,4

    • B. 

      1,2,4,3

    • C. 

      4,3,2,1

    • D. 

      4,3,1,2

  • 31. 
    A(n) ____________________ is a collection of items with "last in first out" retrieval.
    • A. 

      Queue

    • B. 

      Stack

    • C. 

      Array list

    • D. 

      Iterator

  • 32. 
    ____________________ store items in a first in, first out or FIFO fashion.
    • A. 

      Queue

    • B. 

      Stack

    • C. 

      Array list

    • D. 

      Iterator

  • 33. 
    The Stack peek operation is not considered a primitive operation because it can bereplicated by a sequence of other Stack operations. Choose the correct sequence.
    • A. 

      Push, push

    • B. 

      Pop, push

    • C. 

      Push, pop

    • D. 

      Pop, pop

  • 34. 
    What happens when we try to add an element to a Set in which the element isalready present?
    • A. 

      It is added after its duplicate

    • B. 

      Is replaces the duplicate

    • C. 

      It is not added

    • D. 

      It is added anywhere convenient

  • 35. 
    Which Java code is not correct?I Set cats = new HashSet();II HashSet cats = new HashSet();III HashSet cats = new TreeSet();
    • A. 

      I

    • B. 

      III

    • C. 

      I and II

    • D. 

      II and III

  • 36. 
    HashMap and TreeMap classes both implement the Map interface. What makesthem different?I they use different underlying data structuresII HashMap does not implement all Map methodsIII HashMap can only handle a fixed number of key, value pairs
    • A. 

      I

    • B. 

      II

    • C. 

      I and II

    • D. 

      III

  • 37. 
    Which code is correct based upon the object declaration below?Map myLabels = new HashMap();
    • A. 

      MyLabels.put(new JLabel("Hi"), "John");

    • B. 

      MyLabels.put("John", new JLabel ("Hi"));

    • C. 

      MyLabels.put("John");

    • D. 

      MyLabels.remove(new JLabel ("Hi");

  • 38. 
    What does the equals method, inherited from the Object class, actually test for?
    • A. 

      If the objects have the same name

    • B. 

      If the objects are stored in the same location

    • C. 

      If all corresponding fields have the same value

    • D. 

      If at least one corresponding field has the same value

  • 39. 
    Which hash table method will make use of the equals method?I hashcodeII mapIII contains
    • A. 

      I

    • B. 

      I and II

    • C. 

      III

    • D. 

      I, II, and III

  • 40. 
    If you override the equals method but not the hashCode method, what is the likelyresult?
    • A. 

      Some objects will be impossible to find

    • B. 

      The number of collisions will be high

    • C. 

      The get method will run at O(n) complexity

    • D. 

      The get method will run at O(1) complexity

  • 41. 
    Suppose we create an Iterator to a 10-element LinkedList. After calling the nextmethod, we call the remove method twice. What will be the result?I an IllegalStateException is thrownII first two linked list elements are removedIII first linked list element is removed
    • A. 

      I

    • B. 

      II

    • C. 

      III

    • D. 

      I and III

  • 42. 
    If we insert into an empty binary search tree the following sequence of nodes withthe specified keys, what will be the result?Keys: 12 , 7, 25, 6, 9, 13, 44
    • A. 

      The tree will resemble a list

    • B. 

      Node with key = 7 will not have any children

    • C. 

      The root will have key = 12

    • D. 

      The root will have key = 6

  • 43. 
    When designing a hierarchy of classes, features and behaviors that are common toall classes are placed in ____.
    • A. 

      Every class in the hierarchy

    • B. 

      The superclass

    • C. 

      A single subclass

    • D. 

      All subclasses