Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
JAVA PROGRAMMING STUDY QUESTIONS CHAPTERS 1 - 5 NAME: _____________________________________________________ MULTIPLE CHOICE Directions: Circle the response that best answers the question 1. Which of the following is an example of an object-oriented programming language? A. Fortran B. C C. C++ D. COBOL 2. Why is object-oriented programming often the preferred programming paradigm? A. objects are easier to visualize for the user B. objects-oriented code executes faster than any other code C. object-oriented code is easy to reuse D. object-oriented code is automatically user friendly 3. Which of the following programming paradigms requires a programmer to use a linear approach to software development? A. Event-Driven Programming B. Functional Programming C. Object-Oriented Programming D. Procedural Programming 4. When do object-oriented programmers write procedural code? A. when they write the code to add object attributes B. when they write the code for object behaviors C. when they write the code for object instantiation D. when they write code for object destruction 5. Which sequence best describes the physical steps taken to produce a running Java program? A. Write the program. Compile to bytecode. Translate to native code. Run program. B. Write the program. Translate to native code. Compile to bytecode. Run program. C. Write the program. Compile to bytecode. Run program. D. Write the program. Compile to native code. Run program. 1 6. What are the two ways that different programming languages use to change source code into machine language? A. analyze or design B. compile or execute C. compile or interpret D. interpret or execute 7. Which of the following are used to instruct a program to perform mathematical calculations or a test of data? A. operands B. identifiers C. variables D. operators 8. Which of the following terms refers to the usage of rules for symbols and keywords of a language? A. grammar B. local C. syntax D. constant 9. Which of the following could possibly cause a runtime error? A. misspelled keyword B. missing semicolon C. divide by zero D. incorrect class modifier 10. User interface objects do not contain what? A. buttons B. check boxes C. servers D. radio buttons 11. The Java Virtual Machine translates and executes code that is stored in which type of files? A. .java files B. .code files C. .javac files D. .class files 12. What is the suffix of a java bytecode file? A. .class B. .cls C. .java D. .jvm 2 13. Which of the following JDK utility programs is used to compile a Java source code file into bytecode? A. jar B. java C. javac D. javadoc 14. What is the file extension of a Java source file? A. .class B. .cls C. .java D. .jvm 15. Which of the following interprets the bytecode to the specific machine’s language? A. bytecode compiler B. Java compiler C. Java source code D. JVM 16. Which of the following is an example of a keyword that is used to specify access? A. Public B. public C. PUbliC D. PUBLIC 17. One of the first lines of a Java program is the class definition. Which Java keyword must be included in the class definition? A. static B. class C. final D. private 18. Which of the following best describes the relationship between a public Java class name and a Java source code file name that contains the public class? A. The names must be different. B. The names must start with the same letter. C. The names must be the same, but case is irrelevant. D. The names must match exactly including case. 19. Which of the following uses the correct syntax for a main( ) method that starts a Java application? A. public static void main( ) B. public static void main (string args[ ]) C. public static void main (String args[ ]) D. public static main (String args[ ]) 3 20. Which of the following is a valid Java identifier? A. 2Dpoint B. Point#2 C. Point 2D D. TwoDpoint 21. What does Java use as a statement terminator? A. : (colon) B. ; (semi-colon) C. , (comma) D. . (period) 22. Which symbol is used to indicate that the accessibility to attributes and methods is protected only to limit access to objects in the same package? A. “+” B. “-“ C. “#” D. “@” 23. What is a class? A. a specific instance of an object B. an object identifier C. an object reference D. a blueprint or specification of an object 24. Which item in the graphic accurately represents the symbol for a class of objects? A Name B Object Attributes Attributes Methods Methods C Name Attributes Functions A. graphic A B. graphic B C. graphic C D. graphic D 25. D Name Date Methods Which of the following choices is an instance of a class Car? A. MountainBike B. FordMustang C. DodgeCaravan D. ToyotaPickUp 4 26. Which of the following terms refers to a method that has the same name as the class and no return type? A. mutator B. accessor C. constructor D. custom method 27. Which of the following terms refers to a method that accomplishes a non-standard task in a class? A. mutator method B. accessor method C. instance method D. custom method 28. Which of the following best describes a mutator? A. a mutator allows you to change the object reference to another object of the same type B. a mutator provides standard ways of setting data values for an object C. a mutator is an object method to create and return a new object of the same type D. a mutator provides standard ways of retrieving data values for an object 29. Which of the following best describes an accessor? A. an accessor lets you overload a class behavior B. an accessor provides standard ways of setting data values for an object C. an accessor provides standard ways of retrieving data values for an object D. an accessor is an object method to create and return a new object of the same type 30. Which of the following best describes a constructor? A. a constructor is a special method used to create new objects B. a constructor lets you overload a class behavior C. a constructor is a method with a void return type D. a constructor allows you to change the object reference to another object of the same type 31. If you were writing code for a company that rents cars, what is the best set of mutators listed below for the car inventory? A. setMake, setModel, setColor, setIDnumber, setCurrentCustomer, setMileage, setRentalRate, setStatus, setDueDate B. getMake, getModel, getColor, getIDnumber, getCurrentCustomer, getMileage, getRentalRate, getStatus, getDueDate C. calculateRent, calculatetax, calculatetotalbill, calculateDueDate D. createLicenseNumber, createCustomerName, createCustomerAddress 32. If you were writing code for a company that rents cars, what is the best set of accessor listed below for the car inventory? A. setMake, setModel, setColor, setIDnumber, setCurrentCustomer, setMileage, setRentalRate, setStatus, setDueDate B. getMake, getModel, getColor, getIDnumber, getCurrentCustomer, getMileage, getRentalRate, getStatus, getDueDate C. calculateRent, calculatetax, calculatetotalbill, calculateDueDate D. createLicenseNumber, createCustomerName, createCustomerAddress 5 33. Which terms are used to describe how an object knows to do things? A. behaviors and methods B. reference and methods C. operations and behaviors D. inheritance and behaviors 34. What is the syntax for a single line comment in a Java source file? A. // B. \\ C. /* */ D. \* *\ 35. Which of the following integral data types can store the largest value? A. byte B. short C. int D. long 36. What is the default value for an object reference? A. 0 B. false C. null D. empty 37. What is the scope of a local variable in a method? A. inside the method that declared the variable B. the entire class that declared the variable C. only classes in the same package as the class that declares the variable D. all classes 38. Which of the following statements about the Java keywords is true? A. they are not case-sensitive B. they can never be used as identifiers C. they can also be used as identifiers D. they can never be used in comments 39. What symbols surround the statements in a block of code? A. white space B. commas C. semicolons D. braces 40. What tells the JVM how much memory is required when storing data? A. scope of the data B. value of the data C. life of the data D. type of the data 6 41. The keyword final is used to define which of the following storage locations? A. reference B. static C. local D. constant 42. What stores its own copy of the complete set of attributes specified by a class? A. variable of the class B. reference of the class C. instance of the class D. string of the class 43. Which data modifier does Java use to create a constant? A. final B. public C. protected D. static 44. Which type of data do all the objects of a class share? A. reference B. static C. local D. constant 45. Which one of the following Java keywords is required when declaring the main method that is the start of a Java application? A. static B. class C. final D. int 46. Which term refers to what an object knows? A. method B. class C. attribute D. encapsulation 47. Which term refers to the data in a method that is passed to another method within the calling method? A. arguments B. input C. output D. specifications 48. Which of the following words is a keyword from the Java language? A. dimension B. subroutine C. header D. private 7 49. When a programmer defines a parent or super class with sub classes that receive behaviors and attributes from the super class it is known as what? A. finalizer B. mutator C. inheritance D. encapsulation E. accessor F. mutator G. constructor H. custom 50. Which of the following terms describes the process of hiding information in an object? A. encapsulation B. relationship C. constructor D. mutator 51. What does the keyword “private” indicate? A. access to the object is restricted to within the class it has declared. B. access to the object is restricted to classes with the same name as the object C. access to the object is restricted to classes within the same package as the class that declares the object D. access to the object is unrestricted 52. Which class method has the same name as the class it belongs to? A. accessor B. mutator C. constructor D. custom 53. Which class method has a return type other than void and allows use of private data member values? A. accessor B. mutator C. constructor D. custom 54. Which class method does not return a value but does not have the same name as the class? A. accessor B. mutator C. constructor D. custom 55. Which class method would be used for specialized processing such as calculating a total? A. accessor B. mutator C. constructor D. custom 8 56. Which class method is executed at the time a new instance of an object is created? A. accessor B. mutator C. constructor D. custom 57. What will happen if a programmer tries to execute the following code? byte num; num = 1 + 3; A. num will hold the value of 4 B. num will hold the value of 0 C. num will hold the value of 13 D. the code will not compile because of a type error 58. What happens if a programmer tries to compile and execute the following lines of code in a method? float numA; float numB = 2.0; numA = 6.0/numB; A. numA will hold the value 3.0 B. it will not compile because of the type differences involved C. numA will hold the value 3 D. numA will hold the value 0 59. The dot operator is used to do which of the following operations? A. The dot operator is used to set an attributes value. B. The dot operator is used to create new object behaviors. C. The dot operator is used to create an object. D. The dot operator is used to access non-private methods or member data of an object. 60. Which of the following operators has the highest precedence? A. Addition B. modulus C. division D. parentheses 61. What is casting? A. Converting one object type to another type. B. Deleting the object. C. Accessing the non-private attributes of the object. D. Accessing the private attributes of the object. 62. What is the value of x after this statement executes? int x = 14/5 * 5; A. 14 B. 10 C. 15 D. 0.56 9 63. What are the three control structures used in Java? A. sequence, flow, and decision B. sequence, selection, and decision C. sequence, selection, and iteration D. iteration, decision, and repetition 64. Which of the following describes how procedural programming and object-oriented programming use control structures differently? A. Object-oriented programming uses control flow to structure the flow of the entire program, whereas procedural programming does not. B. Control structures are used only in the methods of a class, while in procedural languages the entire program implements control structures. C. Object-oriented programming does not use control structures. D. Control structures are not used in either type of language. 65. What happens if a double value is assigned to an int? double x = 3.7; int num = x; A. the value of num rounds to 4 B. the value of num gets trunctated to 3 C. num is converted to a double D. the code will not compile 66. Which of the following statements best describes a sequence statement structure? A. The flow of execution can change based on the value of an expression. B. The flow of execution in a method proceeds from one statement to the statement following it, in the order they appear in the source file. C. Execution of the same set of statements can be performed as many times as the programmer wants. D. Code is broken up into modules called methods. 67. Which statement correctly declares a boolean variable named truth? A. boolean truth = true; B. boolean truth = false C. boolean truth == true; D. boolean = true; 68. Which statement correctly declares and initializes a primitive char variable? A. char cr = '/r'; B. char cr = '\n'; C. char c2 = W; D. char c2 = 'W'; 69. What happens when the following lines of code are compiled and executed? float x; x = 3.4; A. The code will not compile. B. The value of x will be 3.4. C. The code will compile but it will produce a runtime error. D. The code will compile but it will produce a warning. 10 70. A math-tutor application is being created that students will use to practice addition skills. Which of the following would be defined as an object in this application? A. The student's name. B. An operand in an addition problem. C. An addition problem. D. The number of questions a student answers correctly. 71. The math application classes has been compiled and a MathProblem object is to be created in another class. What is the syntax for this declaration? A. problem = new MathProblem(); B. set problem = new MathProblem(); C. MathProblem problem; D. MathProblem = new MathProblem(); 72. Which of the following statements best describes the concept of encapsulation? A. Data is freely available so the application has no difficulty accessing the data it needs. B. Data is kept private and the methods to manipulate the data are packaged in a class with the data, so the data is manipulated in a predictable manner. C. A method can be written several ways in the same class as long as the signatures are different. D. A garbage collector destroys all objects no longer being referenced and encapsulates them as they are destroyed. 73. Which pair of method signatures shows overloaded methods? A. float CalcResult(int numA, float numB) int CalcResult(int numB, float numC) B. float DoSomething(int numA) float DoSomething(float numA) C. float CalcAnswer(int numA, float numB) float CalcResult(int numA, float numB) D. float CalcResult(float numA, int numB, int numC) int CalcResult(float numA, int numB, int numC) 74. What is a reason for writing an overloaded method? A. To provide a way for a method to return a variety of data types. B. To allow the same task to be called by different names. C. To provide the user of the method alternative ways to call the method depending on the type of data the user wants to provide to the method. D. To allow the user of the method a way to change the order of the arguments when calling the method. 75. A class called Picture has been created that is to be available to anyone. What would be the correct way to declare a constructor for this class? A. private void makePicture () B. public Picture() C. public void Picture() D. private Picture() 11 76. What is required of the method return value(s)? A. It must match the argument list. B. It must be assignment compatible with the signature. C. It must be one of the arguments passed to the method. D. It must have the same variable name as the arguments. 77. What must all methods have? A. a return type B. an argument C. a name and return type D. a qualifier 78. What are the parts of a method signature? A. qualifiers, name, and arguments B. arguments, return type, and body C. return type, qualifiers, and name D. arguments and method name 79. What is the lifetime of an object or method variable in Java? A. during the compilation process B. duration of the defining code block C. duration of the entire program D. during the programming process only 80. What best describes the data that is available to a method? A. arguments, class data members, local variables, and values returned by method calls B. local variables, static variables, arguments , and instance variables C. class attributes, local variables, and arguments D. local variables and arguments 81. Why is Java considered desirable as a language for the Internet? 82. What is a JVM? What is its purpose? 83. What is bytecode and what is its purpose? 84. What is the API? How do you use the API in Java? 85. Describe OOP? 86. Define inheritance, encapsulation. 87. What statement is used to include a package in a program? 88. Explain the difference between declaring an object name and creating the object. 89. List the rules for naming objects. 90. What are naming conventions? Why are they needed? 12 91. Discuss the purpose of comments in a Java program. What types of comments can you use? 92. What is the purpose of the awt package? 93. Name and describe the three types of bugs that may appear in a program. 94. How are the Color and Font objects used? 95. Describe how to change the color of an applet's panel, and how to change to color of text that displays on the applet. 96. What is the purpose of an HTML file? What tag must appear in the HTML file to make an applet run? 97. What is the purpose of the Class Design Form? 98. What is the purpose of the constructor method? When and how would you call a constructor method? 99. Give examples of constants defined in the Java awt package 100. What is a string literal? Give an example of its use. 101. How do you create a numeric constant? 102. Differentiate between a primitive data type and a data wrapper class. 103. Explain the difference between a class variable and an instance variable. How is each declared and used? 104. List and explain the three methods available for a TextArea component 105. Explain the purpose of concatenation. How is concatenation implemented? 106. What does it mean if you receive a message that your code is deprecated? 107. List and explain the steps you need to have your program respond to button’s click. 108. What methods must you include in your program when you implement the MouseListener? 109. What is the default layout when no layout manager is specified? 110. If you want to create a table appearance with each component of the same size in rows and columns, what would be the appropriate layout manager 111. Name the sections available in a BorderLayout. 112. What is the purpose of the horizontal and vertical gap parameters? 13 113. How would you add a component to the top section of a border layout? 114. Explain each of the following GridBagConstraints data members. 115. Discuss the purpose of the REMAINDER and RELATIVE constants. What is the difference between using gridx versus gridheight 116. What is the default alignment within a cell of a GridBagLayout? 117. Why would you want to use Panels? 118. What are the differences between using the + and += and ++ operators? 119. What is the difference between intCount++ and ++intCount if the operation is a statement by itself 120. When would you use a decrement operator? 121. How does precedence of operators impact your applications? 122. Why must you convert user input to a numeric data type? How is the conversion accomplished? 123. How can you convert a numeric field for display in a label? 124. How does Java handle mixed data types in a calculation? 125. How can you explicitly change the data type of a variable? 126. Describe the necessary steps to format a floating-point number of output. The number should display with exactly two decimal positions. 127. How is the locale for the formatting determined? How can you indicate a specific locale? 128. What is an exception? When does an exception occur? How do you handle an exception? 129. What is a wrapper class? When would it be advantageous to use a wrapper class? 130. List and define the basic concepts of object-oriented programming 131. Explain the relationship between a superclass and a subclass. 132. What is an abstract class? An interface? 133. What is an object, how is it created? 134. What is the effect of making a data member private? A method private? 135. Where is the data type for a method's return value specified? 14 136. How is a value returned from a method? 137. When would you use the return type void? 138. What is a method's parameter list and how does it relate to arguments in a method call? 139. What items properly belong in an applet class? What items properly belong in a separate class? 140. Explain how the compiler can recognize that a method is a constructor method. 141. How can an object of a class retrieve the value of a private property? 142. What is a class variable and how does it differ from an instance variable? 143. Why might a class have multiple methods with the same name but different parameter lists? 15 DIRECTIONS: For the following UML, create the class indicated below in BlueJ. Make sure your class compiles properly. 1. Within your class, create a new object of the class (in the main method) to test your overloaded constructor. Set up code to print out the data set by the constructor. When you print your values, make sure that your print line has the appropriate label also printed to distinguish between the data members. 2. To test your accessors and mutators, create a second new object and set up code to change the data member values, then print out resulting data values (with the appropriate label to identify the values). 3. Your custom method will calculate the inventory cost of that item by multiplying the quantity of the item in the inventory by the price of that product item. Write code in your main method which will print out your inventory cost (with the appropriate label to identify the value). 4. Save your work on the disk provided and turn in. Make sure your name is on your disk. Product – – – – prodName: String prodID: int prodQuantity: int prodPrice: double + + + + + + + + + + + + main(args: String[ ]): void Product( ) Product(name: String, id: int, qty: int, price: double) setProdName(name: String): void getProdName( ): String setProdID(id: int ): void getProdID( ): int setProdQuantity(qty: int): void getProdQuantity( ): int setProdPrice(price: double): void getProdPrice( ): double calcInvCost(): double 16