Java Common pen Questions < three >

Source: Internet
Author: User

1, the life cycle of the servlet can be divided into the initial stage, the operation phase and the destruction phase, the following is the initial stage:

A. Load the Servler class and the. CALSS corresponding data

B. Creating ServletRequest and Servletresponse objects

C. Create a ServletConfig object

D. Creating a Servlet Object

Reference Answer: ACD

2, about the comparison between Java and C + +, it is wrong to say:

A, Java does not support pointers, C + + support

B, Java programs do not need to explicitly care about memory release, while C/

C, Java and C + + are purely compiled languages, so their class is statically linked at compile time (static binding).

D, Java Array, string can not overflow, C + + array, string may overflow boundary

Reference Answer: CD

3, the following code, the wrong argument is:

1  Public class Test5 {2      Public int x; 3      Public Static void Main (string[] args) {4         System.out.println ("Value is" +x); 5     }6 }

A, the program prints out "Value is 0"

B, the program will throw NullPointerException

C, non-static variables cannot be referenced by static variables

D, compiler will throw "possible reference before assignment" error

Reference Answer: C

4. The variables A, B, C in the following Java code are stored in which storage area of memory respectively

1  Public classTest {2     PrivateString astring= "AA";3      Public BooleanMethodB () {4String b= "BB";5         FinalString c= "CC";6         return true;7     }8}

A, heap area, heap area, heap area B, heap area, stack area, heap area C, heap area, stack area, stack area

D, heap area, heap area, stack area E, static area, stack area, heap area D, static area, stack area, stack area

Reference Answer: C

Analysis: Heap: All objects are stored, and only one heap in the JVM is shared by all threads, only the object itself

Stack area: Each thread has a stack area that holds references to objects of the base type and custom objects

Static zone: Also called a method area, like a heap, is shared by all threads, which contains the unique elements of the entire program, such as Class

5. The following code snippet is correct:

1 byte b1=1,b2=2, B3,b6; 2 Final byte b4=4,b5=6; 3 b6=b4+b5; 4 b3= (b1+B2); 5 System.out.println (B3+B6);

A, Output results: 13

B, Statement: B6=B4+B5 compilation error

C, Statement: B3=B1+B2 compilation error

D, run-time throws an exception

Reference Answer: C

Analysis: Requires a strong turn, namely: b3= (Byte) (B1+B2), (B1+B2) with the value int type

6. The following are the overloads of the Setvar:

1  Public class Test5 {2      Public void setVar (int A,int b,float  c) {4    }  5 }

A, private void SetVar (int a,float c,int b) {}

B, protected void SetVar (int a,int b,float c) {}

C, public int setVar (int a,float c,int b) {return A;}

D, public int etvar (int a,float c) {return A;}

Reference Answer: ACD

7. The following statements are correct:

1  Public classTEST5 {2      Public Static voidMain (string[] args) {3          floatf=42.0f;4          floatf1[]=New float[2];5          floatf2[]=New float[2];6          float[] f3=F1;7          LongX=42;8f1[0]=42.0f;9     }Ten}

A, F1==F2

B, X==f1[0]

C, F1==F3

D, F2==f1[1]

Reference Answer: BC

8. The following statements are correct:

A. The Java class file that can be successfully run by Java.exe must have the main () method

B, J2SDK is the Java API

C, Appletviewer.exe can run the. jar file with the JAR option

D. The Java class file that can be successfully run by Appleviewer must have the main () method

Reference Answer: BCD

Analysis: J2SDK is a programming tool, Appletviewer.exe is used to explain the execution of Java applet applications, Appletviewer successfully run a Java class file without the main () method

9. The Synchronizer provided by the JDK for concurrent programming is:

A, Semaphore B, Cyclicbarrier C, Coutdownlatch D, Counter

Reference Answer: ABC

10, about the following procedure, the correct statement is:

1  Public classTEST5 {2      Public Static voidMain (string[] args) {3Boolean flag=false;4          if(flag=true){5System.out.println ("true");6}Else{7System.out.println ("false");8          }9     }Ten}

A, the code fails to Complie at the "if" statement.

B, an exception are thrown at Run-time at the "if" statement

C, the text "true" is displayed

D, the text "false" is displayed

Reference Answer: C

Parse: The default value of Boolean is false, and Flag=true is an assignment, that is, if (true)

Java Common pen Questions < three >

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.