Analysis of Java 2 programmer test (SCJP) Questions

Source: Internet
Author: User


Whether you are a newbie or an expert in programming, you will be amazed by the Infinite Charm of Sun's Java. Java brings you more than just the advantages of object-oriented, open, platform-independent, easy-to-use, secure, and "Write once, run anywhere" software development. More importantly, it provides a novel way of expressing ideas and a brand new way of thinking. As the scale of the problem to be solved expands, the flexibility of Java's thorough Object-oriented thinking will emerge. Undoubtedly, Java is the most handy tool when you develop large software or the first choice for getting started with IT.

SCJP exam Introduction

● Examination Method

All questions in English are answered by computer and take the test at the authorized Prometric Test Center

Exam ID: 310-025

Prerequisites: None

Exam questions: Check, fill in the blanks, and drag and drop match

Question count: 59

Pass criteria: 61%

Time: 120 minutes

Cost: 1250 RMB

● Required capabilities

● Use the Java programming language to create Java applications and applets.

● Define and describe garbage collection, security, and Java Virtual Machine (JVM ).

● Describes and uses the object-oriented features of Java.

● Develop a graphical user interface (GUI ). Use multiple la s supported by Java.

● Describe and use the Java event processing mode.

● Use a Java mouse to input, text, window, and menu widgets.

● Use Java exception handling to control program execution and define your own exception events.

● Use the advanced object-oriented features of the Java language, including method overloading, method coverage, abstract classes, interfaces, final, static, and access control.

● Implement file input/output (I/O ).

● Use the internal thread mode of Java to control multithreading.

● Use the Sockets mechanism of Java for network communication.

Example 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

Comments: The identifier in Java must start with a letter, dollar sign ($), or underscore. Keywords and reserved words cannot be used as identifiers. Const in Option C is a reserved word of Java, so it cannot be used as an identifier. In option E, 3_case starts with a number and violates 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 values (null, for example ).


Comments: in Java, garbage collection cannot be forced to be executed immediately. Calling the System. gc () or Runtime. gc () static method cannot ensure immediate execution of the garbage collector, because there may be threads with higher priority. So option B and D are incorrect. The error in Option C is that the System. gc () method does not accept parameters. The method in option E allows the object to be collected during the next spam collector operation.

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 .}


9. public static void main (String args []) {

10. Test t = new Test ();

11. char ch = "y ";

12. t. test (ch );

13 .}

14 .}

Which of the statements below is true? (Choose one .)

A. Line 5 will not compile, because void methods cannot be 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 produce the following output: I am a String.

Answer: D

Comments: in row 12th, the 16-bit long char variable ch will be automatically converted into a 32-bit long int type during compilation and passed to void test (int I) at runtime) method.

Example 4:

Which of the following lines of code will compile without error?


Int I = 0;

If (I ){

System. out. println ("Hi ");



Boolean B = true;

Boolean b2 = true;

If (B = b2 ){

System. out. println ("So true ");



Int I = 1;

Int j = 2;

If (I = 1 | j = 2)

System. out. println ("OK ");


Int I = 1;

Int j = 2;

If (I = 1 & | j = 2)

System. out. println ("OK ");

Answer: B, C

Comment: Option A is incorrect because A boolean expression is required after the if statement. Logical operations include ^, &, | and &, |, but "& |" is invalid, So 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

Comments: There are two possible methods for code reuse in Java: combination ("has a" relationship) and inheritance ("is a" relationship ). The "has a" link is implemented by defining class attributes, while the "is a" link is implemented by class inheritance. In this example, options A, B, and C reflect the "is a" relationship; Option D and E reflect the "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 are accessed using a unique key.

E. The elements in the collection are guaranteed to be synchronized

Answer: A, C

Comment: The TreeSet class implements the Set interface. Set is unique among the elements, and option C is correct. Because the tree-like storage method is used to organize elements in sequence, 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

Comment: Reader/Writer only processes the input and output of Unicode characters. Float and double can be used for I/O through stream.

Example 8:

What does the following paint () method draw?

1. public void paint (Graphics g ){

2. g. drawString ("Any question", 10, 0 );

3 .}

A. The string "Any question ?", With its top-left corner at 10, 0

B. A little squiggle coming down from the top of the component.

Answer: B

Comment: the drawString (String str, int x, int y) method uses the current color and character to display the str content, and the baseline of the leftmost character is from (x, y. In this question, y = 0, so the baseline is at the top. We can only see a part of the downstream letters, that is, the lower half of 'y' and 'Q.

Example 9:

What happens when you try to compile and run the following application? Choose all correct options.

1. public class Z {

2. public static void main (String [] args ){

3. new Z ();

4 .}


6. Z (){

7. Z alias1 = this;

8. Z alias2 = this;

9. synchronized (alias1 ){

10. try {

11. alias2.wait ();

12. System. out. println ("done waiting ");

13 .}

14. catch (InterruptedException e ){

15. System. out. println ("INTERR


16 .}

17. catch (Exception e ){

18. System. out. println ("other exception ");

19 .}

20. finally {

21. System. out. println


22 .}

23 .}

24. System. out. println ("all done ");

25 .}

26 .}

A. The application compiles but doesnt 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"


Comment: In Java, every object has a lock. The lock is controlled by one thread at any time. Because alias1 and alias2 point to the same object Z, the thread owns the lock of the Object Z before the execution of row 11th. After 11th rows are executed, the thread releases the lock of the Object Z and enters the waiting pool. However, since then, no thread has called the notify () and notifyAll () Methods of the Object Z, so the process has been in the waiting state and no output.

Example 10:

Which statement or statements are true about the code list

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.