Sun Certification Java2 Programmer Exam (SCJP) Question Analysis
Foreword Whether you are a newbie or an expert in programming, you will be amazed in the infinite charm of Sun Java. Java brings you not only to object-oriented, open, platform-independent, easy-to-use, security, and "Write Once, Run Anywhere", more importantly, it provides a novel expression The way of thought, a brand new thinking mode. As the scale to be solved is constantly expanding, Java thoroughly faces the flexibility of object-oriented ideas. Undoubtedly, Java is the best-handed weapon when you develop large software, or the introduction of IT's entry is preferred. SCJP Exam Introduction · Examination Form All English Questions : 61% Time limit: 120 minutes fee: 1250 yuan · Requirements to create Java applications and Applets using Java programming languages. Define and describe the garbage collection, security, and Java virtual machine (JVM). Describe and use the Java language-oriented features. Develop graphical user interface (GUI). Multiple layout management supported by Java. Describe and use Java event processing mode. Use the Java language mouse input, text, windows, and menu widgets. Use Java's exception to control program execution and define users their own exceptions. Using advanced object-oriented features of Java language, including method overload, method override, abstract class, interface, finAl, static, and access control. Implement the input / output (I / O) of the file. Use the inner thread mode in the Java language to control multithreading. Use Java's Sockets mechanism for network communication. Test questions Analysis 1: Choose the Three Valid Identifiers from Those Listed Below. A. IdolikethelongnameClass B. $ BYTE C. Const D. _ok E. 3_Case Answer: A, B, D Review: Java Mark must be letters, dollars The character ($) or underscore (_) begins. Keywords and reserved words cannot be used as a marker. The Const in the option C is a reserved word of Java, so it cannot be made. The 3_case in the option e started the number of Java in the beginning and violated Java rules. Example 2: How can you force Garbage Collection of an Object? A. Garbage Collection Cannot Be Forced B. Call System.gc (). C. Call System.gc (), Passing IN a Reference To The Object To Be Garbage Collected. D. Call runtime.gc (). E. SET All References to the Object to new value (Null, for example). Answer: A Comments: Waste collection in Java cannot be executed immediately. Call system.gc () or runtime.gc () static method cannot guarantee the immediate execution of the garbage collector, because there may be a higher priority thread. So the options B and D are incorrect. The error of the option C is that the system.gc () method is not accepting parameters. The method in the option E allows the object to be collected when the next garbage collector is running.
Example 3: Consider The Following Class: 1. Class Test (INT I) {2. Void Test (INT i) {3. System.out.println ("I am An Int."); 4.} 5. Void Test (String s) {6. System.Out.println ("I am A string."); 7.} 8. 9. Public static void main (string args []) {10. Test T = New Test (); 11. CHAR CH = "y"; 12. T. That (ch); 13.} 14. overridden. B. Line 12 will not compile, because there is no version of test () that rakes a char argument. C. The code will compile but will throw an exception at line 12. D. The code will compile and produce the following Output: I am AN INT. E. The Code Will Compile and Product The Following Output: I am A String. Answer: D Review: At 12th line, the 16-bit CHAR type variable CH is automatically converted to a compile 32-bit length INT type, and pass it to the Void Test (INT I) method at runtime. Example 4: Which of The Following Lines of Code Will Compile WITHOUT ERROR? A. INT i = 0; if (i) {system.out.println ("hi");} B. Boolean b = true; boolean b2 = true; if (b == b2) {system.out.println "So true");} C. I = 1; int J = 2; if (i == 1 || j == 2) System.out.Println ("OK"); D. I = 1; INT J = 2; if (i == 1 & | j == 2) System.out.Println ("OK"); formula. Logical operations are ^, &, | and &&, ||, but "& |" is illegal, so the option d is incorrect.
Example 5: Which two demonstrate a "has a" relationship (Choose two) A. public interface Person {} public class Employee extends Person {} B. public interface Shape {} public interface Rectandle extends Shape {} C. public interface Colorable? {} public class Shape implements Colorable {} D. public class Species {} public class Animal {private Species species;} E. interface Component {} class Container implements Component {private Component [] children;} answer: D, E reviews: There are two possible ways to reuse in Java, ie combinations ("HAS A" relationship) and inheritance ("IS A" relationship). "HAS A" relationship is implemented by defining the properties of the class; and the "IS A" relationship is achieved by the inheritance. In this example, the options A, B, and C reflect the "IS A" relationship; option D, E reflects "HAS A" relationship. Example 6: Which two statements are true for the class java.util.TreeSet (Choose two) A. The elements in the collection are ordered B. The collection is guaranteed to be immutable C. The elements in the collection are guaranteed?.. To be unique. D. The Elements in The Collection Ared Using a Unique Key. E. The Elements in The Collection AreaTeed To Be Synchronized Answer: A, C Reviews: The Treeset class implements the SET interface. The features of SET are the only elements, and the option C is correct. Since the tree storage is used, the elements are organized in an orderly manner, so the option A is also correct. Example 7: True Or False: Readers Have Methods That Can Read and Return Floats and Doubles. A. Ture B. False Answer: B Reviews: Reader / Writer only processes the input and output of Unicode characters.
FLOAT and DOUBLE can perform I / O through stream. Example 8: What does the folload paint () Method Draw? 1. Public Void Paint (Graphics G) {2. g.drawstring ("Any Question", 10, 0); 3. A. The string "any quest question?", With its Top-Left Corner AT 10, 0 B. A Little Squiggle COMING DOWN From The Top of The Component. Answer: b Review: String Str, Int x, The INT Y method is to display the current color and characters, display the contents of the STR, and the baseline of the leftmost character begins with (x, y). In this question, y = 0, so the baseline is at the top end. We can only see a part of the downlink letter, namely the second half of the letter 'Y', 'q'. Example 9: What happens when you trying application? Cho3 {2. public static void main (string [] args) {3. new z (); 4.} 5. 6. z () {7. z alias1 = this; 8. z alias2 = this; 9. Synchronized (alias) {10. Try {11. Alias2.wait (); 12. System.out.println (" "); 13.} 14. Catch (InterruptedException E) {15. System.out.Println (" Interrr Upted "); 16.} 17. Catch (Exception E) {18. System.out.println (" Other Exception "); 19.} 20. Finally {21. System.out.println (" Finally "); 22.} 23.} 24. System.out.Println (" all done "); 25.} 26. } A. The application compiles but does not print anything. B. The application compiles and print "DONE WAITING" C. The application compiles and print "FINALLY" D. The application compiles and print "ALL DONE" E. The application compiles And Print "Interrupted" Answer: A Comments: In Java, every object is locked. At any time, the lock is mostly controlled by a thread. Since Alias1 points to the same object Z, before executing Chain 11, the thread has the lock of the object z. After performing end 11, the thread releases the lock of the object Z and enter the waiting cell. However, there will be no thread calls the notify () and notifyAll () methods, so the process has been in the waiting state, no output.