Anda di halaman 1dari 44
Exam : 310-081 Title : Sun Certified Web Component Developer for the Java 2 Platform,

Exam : 310-081

Title

: Sun Certified Web Component Developer

for the Java 2 Platform, Enterprise Edition 1.4

Ver

: 10-19-04

310-081

Total Question 108

QUESTION 1 Given:

AnInterface is an interface. AnAdapter0 is a non-abstract, non-final class with a zero argument constructor. An Adapterl is a non-abstract, non-final class without a zero argument constructor, but with a constructor that takes one int argument. Which two construct an anonymous inner class? (Choose two.)

A. AnAdapter1 aa = new AnAdapter1 () {}

B. AnAdapter0 aa = new AnAdapter0 () {}

C. AnAdapter0 aa = new AnAdapter0 (5) {}

D. AnAdapter1 aa = new AnAdapter1 (5) {}

E. AnInterface ai = new Anlnterface (5)) {

Answer: BD

QUESTION 2

1.

class A {

3.

public String to String() {

4.

return "4";

5.

}

6.

}

7.

class B extends A {

8.

public String toString() {

9.

return super.toString() + "3";

10. }

11. }

12. public class Test {

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

14. System.out.printIn(new B());

15. }

16. }

What is the result?

A. Compilation succeeds and 4 is printed.

B.

C. An error on line 9 cause compilation to fail.

D. An error on line 14 cause compilation to fail.

E. Compilation succeeds but an exception is thrown at line 9.

Compilation

is printed.

Answer: B

310-081

QUESTION 3

Given:

1. public class Method Over {

2. public void set Var (int a, int b, float c) {

3. }

4. }

Which two overload the set Var method? (Choose two.)

A. private void set Var(int a, float c, int b) {}

B. protected void set Var(int a, int b, float c) {}

C. public int set Var(int a, float c, int b) {return a:}

D. public int set Var(int a, int b, float c) {return a:}

E. protected float set Var(int a, int b, float c) {return c:}

Answer: AC

QUESTION 4

1.

class A {

2.

public byte file Number () {

3.

return l;

4.

}

5.

}

6.

7.

Class B extends A {

8.

public short getNumber() {

9.

return 2;

10.

}

11.

12.

public short getNumber() {

13.

B b = new B();

14.

System.out.printIn(b.getNumber());

15.

}

16.

}

What is the result?

A. Compilation succeeds and l is printed.

B. Compilation succeeds and 2 printed.

C. An error at line 8 cause compilation to fail.

D. An error at line 14 cause complication to fail.

E. Complication succeeds but an exception is thrown at line 14.

Answer: C

QUESTION 5

Given:

1. public class Foo {

Actualtests.com - The Power of Knowing

310-081

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

3. StringBuffer a = new StringBuffer("A");

4. StrinbBuffer b = new StringBuffer("B");

5. operate (a, b);

6. System.out.printIn(a + "," + b):

7. }

8. static void operate (StringBuffer x, StringBuffer y) {

9. y.append(x);

10. y = x;

11. }

12. }

What is the result?

A. The code compiles and prints "A,B".

B. The code compiles and prints "A,BA".

C. The code compiles and prints "AB,B".

D. The code compiles and prints "AB,AB".

E. The code compiles and prints "BA,BA".

F. The code does not compile because "+" cannot be overloaded for StringBuffer.

Answer: B

QUESTION 6

1.

public class X {

2.

private static int a:

3.

4.

public static void main (String [] args) {

5.

modify (a) :

6.

System.out.printIn(a) {

7.

}

8.

9.

public static void modify (int a) {

10. a++;

11. }

12. }

What is the result?

A. The program runs and prints "0"

B. The program runs and prints "1"

C. The program runs but aborts with an exception.

D. An error "possible undefined variable" at line 5 cause compilation to fail.

E. An error "possible undefined variable" at line 10 cause compilation to fail.

Answer: A

310-081

QUESTION 7

1.

public class Test {

2.

private static int j = 0;

3.

4.

public static Boolean method B (int k) {

5.

j + = k;

6.

return true:

7.

}

8.

9.

public static void method A (int i) {

10.

Boolean b;

11.

b = I < 10 | method b (4):

12.

b = I < 10 || methodb(8):

13.

}

14.

15.

public static void main (String args []) {

16.

method A (0);

17.

System.out.printIn(i);

18.

}

19.

}

What is the result?

A. The program prints "0".

B. The program prints "4".

C. The program prints "8".

D. The program prints "12".

E. The code does not compile.

Answer: B

QUESTION 8 Which two are equivalent? (Choose two.)

A. 16 > 4

B. 16 / 2

C. 16 * 4

D. 16 >> 2

E. 16 / 22

F. 16 >>> 2

Answer: DF

QUESTION 9

Given:

1. public class X {

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

Actualtests.com - The Power of Knowing

3. byte b = 1277;

4. byte c = 126;

5. byte d = b + C;

6. }

7. }

Which statement is true?

310-081

A. Compilation succeed and d take the value 253.

B. Line 5 contains an error that prevents compilation.

C. Line 5 throws an exception indicating "out of range"

D. Line 3 and 4 contain errors that prevent compilation.

E. The compilation succeed and d takes the value of 1.

Answer: B

QUESTION 10

Given:

8. int index = 1;

9. int[]foo = new int [3];

10. int bar = foo [index];

11. int baz = bar + index;

What is the result?

A. baz has a value of 0.

B. baz has a value of 1.

C. baz has the value of 2.

D. An exception is thrown.

E. The code will not compile.

Answer: B

QUESTION 11

Given:

1.

public class Test {

2.

public static void main (String [] args) {

3.

unsigned byte b = 0;

4.

b--:

5.

6.

}

7.

}

What is the value of b bat line 5?

A. -1

B. 225

C. 127

D. Compilation will fail.

E. Compilation will succeed but the program will throw an exception at line 4.

Actualtests.com - The Power of Knowing

310-081

Answer: D

QUESTION 12

Given

1. public class Test {

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

3. String foo = args [0];

4. String bar = args [1];

5. String baz = args [2];

6. }

7. }

And command line is vacation:

Java Test red green blue

What is the Result?

A. baz has the value of "".

B. baz has the value of null.

C. baz has the value of "red"

D. baz has the value of "blue"

E. baz has the value of "green"

F. The code does not compile.

G. the program throws an exception.

Answer: D

QUESTION 13

Given:

1. //Point X

2. public class Foo {

3. public static void main (String [] args) throws Exception {

4. Print Writer out = new Print Writer (new

5. java.io.Output Stream Writer (System.out), true);

6. out.printIn ("Hello")

7. }

8. }

Which statement at Point X on line 1 allows this code to compile and run?

A. import java.io.PrintWtier;

B. include java.io.PrintWRiter;

C. import java.io.OutputStream Writer;

D. include java.io.OutputStream Writer;

E. No statement is needed.

Answer: A

Actualtests.com - The Power of Knowing

310-081

QUESTION 14 Which two method declarations are valid for an interface.? (Choose two)

A. Public double methoda():

B. static void methoda(double d1)

C. public final double methoda ();

D. abstract public void methoda ();

E. protected void methoda(double d1);

Answer: AD

QUESTION 15

1.

package foo;

2.

3.

import java.util.Vector

4.

5.

private class My Vector extends Vector {

6.

Int i = 1'

7.

public MyVector () {

8.

i = 2;

9.

}

10.

}

11.

12.

public class My New Vector extends my Vector {

13.

public MyNew Vector () {

14.

i = 4;

15.

}

16.

public static void main (String args []) {

17.

MyVector v = new My New Vector ();

18.

}

19.

}

What is the result?

A. Compilation will succeed.

B. Compilation will fail at line 5.

C. Compilation will fail at line 6.

D. Compilation will fail at line 14.

E. Compilation will fail at line 176.

Answer: B

QUESTION 16 Which four types of object can be thrown using the throw statement? (Choose four.)

A. Error

Actualtests.com - The Power of Knowing

B. Event

C. Object

D. Exception

E. Throwable

F. Runtime Exception

310-081

Answer: ADEF

QUESTION 17

Given:

1. public class Foo {

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

3. try { System.exit (0); }

4. finally { System.out.printIn("Finally"):}

5. }

6. }

What is the result?

A. the program runs and prints nothing.

B. The program runs and prints "Finally".

C. The code compiles. But an exception is thrown at runtime.

D. the code will not compile because the catch block is missing.

Answer: A

QUESTION 18

Given:

1. Public class While Foo}

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

3. int x = I, y = 6

4. while ( y--) {x++:}

5. System, out. printIn ("x = " + x + " y = " + y):

6. {

7. {

What is the result?

A. The output is X = 6 y = 0

B. The output is x = 7 y = 0

C. The output is x = 6 y = -1

D. The output is x = 7 y = -1

E. Compilation will fail.

Answer: E

310-081

6. <my Tag:foo bai = 42>

7. <%=" processing"%>

8. </my Tag.foo>

And a custom tag handler for foo which extends Tag Support. Which two are true about the tag handler referneed by my Tag. (Choose two.)

A. The do Start Tag method is called once.

B. The do After Body method is NOT called.

C. The EVAL_Page constant is a valid return value for the do End Tag Method.

D. the EVAL_BODY_BUFFERED constant is a valid return value for the do Start Tag

method.

Answer: AC

QUESTION 20

Given

11. Public void services (Servlet Request request,

12. Servlet Response response)

13. throws 10 Exccption {

14. Servlet Context cxt = get Servlet Config ().get Servlet Context ():

15. Input Stream in =

16. insert code here

17. {

Which statement. At line 16, retrieves an Input Stream for the file / WEBINF/

myresrc.bin?

A. ctx.get put Stream ("/WEB-INF/myresrc.bin"):

B. ctx.get Input Stream ("/WEB-INF/myresrc.bin"):

C. ctx.get Resource As Stream ("/WEB-INF/myresrc.bin"):

D. new Input Stream (new Url ("/WEB-INF/myresrc.bin"):

E. Get Class (). Get Resource As Stream ("/WEB-INF/myresrc.bin"):

Answer: C

QUESTION 21 Given an HttpServlet Request request and Http Servlet Response response, which sets a cookie "username" with the value "joe" in a servlet.?

A. request.add Cookie ("username". "joe")

B. request.set Cookie ("username, "joe")

C. response.add Cookie (username", "joe"))

D. request.add Header (new Cookie ("username", "joe"))

E. request.add Cookie (new Cookie ("username", "joe"))

F. response.add Cookie (new Cookie ("username", "joe"))

G. response.add Header (new Cookie ("username", "joe"))

Actualtests.com - The Power of Knowing

310-081

Answer: F

QUESTION 22

Given:

10. public void service Servlet Request request.

11. Servlet Response response) {

12. ServletInput Stream sis=

13. //insert code here

14. }

Which retrieves the binary input stream on line 13?

A. request.get Writer ():

B. request.get Reader ():

C. request.get Input Stream():

D. request.get Resource As Stream():

E. request.get Resource As Stream (Servlet Request. REQUEST):

Answer: C

QUESTION 23

index.html:

16. <from method = "GET" action = "MyServlet">

17. <input type= "text" name+ "foo">

18. <input type= "text" name = "foo">

19. <input type = "submit">

20. </from>

MyServlet.java:

6. public void doGet (Http ServletRequest request.

7. HttpServletREsponseresponse_

8. throws IOException. ServletExecption {

9. String first = request.getParameter )"foo");

10. String second:

11. // your code here

12 } Which statement inserted at line II, retrieves the text from the second text field?

A. second = request.getParameter ("foo"):

B. second = request.getParameter ("foo", 1):

C. second = request.getParameter ("foo",2):

D. second = request.getParameter (foo") [1]:

E. second = request.getParameter Values ("foo") [1]:

Answer: E

310-081

QUESTION 24 Which HTTP method represents a request for information about the supported methods on an HTTP server?

A. GET

B. INFO

C. HEAD

D. TRACE

E. OPTIONS

Answer: E

QUESTION 25

Given the definition of MyObject and that an instance of MyObject is bound as a session attribute:

8. package com.example:

9. public class MyObject implements

10. javax-servlet.http.HttpSessionBindingListner{ 11.// class body code here

12.}

Which is true?

A. Only single instance of MyObject may exist within a session.

B. The unbound method of the MyObject instance is called when the session to which it

is bound times out.

C. The com.example.MyObjectmust be declared as a servlet event listener in the web

application deployment descriptor.

D. The value Unbound method of the MyObject instance is called when the session to

which it is bound times out.

Answer:

QUESTION 26 Under what two circumstances is the set JspBody method NOT called in a tag class that implements the Simple Tag interface? (Choose two)

A. The tag is invoked without a body.

B. The doTAb method throws an exception.

C. The <body-content> element has the value empty.

D. The tag is called with the attribute skip-body=true

Answer: AC

QUESTION 27 Which two statements are true? (Choose two.)

Actualtests.com - The Power of Knowing

310-081

A. An inner class may be declared as static.

B. An anonymous inner class can be declared as public.

C. An anonymous inner class can be declared as private.

D. An anonymous inner class can extend an abstract class.

E. An anonymous inner class can be declared as protected.

Answer: AD

QUESTION 28 Which statements about static inner classes is true?

A. An anonymous class can be declared as static.

B. A static inner class cannot be a static member of the outer class.

C. A static inner class does not require an instance of the enclosing class.

D. Instance member of a static inner class can be referenced using the class name of the

static inner class.

Answer: C

QUESTION 29

Given:

1. public class MethodOver {

2. private int x,y:

3. private float z:

4. public vod set var (int a, int b, float c) {

5. x = a;

6. y = b;

7. z = c;

8. }

9. }

Which two overload the setVar method? (Choose two.)

A. void set Var Iint a, int b, float c) {

x

= a:

y

= b:

z

= c:

}

B.

public void setVar(int a, float c, int b) {

SetVar (a, b, c);

}

C.

public void setVarIint a, float c, int b){

this(a, b, c);

}

C.

public void setVar(int a, float c, int b) {

This (a, b, c);

}

Actualtests.com - The Power of Knowing

310-081

D.

public void setVarIint a, float b) {

X

= a:

Y

= b:

}

E.

public void setVar(int as, int by, float cz) {

x

= ax;

y

= by:

z

= cz:

}

Answer: BD

QUESTION 30 Which two demonstrate an "is a" relationship? (Choose two.)

A. public interface Person {}

Public class Employee extends Person {}

B. public interface Shape {}

public interface Rectangle extends Shape {}

C. public interface Color {}

public class Shape { private Color color; }

D. public class Species {}

public class Animal { private Species species; }

E. interface Component {}

Class Container implements Component { private Component [] children;

Answer: BE

QUESTION 31

Given:

1. public class Test {

2. public static void leftShift(in i int j) {

3. i <<=j;

4. }

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

6. int I = 4, j =2;

7. leftShift (i.j);

8. System.out.printIn(i);

9. }

10. } What is the result?

A. 2

B. 4

C. 8

Actualtests.com - The Power of Knowing

310-081

D. 16

E. The code will not compile.

Answer: B

QUESTION 32

1.

public class X {

2.

public static void main (String [] args) {

3.

int [] a = new int [l]:

4.

modify (a):

5.

System.out.printIn(a[0]):

6.

}

7.

8.

public static void modify (int [] a) {

9.

a [0] ++;

10. }

11. }

What is the result?

A. The program runs and prints "0"

B. The program runs and prints "1"

C. The program runs but aborts with an exception.

D. An error "possible undefined variable" at line 4 causes compilation to fail.

E. An error "possible undefined variable" at line 9 cause compilation to fail.

Answer: B

QUESTION 33

1. public class X {

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

3. String sl = new String ("true");

4. Boolean bl - new Boolean (true);

5. if (sl.cquals(bl)) {

6. System.out.printIn ("Equal"):

7. }

8. }

9. }

What is the result?

A. the program runs and prints nothing.

B. The program runs and prints "Equal".

C. An error at line 5 cause compilation to fail.

D. The program runs but aborts with an exception.

Answer: A

310-081

QUESTION 34

Given:

1. public class Test {

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

3. Sytstem.out.printIn (6 3) :

4. }

5. }

What the output?

Answer: 5

QUESTION 35

Given:

8. String foo = "blue";

9. boolcan [] bar = new Boolean [1];

10. if (bar [0] {

11. foo = "green";

12. }

What is the result?

A. foo has the value of ""

B. foo hast he falue of null.

C. foo has the value of "blue"

D. foo has the value of "green"

E. An exception is thrown.

F. The code will not compile.

Answer: C

QUESTION 36 Which two are reserved words in Java? (Choose two.)

A. run

B. import

C. default

D. implement

Answer: BC

QUESTION 37

Given

1. public class Foo{

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

3. Strings;

4. System.outprintIn ("S="+s):

5. }

Actualtests.com - The Power of Knowing

6. }

What is the result?

310-081

A. The code compiles and "s=" is printed.

B. The code compiles and "s=" + s);

C. The code does not compile because Strings is not initialized.

D. The code does not compile because Strings cannot be referneed.

E. The code comiles, but a NullPointer Exception is thrown when toString is called.

Answer: C

QUESTION 38 Which will declare a method that forces a subclass to implement it?

A. public double methoda ():

B. static void methoda(double d1) {}

C. public native double methoda ():

D. abstract public foid methoda ():

E. protected void methoda (double d1) {}

Answer: D

QUESTION 39

Given:

1. public class Foo {

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

3. System.out.printIn ("Hello world.");

4. }

5. }

What is the result?

A. An exception is thrown.

B. The code does not compile.

C. "Hello worlds." Is printed to the terminal.

D. The program exits without printing anything.

Answer: A

QUESTION 40

Given

1. public class Exception Test {

2. class Test Exception extends Exception {}

3. public void runs Test () throws Test Exception {}

4. public void test () /* Point X*/{

5. run Test ();

6. }

Actualtests.com - The Power of Knowing

310-081

7. }

At Point X on line 4, which code can be added to make the code compile?

A. throws Exception

B. catch (Exception e)

C. throws Runtime Exception

D. catch (Test Exception e)

E. No code is necessary.

Answer: A

QUESTION 41

Given

1. public class for Bar {

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

3. int i = 0 and j = 5

4. tp: for (;;) {

5. i ++;

6. for (;;)

7. if (i > -- j) break tp:

8. }

9. System.out.printIn ("i= " + " j = " + j):

10. {

11. {

What is the result?

A. The program runs and prints " I = 1 , j = 0"

B. The program runs and prints " I = 1 , j = 4"

C. The program runs and prints " I = 3 , j = 4"

D. The program runs and prints " I = 3 , j = 0"

E. An error at line 4 cause compilation to fail.

F. An error at line 7 cause compilation to fail.

Answer: A

QUESTION 42 Given the Tag:

<my Tag.get Advice type ="fashion"/> Assuming the tag referenced by my Tags: get Advice uses the Classic event model, which is true?

A. The do After Body method is called.

B. The doEnd Tag method is NOT called.

C. The type attribute may be specified in the TLD

D. The do Start Tag Method must always return SKIP_BODY.

E. The TLD for this tag must NOT include a <body.content> tag.

Actualtests.com - The Power of Knowing

310-081

Answer: C

QUESTION 43 Which two prevent a servlet from handling requests.? (Choose two.)

A. The servlet's init method returns a non-zero status.

B. The servlet's init method throws a Servlet Exception

C. The servlet's init method sets the Servlet Response's context length to 0

D. The servlet's init method sets the Servlet Response's content type to null.

E. The servlet's init method does NOT return within a time period defined by the servlet

container.

Answer: BE

QUESTION 44 For an HttpServlet Response response, which two create a custom header? (Choose two)

A. response.set Header ("X-MyHeader". "34"):

B. response.addHeader ("X-MyHeader". "34"):

C. response. Set Header (new Http Header ("X-MyHeader". "34")):

D. response.addHeader(new Http Header ("X-MyHeader". "34")):

E. response. addHeader (new Servlet Header ("X-MyHeader". "34")):

F. response. setHeader (new Servlet Header ("X-MyHeader", "34")):

Answer: AB

QUESTION 45 Which two HTTP methods are used to process from data in a servlet? (Choose two.)

A. doGET

B. doPut

C. doPost

D. doTrace

E. doSubmit

F. doProcess

Answer: AC

QUESTION 46 A developer wants too use EL to invoke a function using S{my:bloof("foof")}. Which is always true?

A. The method invoked by this function must be statie.

B. The function class must implement the Function interface.

Actualtests.com - The Power of Knowing

310-081

C. The expression is NOT a valid EL expression for invoking a function.

D. The function must be declared in a web.xml file using the <function> element.

E. The function class must have a method with the signature:

Void bloof (java.lang.Strings)

Answer A

QUESTION 47 Which two are characteristics of the Intercepting Filter pattern? (Choose two)

A. it provides centralized request handling for incoming requests.

B. It forces resource authentication to be distributed across web components.

C. It reduces coupling between presentation-tier clients and underlying business services.

D. It can be added and removed unobtrusively, without requiring changes to existing

code.

E. It allows preprocessing and postprocessing on the incoming requests and outgoing

responses.

Answer: DE

QUESTION 48

1. class EnclosingOne {

2. public class InsideOne {}

3. }

4. public class InnerTest{

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

6. EnclosingOne eo = new EnclosingOne():

7. //insert code here

8. }

9. }

Which statement at line 7 constructs an instance of the inner class?

A. InsideOne ei = eo.new InsideOne():

B. eo.InsideOne ei= co.new InsideOne():

C. InsideOne ei = EnclosingOne.new InsideOne():

D. EnclosingOne.insideOne ei = eo.new InsideOne():

Answer: D

QUESTION 49

Given:

1. class Base Class {

2. private float x = 1.0f;

3. protected void set Var(float f) { x = f;}

4. }

5. class SubClass extends BaseClass{

6. private float x = 2.0f

Actualtests.com - The Power of Knowing

310-081

7. //insert code here

8. }

Which two are void examples of method overriding? (Choose two.)

A. void setVar(float f) { x = f;}

B. public void setVar(int f) { x =f;}

C. public void setVar(float f) {return f;}

D. public double setVar(float f) {return f;}

E. protected float setVar() { x = 3.0f; return 3.0f; }

Answer: CE

QUESTION 50

1.

Class A {

2.

public int getNumber(int a) {

3.

return a + l:

4.

}

5.

}

6.

7.

class B extends A {

8.

public int getNumber(int a) {

9.

return a + 2:

10.

}

11.

12.

public static void main (String args[] {

13.

A a = new B();

14.

Systemout.printIn(a.getNumber(0));

15.

}

16.

}

What is the result?

A. Compilation succeeds and 1 is printed.

B. complication succeeds and 2 is printed.

C. An error at line 8 causes compilation to fail.

D. An error at line 13 causes complication to fail.

E. An error at line 14 causes compilation to fail.

Answer: B

QUESTION 51

1.

public class Test {

2.

public static void string Replace(String text) {

3.

text = text.replace ("J". "I");

4.

}

5.

6.

public static void buffer Replace (String Buffer text) {

Actualtests.com - The Power of Knowing

310-081

7.

text = text.append ("c")

8.

}

9.

10.

public static void main (String args []) {

11.

String textString = new String ("java");

12.

String Buffer textBuffer = new String Buffer ("java");

13.

14.stringReplace (textString):

15.

buffer Replace (textBuffer):

16.

17.

System.out.printIn(TextString + textBuffer);

18.

}

19.

}

What is the output?

Answer: ajvajavac

QUESTION 52

Given:

1. public class Foo {

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

3. int i = l:

4. int j = i++;

5. if ((i = = ++j) | (i++==j)) {

6. i + = j;

7. }

8. }

9. }

What is the final value of i?

A. 1

B. 2

C. 3

D. 4

E. 5

Answer: E

QUESTION 53

Given:

1.

public class Test {

2.

public static void main (String args[]) {

3.

int i + 0 x FFFFFFF1:

4.

int j = i;

5.

6.

}

Actualtests.com - The Power of Knowing

310-081

7. }

What is the decimal value of J at line 5?

A. 0

B. 1

C. 14

D. –15

E. An error at line 3 cause compilation to fail.

F. An error at line 4 cause compilation to fail.

Answer: C

QUESTION 54

Given:

8. int index = 1:

9. Boolean [] test = new boolcan [3];

10. boolcan foo = test [index];

What is the result?

A. foo has the value of 0.

B. foo has the value of null.

C. foo has the value of true.

D. foo has the value of false.

E. An-exception is thrown.

F. The code will not compile.

Answer: D

QUESTION 55

Given;

1. public class Test

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

3. String foo = args [1]:

4. String bar = args [2]:

5. String bar = args [3]:

6. }

7. }

And command line is vacation:

Java Test red green blue

A. bas has the value of "".

B. baz has the value of null.

C. bas has the value of "red".

D. baz has he value of "blue".

E. baz has the value of "green".

F. the code does not compile.

Actualtests.com - The Power of Knowing

310-081

G. The program throws and exception.

Answer: G

QUESTION 56 Which three are valid URL mappings to a servlet in a web deployment descriptor? (Choose three.)

A. */*

B. /*.do

C. myServlet

D. /Myservlet

E. /MyServlet/*

F. MyServlet/*.isp

Answer: BDE

QUESTION 57

Given:

1. public class X {

2. public Object m () {

3. Object o = new Float ( 3.14 F);

4. Object [] oa = new Object [1]:

5. oa [0] = o;

6. o = null:

7. oa [0] = null;

8. return o:

9. }

10. } When is the Float object. Created in line 3, eligible for garbage collection?

A. just after line 5

B. just after line 6

C. just after line 7

D. just after line 8 (that is . as the method returns)

Answer: C

QUESTION 58

1.

public class Test {

2.

public static String output = "";

3.

4.

public static void foo (int i ) {

5.

try {

6.

if ( i = = 1) {

7.

throw new Exception ():

Actualtests.com - The Power of Knowing

310-081

8. }

9. output + = "1";

10.

}

11.

catch (Exception e) {

12.

output + = "2";

13.

return;

14.

}

15.

finally {

16.

out put + = "3";

17.

{

18.

output + = "4";

19.

}

20.

21.

public statie void main (String args [] {

22.

foo (0);

23.

foo (1);

24.

25.

}

26.

}

What is the value of the variable output at line 24?

Answer: 13423

QUESTION 59

5. public class My Tag Handler extends Tag Support {

6. publin int do Start Tag () throws Jsp Exception {

7. try{

8. Writer out = page Context.get Response ().get Writer ();

9. String name = page Context. Find Attribute ("name");

10.

out.print (name);

11.

} catch (Exception ex) {/* handle exception */}

12.

return SKIP_BODY:

13.

}

14.

15.

PUBLIC INT DO after Body () throws Jsp Exception {

16.

try {

17.

Writer out =page Context.get Response ().get Writer ():

18.

out.print ("done"):

19.

catch (Exception ex) " /* handle exception */}

21.

}

42.

}

The attribute "name" has a value of "Foo," What is the result if this tag handler's tag is invoked?

A. Foo

B. done

Actualtests.com - The Power of Knowing

310-081

C. Foodone

D. An exception is thrown at runtime.

E. Compilation fails because of an error in this code.

Answer: A

QUESTION 60 For a given Servlet Response response, which two retrieve an object for writing text data? (Choose two)

A. response.get Writer ()

B. response.get Output Stream ()

C. response.get Output Writer ()

D. response.get Writer ().get Output Stream()

E. response.get Writer (Writer.OUTPUT_TEXT)

Answer: AB

QUESTION 61 Which retrieves all cookies sent in a given HttpSErvletRequest request?

A. request.getCookies()

B. request.getAttributes()

C. request.getSession ().getCookies()

D. request.getSession (). GetAttributes()

Answer:

QUESTION 62 Which two are valid values for the <transport-guarantee> element inside a <security-constraint> element of a web application deployment descriptor? (Choose two.)

A. NULL

B. SECURE

C. INTEGRAL

D. ENCRYPTED

E. CONFIDENTIAL

Answer:

QUESTION 63 Which two statements are true? (Choose two.)

A. An anonymous inner class can be declared inside of a method.

B. An anonymous inner class constructor can take arguments in some situations.

Actualtests.com - The Power of Knowing

310-081

C. An anonymous inner class that is a direct subclass of Object can implement multiple

interfaces.

D. Even if a class Super does not implement any interfaces, it is still possible to define an

anonymous inner class that is an immediate subclass of Super that implements a single

interface.

E. Even if a class Super does not implement any interfaces, it is still possible to define an

anonymous inner class that is an immediate subclass of Super that implements multiple

interfaces.

Answer: AB

QUESTION 64

Given:

1. public class ConstOver {

2. public constOver(int x, int y, int z) {

3. }

4. }

Which two overload the ConstOver Constructor? (Choose two.)

A. ConstOver() {}

B. protected int ConstOver(){}

C. private ConstOver(int z, int y, byte x ) {}

D. public Object ConstOver(Int x, int y, int z) {}

E. pubic void ConstOver (byte x, byte y, byte z) {}

Answer: AC

QUESTION 65

Given:

1. public class Foo {

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

3. String Buffer a = new StringBuffer ("A");

4. String Buffer b - new StringBuffer ("B");

5. operate (a, b);

6. System.out.printIn(a+ "," + b);

7. }

8. Static void operate(StringBuffer x. String Buffer y) {

9. X.append(y);

10. y = x;

11. }

12. }

What is the result?

A. The code compiles and prints "A,B".

B. The code compiles and prints "A,A".

C. The code compiles and prints "B,B".

Actualtests.com - The Power of Knowing

310-081

D. The code compiles and prints "AB,B".

E. The code compiles and prints "AB,AB".

F. The code does not compile because "+" cannot be over loaded for StringBuffer.

Answer: D

QUESTION 66 Given:

Integer i = new Integer (42); Long l = new Long (42); Double d = new Double (42.0); Which two expression evaluate to true? (Choose two.)

A. (i = = l)

B. (i = = d)

C. (d = = l)

D. (i.equals(d))

E. (i.equals(i))

F. (i.equals(42))

Answer: DE

QUESTION 67 What is the numerical range of char?

A.

B. 0 65535

C. –256…255

D.

E. Range is platform dependent.

0

32767

32768

32767

Answer: B

QUESTION 68

Given:

1. public class Test {

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

3. String foo = args [1];

4. String bar = args [2];

5. String baz = args [3];

6. System.out.printIn("baz="+baz):

7. }

8. }

and the output:

baz = 2 Which command line invocation will produce the output?

Actualtests.com - The Power of Knowing

A. java Test 2222

B. java Test 1234

C. java Test 4242

D. java Test 4321

310-081

Answer: C

QUESTION 69

Given:

1. public interface Foo {

2. int k = 4:

3. }

Which three are equivalent to line 2? (Choose three)

A. final int k = 4:

B. public int k = 4:

C. static int k = 4:

D. private int k = 4:

E. abstract int k = 4:

F. volatile int k = 4:

G. transient int k = 4:

H. protected int k = 4:

Answer: ABC

QUESTION 70

Given

1. public class Foo {

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

3. try { return;}

4. finally { Syste.out.printIn ("Finally");}

5.}

6.}

What is the result?

A. The program runs and prints nothing.

B. The program runs and prints "Finally".

C. The code comiles. But an exception is thrown at runtime.

D. The code will not compile because the catch block is missing.

Answer: B

QUESTION 71

11. public class Iterate Handler extends Body Tag Support {

12. private Collection c:

Actualtests.com - The Power of Knowing

310-081

13. private Iteator it:

14. public void set Coll (Collection c) {this.c + c;}

15. public int do Start Tag () throws Jsp Exception {

16. // insert code here

17. }

18. public void dolnit Body () throws Jsp Exception {

19. it = c. iterator ():

20. page Context.set Attribute ("item" it.next());

21. }

22. public int do After Body () throuws Jsp Exception {

23. if (it. Has Next ()){

24. page Context.set Attribute ("item", it.next ());

25. // insert code here

26. } else {

27. try {

28. get Body Content (). Write Out (get Previous Out ());

29. } catch (Exception e) {}

30. // insert code here

31. }

32. }

33. }

Given that the loop tag properly iterates over Collection assigned to its cool

attribute.

<mx: loop coll = <% = a Collection %> > <jsp: use Bean id= "item" scope =" page class = "java. Lang. String"/> </mx:loop> Which additions needs to be made to the Iterate Handler class for it to properly perform as the tag handler for the loop tag.?

A. Insert return c. is Empty () ? EVAL_BODY_AGAIN:SKIP_BODY: at line 16

Insert return EVAL_BODY_AGAIN: at line 25. Insert return SKIP_BODY: At line 30.

B. Insert return c. is Empty ()? SKIP_BODY: EVAL_BODY_AGAIN: at line 16

Insert return SKIP_BODY: at line 25. Insert return EVAL_BODY_AGAIN: at line 30

C. Insert return c. is Empty () ? EVAL_BODY_AGAIN : SKIP BODY: at line 16

Insert return EVAL_BODY_AGAIN: at line 25. Insert return SKIP_BODY: at line 30.

D. Insert return c. is Empty ()? EVAL_BODY_AGAIN:SKIP_BODY: at line 16

Insert return SKIP_BODY: at line 25. Insert return EVAL_BODY_AGAIN: at line 30

Answer: C

310-081

data? (Choose two)

A. response.get writer ()

B. response.get Output Stream ()

C. response.getOutput Writer()

D. response.get Writer ().get Output Stream ()

E. response.get Writer (Writer.OUTPUT_BINARY)

Answer: B

QUESTION 73 Which HTTP method has the characteristic that multiple indential requests may produce side effect beyond those of a single request?

A. PUT

B. GET

C. INFO

D. POST

E. HEAD

F. TRACE

Answer: D

QUESTION 74 Which three are valid URL mappings to a servlet in a web deployment descriptor? (Choose three.)

A. */*

B. /*.do

C. myServlet

D. /Myservlet

E. /MyServlet/*

F. MyServlet/*.isp

Answer: BDE

QUESTION 75

Given:

1.

package foo;

2.

3.

public class Outer {

4.

public static class Inner {

5.

}

6.

}

Which statement is true?

Actualtests.com - The Power of Knowing

310-081

A. An instance of the Inner class can be constructed with "new Outer.Inner()".

B. An instance of the Inner class can only be constructed from within the Outer class.

C. An instance of the Inner class can only be constructed from within the Outer class.

D. From with in the package bar, an instance of the Inner class can be constructed with

"new Inner()".

Answer: A

QUESTION 76

1.

class A {

2.

public int getNumber(int a) {

3.

return a + l;

4.

}

5.

}

6.

7.

class B extends A {

8.

public int getNumber(int a, char c) {

9.

return a + 2;

10.

}

11.

12.

public static void main (String args[]) {

13.

B b = new B();

14.

System.out.print(b.getNumber(0));

15.

}

16.

}

What is the result?

A. Compilation succeeds and 1 is printed.

B. Compilation succeeds and 2 is printed.

C. An error at line 8 causes compilation to fail.

D. An error at line 14 causes compilation to fail.

Answer: A

QUESTION 77

1.

public class Test {

2.

public static void replace J(String text) {

3.

text.replace("J" - "I");

4.

}

5.

6.

public static void main (String args []) {

7.

String text = new String ("java");

8.

replace J (text);

9.

System.out.printIn(text);

10. }

11. }

Actualtests.com - The Power of Knowing

What is the result?

310-081

A. The program prints "lava".

B. The program prints "java".

C. An error at line 7 causes compilation to fail.

D. Complication succeeds but the program throws an exception.

Answer: B

QUESTION 78

Given:

1. public class Foo {

2. private int val:

3. public Foo (int v) { val = v:}

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

5. Foo a = new Foo (10):

6. Foo b = new Foo (10):

7. Foo c = a:

8. int d = 10;

9. double e = 10.0:

10. }

11. }

Which three logical expressions evaluate to true? (Choose three.)

A. (a = = c)

B. (d = = c)

C. (b = = d)

D. (a = = b)

E. (b = = c)

F. (d == 10.0)

Answer: ABF

QUESTION 79 Which two are valid declarations of char? (Choose two.)

A. Char ch = "a";

B. char ch = "";

C. char ch = "café";

D. char ch = "ucafe";

E. char ch = "ucafe';

F. char ch = "u10100';

G. char ch = (char) true;

Answer: BE

QUESTION 80

Given:

1. Public class Foo {

310-081

2. static Strings;

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

4. System.out.printIn ( "s=" + s):

5. }

6. }

What is the result?

A. The code compiles and "s=" is printed.

B. The code compiles and "s=null" is printed.

C. The code does not compile because Strings is not initialized.

D. The code does not compile because because Strings cannot be referneed.

E. The code comiles.butt a NullPointerException is thrown when toString is called.

Answer: B

QUESTION 81

1.

package foo;

2.

3.

import java. Util. Vector;

4.

5.

protected class my Vector extends Vector {

6.

int i = 1;

7.

public MyVector () {

8.

i = 2;

9.

}

10.

}

11.

12.

public class MyNewVector extends MyVector {

13.

public MyNew Vector () {

14.

I = 4;

15.

}

16.

public static void main (String args []) {

17.

MyVector v = new MyNewVector ():

18.

}

19.

}

What is the result?

A. Compilation will succeed.

B. Compilation will fail at line 5.

C. Compilation will fail at line 6.

D. Compilation will fail at line 14.

E. Compilation will fail at line 17.

Actualtests.com - The Power of Knowing

310-081

Answer: B

QUESTION 82

1. import java. Io. IO Exception:

2. public class Exception Test {

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

4. try {

5. method A ()

6. catch (IOException e) {

7. System.out.printIn ("Caught IO Exception")

8. catch (exception e) {

9. System. Out. printIn ("Caught Exception");

10. }

11. }

12. public void method A () {

13. throw new IO Exception () ;

14. }

15. }

What is the result?

A. The code will not compile.

B. The output is Caught Exception

C. The output is Caught IO Exception

D. The program executes normally without printing a message.

Answer: A

QUESTION 83 Which statement is true if the do Start Tag method returns EVAL_BODY_BUFFERED?

A. The tag handler must extend body Tag.

B. The do After Body method is NOT called.

C. The set Body Content method is called.

D. It is never legal to return EVAL_BODY_BUFFERED from do Start Tag.

Answer: C

QUESTION 84 A collection of products is stored in the Servle Context in an attribute called catalog. Which JSTL code structure iterated over each product in the collection and prints out the names of the products in an un-ordered list?

A. <ul>

<c:for var='product' items={catalog}>

Actualtests.com - The Power of Knowing

310-081

<li><%=product.getName()%<>/li>

</c:for>

</ul>

B. <ul>

<c:for id=product' collection = S{catalot}> </c:for> </ul>

C. <ul?

<c:forEach var=product' items S{catalog}> <li><%=product.getName()%></li> </ul>

D. <ul>

<c:forEach id=product' collection =S{catalog}>

<li><%= product.getName()% ></li> </ul>

Answer: C

QUESTION 85 Which statements about static inner classes are true? (Choose two.)

A. A static inner class requires a static initializer.

B. A static inner class requires an instance of the enclosing class.

C. A static inner class has no reference to an instance of the enclosing class.

D. A static inner class has access to the non-static members of the outer class.

E. Static members of a static inner class can be referenced using the class name of the

static inner class.

Answer: CE

QUESTION 86

1.

public class MyCircle {

2.

public double radius:

3.

public double diameter:

4.

5.

public void setRadius(double radius) {

6.

this.radius = radius:

7.

this.diameter = radius * 2;

8.

}

9.

10.

public double getRadius() {

11.

return radius:

12.

}

13.

}

Which statement is true?

Actualtests.com - The Power of Knowing

310-081

A. The MyCircle class is full encapsulated.

B. The diameter of a given MyCircle is guaranteed to be twice its radius.

C. Lines 6 and 7 should be in a synchronized block to ensure encapsulation.

D. The radius of a MyCircle object can be set without affecting its diameter.

Answer: D

QUESTION 87 Which two are equivalent? (Choose two.)

A. 3 / 2

B. 3 < 2

C. 3 * 4

D. 3 << 2

E. 3 * 22

F. 3 <<<2

Answer: CD

QUESTION 88 Which is a valid identifier?

A. false

B. default

C. _object

Answer: C

QUESTION 89

Given:

1. public class X {

2. publie Object m () {

3. Object o = new Float ( 23.14F):

4. Object [] oa = new Object [1]:

5. oa [0] = o:

6. o = null;

7. return oa [0]

8. }

9. }

When is the Float object. Created in line 3. eligible for garbage collection?

A. just after line 5

B. just after line 6

C. just after line 7 (That is. As the method returns)

D. Never in this method

Actualtests.com - The Power of Knowing

310-081

Answer: D

QUESTION 90

Given:

3. int I = I , j = 10;

4. do {

5. if (i>j) continue:

6. j--:

7. } while (++<6);

After execution. What are the values for I and j?

A. i = 6 and j = 5

B. i = 5 and j = 5

C. i = 6 and j = 4

D. i = 5 and j = 6

E. i = 6 and j = 6

Answer: A

QUESTION 91 Given a header in an HTTP request:

X-Retries:4

Which two retrieve the value of the header from a given ServletRequest request? (Choose two.)

A. request.getHeader ("X-Retries")

B. request.getIntHeader ("X-Retries")

C. request.getRequestHeader ("x-Retries")

D. request.getHeaders ("X-Retries").get (0)

E. CK request.getRequest Headers ("X-Retries"). Get (0)

Answer: AB

QUESTION 92 Given:

String value = getServletContext().GetlnitParameter("foo"):

in an HttpServlet and a web application deployment descriptor that contains:

<contex-param> <param-name>foo</param-name> <param-value>frodo</value> <context-param> Which two are true? (Choose two)

A. The foo initialization parameter CANNOT be set programmatically.

B. Compilation fails because getlnitParameter returns type Object.

Actualtests.com - The Power of Knowing

310-081

C. The foo initialization parameter is NOT a servlet initialization parameter.

D. Compilation fails because ServletContext does NOT have a getlnitParameter method.

E. The foo parameter must de defined within the <servlet> element of the deployment

descriptor.

F. The foo initialization parameter can also be retrievedusing getSErvletConfig().

GetlnitParameter ("foo"). Answer AC

QUESTION 93

Given:

1. class BaseClass {

2. private float x = 1.0 f;

3. protected float getVar() {returnx:}

4. }

5. class SubClass extends BaseClass {

6. private float x = 2.0f;

7. //insert code here

8. }

Which two are valid examples of method overriding? (Choose two.)

A. float getVar() {return x:}

B. public float getVar() {return x; }

C. public double getVar() {return x; }

D. protected float getVar() {return x; }

E. public float getVar(float f) {return f;}

Answer: BD

QUESTION 94

Given:

1. public class Foo {

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

3. int i = l:

4. int j = I++;

5. if ((i>++j) && (i++ = = j)) {

6. i + = j:

7. }

8. }

9. }

What is the final value of i?

A. 1

B. 2

C. 3

D. 4

E. 5

Actualtests.com - The Power of Knowing

310-081

Answer: B

QUESTION 95

Given:

1. //Point X

2. public class Foo{

3. public static void main (String[] args) throws Exception {

4. java.ioi.PrintWriter out = new java.io.PrintWriter(

5. new java.io.Output Stream Writer (System.out), true):

6. out.printIn ("Hello");

7. }

8. }

Which statement at Point X on line 1 allows this code to compile and run?

A. import java.io.*.;

B. include java.io.*;

C. import java.io.PrintWriter;

D. include java.io.PrintWRiter;

E. No statement in needed.

Answer: E

QUESTION 96

Given

3. Int i = 1 , j = 10:

4. do {

5. if (i++> --j ) continue:

6. } while ( i<5):

After execution. What are the values for i and j

A. i = 6 and j = 5

B. i = 5 and j = 5

C. i = 6 and j = 4

D. i = 6and j = 6

Answer: D

QUESTION 97 Given a servlet OrderServlet mapped to processorder. And a from declaration in HTML:

11. <from action = "processorder">

12. <input type="text" name="first_name">

13. <input type+"text" name = "last_name">

14. <input type= "submit" value = "Submit Order">

15. </from>

Actualtests.com - The Power of Knowing

310-081

What OrderSErvlet method is invoked as a result of this from submission?

A. doGET

B. doPUT

C. doPost

D. doTrace

E. doSubmit

Answer: A

QUESTION 98 Which two demonstrate encapsulation of data? (Choose two.)

A. Member data have no access modifiers.

B. Member data can be modified directly.

C. The access modifier for methods is protected.

D. The access modifier to member data is private.

E. Methods provide for access and modification of data.

Answer: DE

QUESTION 99 Which three are valid declarations of a float? (Choose three.)

A. float foo = -1;

B. float foo = 1.0;

C. float foo = 42el:

D. float foo = 2.02f:

E. float foo = 3.03d:

Answer: ADF

QUESTION 100 Which will declare a method that is available to all members of the same package and be referenced without an instance of the class?

A. abstract public void methoda ();

B. public abstract double inethoda ();

C. static void methoda (double dl) {}

D. public native double methoda () {}

E. protected void methoda (double dl) {}

Answer: C

310-081

context . Which retrieves a URL to /WEB INF/ my config.xml within a web application?

A. session.get Resource ("/WEB-INF/myconfig.xml")

B. request.get Resource ("/WEB-INF/myconfig.xml")

C. context.get Resource ("/WEB-INF/myconfig.xml")

D. get Class ().get Resource ("/WEB-INF/myconfig.xml")

Answer: C

QUESTION 102 Given:

10. public void service (Http Servlet Request request,

11. Http Servlet Response response) {

12. // your code here

13. {

Which code snippet inserted at line 12 cause the client to redirect to

http://www.example.com?

A. response.send Redirect (http://www.example.com):

B. response.send Redirect (new URL ("http://www.example.com"));

C. Request Dispatcher rd=

get Servlet Context (). Get Request Dispatcher ( http://www.example.com")'

rd.

forward (request. Response):

D.

Request Dispatch rd=

Get Servlet Context ().get Request Dispatcher(

New URL (http://www.example.com)); Rd. forward (request.response):

Answer: A

QUESTION 103 Which statement is true?

A. The Error class is a Runtime Exception.

B. No exceptions are subclasses of Error.

C. Any statement that may throw an Error must be enclosed in a try block.

D. any statement that may throw an Exception must be enclosed in a try block.

E. Any statement that may throw an Runtime Exception must be enclosed in a try block.

Answer: B

QUESTION 104 Given:

8. int index = [;

Actualtests.com - The Power of Knowing

310-081

9. String [] test = new String [3];

10. String foo = test [index]

What is the result?

A. foo has the value""

B. foo has the value null.

C. An exception is thrown.

D. The code will not compile.

Answer: B

QUESTION 105

1.

public class X {

2.

public static void main (String [] args) {

3.

Strings = new String ("Hello");

4.

modify (s);

5.

System.out.printIn(s):

6.

}

7.

8.

public static void modify (String s) {

9.

s + = "world!"'

10. }

11. }

What is the result?

A. The program runs and prints "Hello"

B. An error causes compilation to fail.

C. The program runs and prints "Hello world!".

D. The program runs but aborts with an exception.

Answer: A

QUESTION 106

1.

interface Foo {

2.

int k = 0;

3.

}

4.

5.

public class Test implements Foo {

6.

public static void main (String args []){

7.

int i:

8.

Test test = new Test ():

9.

i = test. k:

10. i = Test.k:

11. i = Foo. k:

12. }

13. }

Actualtests.com - The Power of Knowing

310-081

What is the result?

A. Compilation succeeds.

B. An error at line 2 cause compilation to fail.

C. An error at line 9 cause compilation to fail.

D. An error at line 10 cause compilation to fail.

E. An error at line 11 cause compilation to fail.

Answer: A

QUESTION 107 Given an HttpServletRequest request, which retrieves an object of type Account with an Id of "account"?

A. Account account = request.get Resource("account"):

B. Account account = request.get Attribute ("account"):

C. Account account = request.get Parameter (account"):

D. Account account = (Account)request.getResource ("account"):

E. Account account = (Account) request.get Attribute ("account"):

F. Account account = (Account) request.get Paramter ("account"):

Answer: E

QUESTION 108 Which HTTP method represents a request for information about the supported methods on an HTTP server?

A. GET

B. INFO

C. HEAD

D. TRACE

E. OPTIONS

Answer: E

Actualtests.com - The Power of Knowing