J2se exam notes summarize some areas that are easy to ignore

Source: Internet
Author: User

1. Run PROBA 4. What is the result of the following code?

Public class PROBA {<br/> Public static void main (string [] ARGs) {<br/> final int num1 = 0; <br/> final int num2 = integer. parseint (ARGs [0]); <br/> assert num1> num2: "The value must be negative"; <br/> system. out. println ("You specified" + num2); <br/>}< br/>}

 

 

The input result is you specified 4.

 

Reason: assertions is disabled by default.

 

2. Will the following code run?

 

int [] array = new int [Integer.MAX_VALUE + 1];

 

Answer: Yes, but negativearraysizeexception may occur, because the value range of the Java array index is [147,483,647,], while that of integer. max_value + 1 is negative.

 

3. Can a started thread be started again?

 

Answer: No. Start () can only be used once. Otherwise, an illegalthreadstartexception exception will be thrown.

 

4. Test A for execution mechanism. What is the result of the following code input?

 

Public class test {<br/> static Boolean Foo (char c) {<br/> system. out. print (c); <br/> return true; <br/>}< br/> Public static void main (string [] argv) {<br/> int I = 0; <br/> for (FOO ('A'); Foo ('B') & (I <2 ); foo ('C') {<br/> I ++; <br/> Foo ('D '); <br/>}< br/>} 

 

Answer:

 

Abdcbdcb, most of the errors are due to not careful consideration.

 

5. What is the problem with the following code?

 

Class test implements runnable {<br/> int I = 0; <br/> Public int run () {<br/> while (true) {<br/> I ++; <br/> system. out. println ("I =" + I); <br/>}< br/> return 1; <br/>}< br/>} 

 

A: The return type of run should be void ..

 

5. Compare the values. What is the output result of the following code?

 

Public class G6 {<br/> Public static void main (string [] ARGs) {<br/> double D = 0.0, d1 =-0.0; </P> <p> If (D = D1) {<br/> system. out. println (true); <br/>}else {<br/> system. out. println (false); <br/>}</P> <p> If (0.0 =-0.0) {<br/> system. out. println (true); <br/>}else {<br/> system. out. println (false); <br/>}</P> <p> 17 :}< br/> 18 :} 

 

A: True, true

 

6. & bit operations

 

Int A = 128;

Int B = 255;

Int C;

C = A & B

 

What is C?

Answer: 128.

  00000000 00000000 00000000 10000000

  00000000 00000000 00000000 11111111

= 00000000 00000000 00000000 10000000

 

 

7. Nearby matching

 

What is the output result of the following code?

 

Public class test {<br/> Public static void method (Object O) {<br/> system. out. println ("Object:" + O); <br/>}</P> <p> Public static void method (string s) {<br/> system. out. println ("string:" + S); <br/>}</P> <p> Public static void main (string [] ARGs) {<br/> method (null); <br/>}< br/>} 

 

A: The result is string: null.

String is the subclass of the object. It has a priority over NULL for the object. If the method (null) is changed to method (123), the result will be object: 123.

 

8. null

 

Which of the following statements is true?

 

Class

boolean b = null instanceof A

 

A: Yes. null has no class.

 

9 can the following code run normally?

 

Public class test {<br/> Public static void main (string [] ARGs) {<br/> char B = 127; </P> <p> while (false) {<br/> system. out. println (B); <br/>}< br/>} 

 

A: No. Compilation error. system. Out. println (B); cannot be executed.

 

 


 


 


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: info-contact@alibabacloud.com 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.