




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A study guide for pro 192, focusing on java programming concepts. It includes multiple-choice questions covering topics such as data types, access modifiers, serialization, and array manipulation. The guide provides a series of questions and answers designed to test understanding of java fundamentals and object-oriented programming principles. It is useful for students preparing for exams or quizzes on java programming. The questions cover a range of topics, including variable declarations, method calls, and the behavior of java code snippets. The guide also touches on more advanced concepts such as garbage collection and locale-sensitive text formatting. The questions are designed to assess understanding of java syntax, semantics, and best practices. The guide is a valuable resource for anyone looking to improve their java programming skills and prepare for exams or quizzes.
Typology: Exams
1 / 217
This page cannot be seen from the preview
Don't miss anything!
A, B, D - - - - ✔✔Which of the following are valid declarations? Assume java.util.* is imported. (choose 3) A. Vector
A ⦁ public, private, protected, default B ⦁ default, protected, private, public C ⦁ public, default, protected, private D ⦁ default, public, protected, private E ⦁ public, protected, default, private C - - - - ✔✔Which access modifier allows you to access method calls in libraries not created in Java? A ⦁ public B ⦁ static C ⦁ native D ⦁ transient E ⦁ volatile D - - - - ✔✔Which of the following statements are true? (Select all that apply.) A ⦁ A final object's data cannot be changed. B ⦁ A final class can be subclassed. C ⦁ A final method cannot be overloaded. D ⦁ A final object cannot be reassigned a new address in memory. E ⦁ None of the above. A - - - - ✔✔The keyword extends refers to what type of relationship? A ⦁ "is a" B ⦁ "has a" C ⦁ "was a" D ⦁ "will be a" E ⦁ None of the above B - - - - ✔✔Which of the following keywords is used to invoke a method in the parent class?
D ⦁ The code does not compile. E ⦁ None of the above. D - - - - ✔✔What is the value of x after the following operation is performed? x = 23 % 4; A. 23 B. 4 C. 5. D. 3 E. 5 C - - - - ✔✔Given the following code, what keyword must be used at line 4 in order to stop execution of the for loop? boolean b = true; for (;;) { if (b) {
A ⦁ wait() B ⦁ notify() C ⦁ start() D ⦁ run() A - - - - ✔✔Given the following code, which of the results that follow would you expect?
A. boolean, char, byte, double B. byte, int, float, char C. char, short, long, float D. char, int, float, long E. None of the above D - - - - ✔✔23. Which class provides locale-sensitive text formatting for date and time information? A. java.util.TimeFormat B. java.util.DateFormat C. java.text.TimeFormat D. java.text.DateFormat B - - - - ✔✔24. The following line of code is valid. int x = 9; byte b = x; A. True B. False A, B, C - - - - ✔✔25. Which of the following code snippets compile? (choose 3) A. Integer i = 7; B. Integer i = new Integer(5); int j = i; C. byte b = 7; D. int i = 7; byte b = i; E. None of the above D - - - - ✔✔26. What will be the output of the following code? public class StringTest { public static void main(String [] a) { String s1 = "test string"; String s2 = "test string"; if (s1 == s2) {
System.out.println("same"); } else { System.out.println("different"); } } } A. The code will compile but not run. B. The code will not compile. C. "different" will be printed out to the console. D. "same" will be printed out to the console. E. None of the above B - - - - ✔✔27. Java arrays always start at index 1. A. True B. False C - - - - ✔✔28. Which of the following statements accurately describes how variables are passed to methods? A. Arguments are always passed by value. B. Arguments are always passed by reference. C. Arguments that are primitive type are passed by value. D. Arguments that are passed with the & operator are passed by reference. D - - - - ✔✔29. How do you change the value that is encapsulated by a wrapper class after you have instan- tiated it? A. Use the setXXX() method defined for the wrapper class. B. Use the parseXXX() method defined for the wrapper class. C. Use the equals() method defined for the wrapper class. D. None of the above.
D - - - - ✔✔4. If all three top-level elements occur in a source file, they must appear in which order? A. Imports, package declarations, classes/interfaces/enums B. Classes/interfaces/enums, imports, package declarations C. Package declaration must come first; order for imports and class/interfaces/enum definitions is not significant D. Package declaration, imports, class/interface/enum definitions. E. Imports must come first; order for package declarations and class/interface/enum definitions is not significant A, E - - - - ✔✔5. Consider the following line of code: int[] x = new int[25]; After execution, which statements are true? (Choose 2) A. x[24] is 0 B. x[24] is undefined C. x[25] is 0 D. x[0] is null E. x.length is 25 D - - - - ✔✔6. Consider the following application:
B - - - - ✔✔11. Suppose a source file contains a large number of import statements. How do the imports affect the time required to compile the source file? A. Compilation takes no additional time. B. Compilation takes slightly more time. C. Compilation takes significantly more time. A - - - - ✔✔12. Suppose a source file contains a large number of import statements and one class definition. How do the imports affect the time required to load the class? A. Class loading takes no additional time. B. Class loading takes slightly more time. C. Class loading takes significantly more time. A, C - - - - ✔✔13. Which of the following are legal import statements? (choose 2) A. import java.util.Vector; B. static import java.util.Vector.; C. import static java.util.Vector.; D. import java.util.Vector static; B, C - - - - ✔✔14. Which of the following may be statically imported? (Choose 2) A. Package names B. Static method names C. Static field names D. Method-local variable names C - - - - ✔✔15. What happens when you try to compile and run the following code? public class Q15 { static String s;
public static void main(String[] args) { System.out.println(">>" + s + "<<"); } } A. The code does not compile B. The code compiles, and prints out >><< C. The code compiles, and prints out >>null<< C, D - - - - ✔✔16. Which of the following are legal? (Choose 2) A. int a = abcd; B. int b = ABCD; C. int c = 0xabcd; D. int d = 0XABCD; E. int e = 0abcd; F. int f = 0ABCD; A, B - - - - ✔✔17. Which of the following are legal? (Choose 2) A. double d = 1.2d; B. double d = 1.2D; C. double d = 1.2d5; D. double d = 1.2D5; C - - - - ✔✔18. Which of the following are legal? A. char c = 0x1234; B. char c = \u1234; C. char c = '\u1234';
B. int x = 6; if (!(x > 3)) {} C. int x = 6; x = ~x; A - - - - ✔✔3. Which of the following expressions results in a positive value in x? A. int x = - 1; x = x >>> 5; B. int x = - 1; x = x >>> 32; C. byte x = - 1; x = x >>> 5; D. int x = - 1; x = x >> 5; A, C - - - - ✔✔4. Which of the following expressions are legal? (Choose 2) A. String x = "Hello"; int y = 9; x += y; B. String x = "Hello"; int y = 9; if (x == y) {} C. String x = "Hello"; int y = 9; x = x + y; D. String x = "Hello"; int y = 9; y = y + x; A - - - - ✔✔5. What is - 8 % 5? A. - 3 B. 3 C. - 2 D. 2 B - - - - ✔✔6. What is 7 % - 4? A. - 3 B. 3 C. - 4 D. 4 B - - - - ✔✔7. What results from running the following code?
C. float D. You can't add a short to a float. A - - - - ✔✔14. Which statement is true about the following method? int selfXor(int i) { return i ^ i; } A. It always returns 0. B. It always returns 1. C. It always an int where every bit is 1. D. The returned value varies depending on the argument. D - - - - ✔✔15. Which of the following operations might throw an ArithmeticException? A. >> B. >>> C. << D. None of these D - - - - ✔✔16. Which of the following operations might throw an ArithmeticException? A. + B. - C. * D. / E. None of these D - - - - ✔✔17. What is the return type of the instanceof operator? A. A reference B. A class
C. An int D. A boolean A - - - - ✔✔18. Which of the following may appear on the left-hand side of an instanceof operator? A. A reference B. A class C. An interface D. A variable of primitive type A, B - - - - ✔✔19. Which of the following may appear on the right-hand side of an instanceof operator? (Choose 2) A. A reference B. A class C. An interface D. A variable of primitive type E. The name of a primitive type D - - - - ✔✔20. What is - 50 >> 1? A. A negative number with very large magnitude. B. A positive number with very large magnitude. C. - 100 D. - 25 E. 100 F. 25 A, D, E - - - - ✔✔1. Which of the following declarations are illegal? (Choose 3) A. default String s; B. transient int i = 41; C. public final static native int w();