Vous êtes sur la page 1sur 100

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

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.

B.

C.

D.

E.

AnAdapter1 aa = new AnAdapter1 () {}

AnAdapter0 aa = new AnAdapter0 () {}

AnAdapter0 aa = new AnAdapter0 (5) {} AnAdapter1 aa = new AnAdapter1 (5) {} AnInterface
AnAdapter0 aa = new AnAdapter0 (5) {}
AnAdapter1 aa = new AnAdapter1 (5) {}
AnInterface ai = new Anlnterface (5)) {
class A {
public String to String() {
return “4”;
}
}
class B extends A {
public String toString() {
return super.toString() + “3”;
}
}
public class Test {
public static void main (String[] args) {
System.out.printIn(new B());
}
}
Compilation succeeds and 4 is printed.
Compilation …………… is printed.
An error on line 9 cause compilation to fail.
An error on line 14 cause compilation to fail.
Compilation succeeds but an exception is thrown at line 9.

Answer: B, D

Question: 2

1.

3.

4.

5.

6.

7.

8.

9.

10.

11.

12.

13.

14.

15.

16.

What is the result?

A.

B.

C.

D.

E.

Answer: B

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) {}

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

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: A, C

Question: 4

1. class A { 2. public byte file Number () { 3. return l; 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 {
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”.

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

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
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
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?

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

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

16 > 4 16 / 2 16 / 22 16 >>> 2 public class X
16 > 4
16 / 2
16 / 22
16 >>> 2
public class X {
public static void main (String [] args) {
byte b = 1277;
byte c = 126;
byte d = b + C;
}
}
Compilation succeed and d take the value 253.
Line 5 contains an error that prevents compilation.
Line 5 throws an exception indicating “out of range”
Line 3 and 4 contain errors that prevent compilation.
The compilation succeed and d takes the value of 1.

A.

B.

C. 16 * 4

D. 16 >> 2

E.

F.

Answer: DF

Question: 9

Given:

1.

2.

3.

4.

5.

6.

7.

Which statement is true?

A.

B.

C.

D.

E.

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.

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

E. The code will not compile.

Answer: B

Question: 11

Given:

1.

2.

3.

4.

5.

6.

7.

public class Test {

public static void main (String [] args) {

unsigned byte b = 0;

b--:

} } -1 225 127 Compilation will fail. Compilation will succeed but the program will
}
}
-1
225
127
Compilation will fail.
Compilation will succeed but the program will throw an exception at line 4.
public class Test {
public static void main (String[] args) {
String foo = args [0];
String bar = args [1];
String baz = args [2];
}
}
baz has the value of “”.
baz has the value of null.
baz has the value of “red”
baz has the value of “blue”
baz has the value of “green”

The code does not compile.

the program throws an exception.

What is the value of b bat line 5?

A.

B.

C.

D.

E.

Answer: D

Question: 12

Given

1.

2.

3.

4.

5.

6.

7.

And command line is vacation:

Java Test red green blue

What is the Result?

A.

B.

C.

D.

E.

F.

G.

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

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

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

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

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

B. Event

C. Object

D.

E.

F.

Exception Throwable Runtime Exception public class Foo { public static void main (String [] args)
Exception
Throwable
Runtime Exception
public class Foo {
public static void main (String [] args) {
try { System.exit (0); }
finally { System.out.printIn(“Finally”):}
}
}
the program runs and prints nothing.
The program runs and prints “Finally”.
The code compiles. But an exception is thrown at runtime.
the code will not compile because the catch block is missing.
Public class While Foo}
public static void main (Straing[] args) {
int x = I, y = 6
while ( y--) {x++:}
System, out. printIn (“x = “ + x + “ y = “ + y):
{

{

Answer: A, D, E, F

Question: 17

Given:

1.

2.

3.

4.

5.

6.

What is the result?

A.

B.

C.

D.

Answer: A

Question: 18

Given:

1.

2.

3.

4.

5.

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

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

Question: 19

Given:

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.

B.

C.

D.

The do Start Tag method is called once.

The do After Body method is NOT called. The EVAL_Page constant is a valid return
The do After Body method is NOT called.
The EVAL_Page constant is a valid return value for the do End Tag Method.
Public void services (Servlet Request request,
Servlet Response response)
throws 10 Exccption {
Servlet Context cxt = get Servlet Config ().get Servlet Context ():
Input Stream in =
insert code here
{
ctx.get put Stream (“/WEB-INF/myresrc.bin”):
ctx.get Input Stream (“/WEB-INF/myresrc.bin”):
ctx.get Resource As Stream (“/WEB-INF/myresrc.bin”):
new Input Stream (new Url (“/WEB-INF/myresrc.bin”):
Get Class (). Get Resource As Stream (“/WEB-INF/myresrc.bin”):
request.add Cookie (“username”. “joe”)

request.set Cookie (“username, “joe”)

response.add Cookie (username”, “joe”))

request.add Header (new Cookie (“username”, “joe”))

request.add Cookie (new Cookie (“username”, “joe”))

response.add Cookie (new Cookie (“username”, “joe”))

response.add Header (new Cookie (“username”, “joe”))

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

Answer: A, C

Question: 20

Given

11.

12.

13.

14.

15.

16.

17.

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

A.

B.

C.

D.

E.

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.

B.

C.

D.

E.

F.

G.

Answer: F

Question: 22

Given:

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

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.

B.

C.

D.

E.

request.get Writer ():

request.get Reader ():

request.get Input Stream():

request.get Resource As Stream(): request.get Resource As Stream (Servlet Request. REQUEST): <from method =
request.get Resource As Stream():
request.get Resource As Stream (Servlet Request. REQUEST):
<from method = “GET” action = “MyServlet”>
<input type= “text” name+ “foo”>
<input type= “text” name = “foo”>
<input type = “submit”>
</from>
MyServlet.java:
public void doGet (Http ServletRequest request.
HttpServletREsponseresponse_
throws IOException. ServletExecption {
String first = request.getParameter )”foo”);
String second:
// your code here
}
second = request.getParameter (“foo”):
second = request.getParameter (“foo”, 1):
second = request.getParameter (“foo”,2):
second = request.getParameter (foo”) [1]:
second = request.getParameter Values (“foo”) [1]:

Answer: C

Question: 23

index.html:

16.

17.

18.

19.

20.

6.

7.

8.

9.

10.

11.

12

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

A.

B.

C.

D.

E.

Answer: E

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

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

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?

Only single instance of MyObject may exist within a session. The unbound method of the
Only single instance of MyObject may exist within a session.
The unbound method of the MyObject instance is called when the session to which it
is bound times out.
The com.example.MyObjectmust be declared as a servlet event listener in the web
application deployment descriptor.
The value Unbound method of the MyObject instance is called when the session to
which it is bound times out.
The tag is invoked without a body.
The doTAb method throws an exception.
The <body-content> element has the value empty.
The tag is called with the attribute skip-body=true
An inner class may be declared as static.
An anonymous inner class can be declared as public.
An anonymous inner class can be declared as private.
An anonymous inner class can extend an abstract class.
An anonymous inner class can be declared as protected.

A.

B.

C.

D.

Answer: Pending. Send your suggestions at feedback@TestKing.net

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.

B.

C.

D.

Answer: A, C

Question: 27 Which two statements are true? (Choose two.)

A.

B.

C.

D.

E.

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

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

Question: 29

Given:

1. public class MethodOver { 2. private int x,y: 3. private float z: 4. public
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);
}
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 {

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

private Component [] children;

Answer: B, E

Question: 31

Given:

1. public class Test { 2. public static void leftShift(in i int j) { 3.
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
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) {

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

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.

B.

C.

D.

the program runs and prints nothing.

The program runs and prints “Equal”. An error at line 5 cause compilation to fail.
The program runs and prints “Equal”.
An error at line 5 cause compilation to fail.
The program runs but aborts with an exception.
public class Test {
public static void main (String args []) {
Sytstem.out.printIn (6 3) :
}
}
String foo = “blue”;
boolcan [] bar = new Boolean [1];
if (bar [0] {
foo = “green”;
}
foo has the value of “”
foo hast he falue of null.
foo has the value of “blue”
foo has the value of “green”

An exception is thrown.

The code will not compile.

Answer: A

Question: 34

Given:

1.

2.

3.

4.

5.

What the output?

Answer: 5

Question: 35

Given:

8.

9.

10.

11.

12.

What is the result?

A.

B.

C.

D.

E.

F.

Answer: C

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

A. run

B. import

C. default

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

D. implement

Answer: B, C

Question: 37

Given

1.

2.

3.

4.

5.

6.

public class Foo{

public static void main (String [] args) {

Strings;

System.outprintIn (“S=”+s):

}

} The code compiles and “s=” is printed. The code compiles and “s=” + s);
}
The code compiles and “s=” is printed.
The code compiles and “s=” + s);
The code does not compile because Strings is not initialized.
The code does not compile because Strings cannot be referneed.
The code comiles, but a NullPointer Exception is thrown when toString is called.
public double methoda ():
static void methoda(double d1) {}
public native double methoda ():
abstract public foid methoda ():
protected void methoda (double d1) {}
public class Foo {
public void main ( String [] args ) {
System.out.printIn (“Hello world.”);
}
}

What is the result?

A.

B.

C.

D.

E.

Answer: C

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

A.

B.

C.

D.

E.

Answer: D

Question: 39

Given:

1.

2.

3.

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 {

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

2. class Test Exception extends Exception {}

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

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

5. run Test ();

6. }

7. }

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

A.

B.

C.

D.

E.

throws Exception

catch (Exception e)

throws Runtime Exception catch (Test Exception e) No code is necessary. public class for Bar
throws Runtime Exception
catch (Test Exception e)
No code is necessary.
public class for Bar {
public static void main (String [] args){
int i = 0 and j = 5
tp: for (;;) {
i ++;
for (;;)
if (i > -- j) break tp:
}
System.out.printIn (“i= “ + “ j = “ + j):
{
{
The program runs and prints “ I = 1 , j = 0”
The program runs and prints “ I = 1 , j = 4”
The program runs and prints “ I = 3 , j = 4”
The program runs and prints “ I = 3 , j = 0”
An error at line 4 cause compilation to fail.
An error at line 7 cause compilation to fail.

Answer: A

Question: 41

Given

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

11.

What is the result?

A.

B.

C.

D.

E.

F.

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.

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

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.

response.set Header (“X-MyHeader”. “34”): response.addHeader (“X-MyHeader”. “34”): response. Set Header
response.set Header (“X-MyHeader”. “34”):
response.addHeader (“X-MyHeader”. “34”):
response. Set Header (new Http Header (“X-MyHeader”. “34”)):
response.addHeader(new Http Header (“X-MyHeader”. “34”)):
response. addHeader (new Servlet Header (“X-MyHeader”. “34”)):
response. setHeader (new Servlet Header (“X-MyHeader”, “34”)):
doSubmit
doProcess

Answer: B, E

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

A.

B.

C.

D.

E.

F.

Answer: A, B

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.

F.

Answer: A, C

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.

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)

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

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: D, E

Question: 48

1.

2.

3.

4.

5.

6.

7.

8.

9.

class EnclosingOne { public class InsideOne {} } public class InnerTest{ public static void main(String[]args)
class EnclosingOne {
public class InsideOne {}
}
public class InnerTest{
public static void main(String[]args) {
EnclosingOne eo = new EnclosingOne():
//insert code here
}
}
InsideOne ei = eo.new InsideOne():
eo.InsideOne ei= co.new InsideOne():
InsideOne ei = EnclosingOne.new InsideOne():
EnclosingOne.insideOne ei = eo.new InsideOne():
class Base Class {
private float x = 1.0f;
protected void set Var(float f) { x = f;}
}
class SubClass extends BaseClass{
private float x = 2.0f
//insert code here
}

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

A.

B.

C.

D.

Answer: D

Question: 49

Given:

1.

2.

3.

4.

5.

6.

7.

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: C, E

Question: 50

1. Class A {

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

2. public int getNumber(int a) { 3. return a + l: 4. } 5. }
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) {
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 {

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

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

public class Test { public static void main (String args[]) { int i + 0
public class Test {
public static void main (String args[]) {
int i + 0 x FFFFFFF1:
int j = i;
}
}
–15
An error at line 3 cause compilation to fail.
An error at line 4 cause compilation to fail.
int index = 1:

Boolean [] test = new boolcan [3];

boolcan foo = test [index];

Answer: E

Question: 53

Given:

1.

2.

3.

4.

5.

6.

7.

What is the decimal value of J at line 5?

A. 0

B. 1

C. 14

D.

E.

F.

Answer: C

Question: 54

Given:

8.

9.

10.

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.

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

Answer: D

Question: 55

Given;

1. public class Test 2. public static void main (String[] args ) { 3. String
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.
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: B, D, E
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?

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

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.

2.

3.

4.

5.

6.

7.

8.

9.

10.

11.

12.

13.

14.

15.

16.

17.

18.

19.

20.

21.

22.

23.

24.

25.

26.

public class Test {

public static String output = “”;

public static void foo (int i ) { try { if ( i = =
public static void foo (int i ) {
try {
if ( i = = 1) {
throw new Exception ():
}
output + = “1”;
}
catch (Exception e) {
output + = “2”;
return;
}
finally {
out put + = “3”;
{
output + = “4”;
}
public statie void main (String args [] {
foo (0);
foo (1);
}
}
public class My Tag Handler extends Tag Support {
publin int do Start Tag () throws Jsp Exception {

try{

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

String name = page Context. Find Attribute (“name”);

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

return SKIP_BODY:

PUBLIC INT DO after Body () throws Jsp Exception {

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

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

Answer: 13423

Question: 59

5.

6.

7.

8.

9.

10. out.print (name);

11.

12.

13. }

14.

15.

16. try {

17.

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

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.

C.

D.

E.

done Foodone An exception is thrown at runtime. Compilation fails because of an error in
done
Foodone
An exception is thrown at runtime.
Compilation fails because of an error in this code.
response.get Writer ()
response.get Output Stream ()
response.get Output Writer ()
response.get Writer ().get Output Stream()
response.get Writer (Writer.OUTPUT_TEXT)
request.getCookies()
request.getAttributes()
request.getSession ().getCookies()
request.getSession (). GetAttributes()

Answer: A

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

A.

B.

C.

D.

E.

Answer: A, B

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

A.

B.

C.

D.

Answer: A

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: C, E

Explanation:

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

The <transport-guarantee> element can contain any of three values: NONE , INTEGRAL , or

CONFIDENTIAL.

Question: 63 Which two statements are true? (Choose two.)

A. An anonymous inner class can be declared inside of a method. B. An anonymous
A.
An anonymous inner class can be declared inside of a method.
B.
An anonymous inner class constructor can take arguments in some situations.
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: A, B
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”.

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

B. The code compiles and prints “A,A”.

C. The code compiles and prints “B,B”.

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 =
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: D, E
Question: 67
What is the numerical range of char?
A.
0…32767
B.
0…65535
C.
–256…255
D.
32768…32767
E.
Range is platform dependent.
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?

A. java Test 2222

B. java Test 1234

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

C. java Test 4242

D. java Test 4321

Answer: C

Question: 69

Given:

1. public interface Foo {

2. int k = 4:

3. }

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

A.

B.

C.

D.

E.

F.

G.

H.

final int k = 4: public int k = 4: static int k = 4:
final int k = 4:
public int k = 4:
static int k = 4:
private int k = 4:
abstract int k = 4:
volatile int k = 4:
transient int k = 4:
protected int k = 4:
public class Foo {
public static void main (String [] args) }
try { return;}
finally { Syste.out.printIn (“Finally”);}
}
}
The program runs and prints nothing.
The program runs and prints “Finally”.
The code comiles. But an exception is thrown at runtime.
The code will not compile because the catch block is missing.

Answer: A, B, C

Question: 70

Given

1.

2.

3.

4.

5.

6.

What is the result?

A.

B.

C.

D.

Answer: B

Question: 71

11. public class Iterate Handler extends Body Tag Support {

12. private Collection c:

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

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

22. public int do After Body () throuws Jsp Exception { 23. if (it. Has
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
Question: 72
For a given Servlet Response response, which retrieves an object for writing binary 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: A, 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

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

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: B, D,
A.
*/*
B.
/*.do
C.
myServlet
D. /Myservlet
E. /MyServlet/*
F. MyServlet/*.isp
Answer: B, D, E
Question: 75
Given:
1.
package foo;
2.
3.
public class Outer {
4.
public static class Inner {
5.
}
6.
}
Which statement is true?
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.
}

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

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) {
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.
}
What is the result?
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)

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

F. (d == 10.0)

Answer: A, B, F

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

A. Char ch = “a”; B. char ch = “”; C. char ch = “café”;
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: B, E
Question: 80
Given:
1.
Public class Foo {
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 ():

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

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.

Answer: B

import java. Io. IO Exception: public class Exception Test { public static void main (String
import java. Io. IO Exception:
public class Exception Test {
public static void main (String [] args){
try {
method A ()
catch (IOException e) {
System.out.printIn (“Caught IO Exception”)
catch (exception e) {
System. Out. printIn (“Caught Exception”);
}
}
public void method A () {
throw new IO Exception () ;
}
}
The code will not compile.
The output is Caught Exception
The output is Caught IO Exception
The program executes normally without printing a message.
The tag handler must extend body Tag.

The do After Body method is NOT called.

The set Body Content method is called.

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

Question: 82

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

11.

12.

13.

14.

15.

What is the result?

A.

B.

C.

D.

Answer: A

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

A.

B.

C.

D.

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?

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

A. <ul> <c:for var=’product’ items={catalog}>
A.
<ul>
<c:for var=’product’ items={catalog}>
<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?

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.

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

Answer: D

Question: 87 Which two are equivalent? (Choose two.)

A. 3 / 2

B. 3 < 2 C. 3 * 4 D. 3 << 2 E. 3 *
B.
3 < 2
C.
3 * 4
D.
3 << 2
E.
3 * 22
F.
3 <<<2
Answer: C, D
Question: 88
Which is a valid identifier?
A. false
B. default
C.
_object
D.
a-class
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

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?

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

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

request.getHeader (“X-Retries”) request.getIntHeader (“X-Retries”) request.getRequestHeader (“x-Retries”)
request.getHeader (“X-Retries”)
request.getIntHeader (“X-Retries”)
request.getRequestHeader (“x-Retries”)
request.getHeaders (“X-Retries”).get (0)
re request.getRequest Headers (“X-Retries”). Get (0)
The foo initialization parameter CANNOT be set programmatically.
Compilation fails because getlnitParameter returns type Object.
The foo initialization parameter is NOT a servlet initialization parameter.
Compilation fails because ServletContext does NOT have a getlnitParameter method.
The foo parameter must de defined within the <servlet> element of the deployment
descriptor.
The foo initialization parameter can also be retrievedusing getSErvletConfig().
GetlnitParameter (“foo”).

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

A.

B.

C.

D.

E.

Answer: A, B

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.

B.

C.

D.

E.

F.

Answer: A, C

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;

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

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: B, D Question: 94 Given: 1. public class Foo { 2. public static void
Answer: B, D
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
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.

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

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.

B. i = 5 and j = 5

i = 6 and j = 5 i = 6and j = 6 <from action
i = 6 and j = 5
i = 6and j = 6
<from action = “processorder”>
<input type=”text” name=”first_name”>
<input type+”text” name = “last_name”>
<input type= “submit” value = “Submit Order”>
</from>
Member data have no access modifiers.
Member data can be modified directly.
The access modifier for methods is protected.

The access modifier to member data is private.

Methods provide for access and modification of data.

C. i = 6 and j = 4

D.

Answer: D

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

11.

12.

13.

14.

15.

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.

B.

C.

D.

E.

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:

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

D. float foo = 2.02f:

E. float foo = 3.03d:

Answer: A, D, F

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.

B.

C.

D.

E.

abstract public void methoda ();

public abstract double inethoda ();

static void methoda (double dl) {} public native double methoda () {} protected void methoda
static void methoda (double dl) {}
public native double methoda () {}
protected void methoda (double dl) {}
session.get Resource (“/WEB-INF/myconfig.xml”)
request.get Resource (“/WEB-INF/myconfig.xml”)
context.get Resource (“/WEB-INF/myconfig.xml”)
get Class ().get Resource (“/WEB-INF/myconfig.xml”)
public void service (Http Servlet Request request,
Http Servlet Response response) {
// your code here
{
response.send Redirect (http://www.example.com):
response.send Redirect (new URL (“http://www.example.com”));

Request Dispatcher rd= get Servlet Context (). Get Request Dispatcher ( http://www.example.com”)’ rd. forward (request. Response):

Request Dispatch rd= Get Servlet Context ().get Request Dispatcher( New URL (http://www.example.com)); Rd. forward (request.response):

Answer: C

Question: 101 Given an Http Session session. A Servlet Request request. And a Servlet Context context. Which retrieves a URL to /WEB INF/ my config.xml within a web application?

A.

B.

C.

D.

Answer: C

Question: 102

Given:

10.

11.

12.

13.

Which code snippet inserted at line 12 cause the client to redirect to http://www.example.com?

A.

B.

C.

D.

Answer: A

Question: 103 Which statement is true?

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

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.

9.

10.

int index = [; String [] test = new String [3]; String foo = test
int index = [;
String [] test = new String [3];
String foo = test [index]
foo has the value””
foo has the value null.
An exception is thrown.
The code will not compile.
public class X {
public static void main (String [] args) {
Strings = new String (“Hello”);
modify (s);
System.out.printIn(s):
}
public static void modify (String s) {
s + = “world!”’
}
}
The program runs and prints “Hello”
An error causes compilation to fail.
The program runs and prints “Hello world!”.
The program runs but aborts with an exception.

What is the result?

A.

B.

C.

D.

Answer: B

Question: 105

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

11.

What is the result?

A.

B.

C.

D.

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:

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

8. Test test = new Test ():

9. i = test. k:

10. i = Test.k:

11. i = Foo. k:

12. }

13. }

What is the result?

A.

B.

C.

D.

E.

Compilation succeeds.

An error at line 2 cause compilation to fail.

An error at line 9 cause compilation to fail. An error at line 10 cause
An error at line 9 cause compilation to fail.
An error at line 10 cause compilation to fail.
An error at line 11 cause compilation to fail.
Account account = request.get Resource(”account”):
Account account = request.get Attribute (“account”):
Account account = request.get Parameter (account”):
Account account = (Account)request.getResource (“account”):
Account account = (Account) request.get Attribute (“account”):
Account account = (Account) request.get Paramter (“account”):
HEAD

Answer: A

Question: 107 Given an HttpServletRequest request, which retrieves an object of type Account with an Id of “account”?

A.

B.

C.

D.

E.

F.

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.

D. TRACE

E. OPTIONS

Answer: E

Question: 109 For a given ServletResponse response, which retrieves an object for writing binary data?

A. response.getWriter()

B. response.getOutputStream()

C. response.getOutputWriter()

D. response.getWriter().getOutputSTream()

E. response.getWriter(Writer.OUTPUT_BINARY)

Answer: B

Question: 110

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

A JSP page needs to instantiate a JavaBean to be used by only that page. Which two jsp:useBean attributes must be used to access this attribute in the JSP page? (Choose two.)

A. id

B. type

C. name

D. class

E. scope

F. create

Answer: A, D

id B. type C. name D. class E. scope F. create Answer: A, D Explanation: Scope

Explanation:

Scope is default to page, so don't need it. Only two "required" vars are ID and CLASS.

Question: 111 In form-based authentication, what must be included in the HTML returned from the URL specified by the <login-page> element?

A. a base-64 encoded user name and password

B. a form that POSTs to the j_security_check URL

C. an applet that requests the user name and password from the user

D. a hidden field that supplies the login-constraint used by the application

Answer: B

Question: 112 Which two security mechanisms protect the response stream? (Choose two.)

A. authorization

B. data integrity

C. confidentiality

D. authentication

Answer: B, C

Question: 113 Which two pieces of information are needed when declaring the web resource collection in the deployment descriptor? (Choose two.)

A. the URL pattern that requires authorization

B. the HTTP methods that require authorization

C. the users allowed access to the web resource

D. the J2EE roles allowed access to the web resource

E. the authentication mechanism required by the web resource

Answer: A, B

Question: 114 When using a form-based authentication, which action must be used in the login form?

A. j_login

B. j_get_user

Exam Name:

Sun Certified Web Component Developer for the Java 2 Platform, Enterprise Edition 1.4

Exam Type:

SUN

   

Exam Code:

310-081

Total Questions:

254

C. j_login_check

D. j_get_security

E. j_security_check

Answer: E

Question: 115 Which security mechanism is employed only on the server-side to limit access to resources or components?

A. authorization

B. data integrity

resources or components? A. authorization B. data integrity C. confidentiality D. authentication Answer: A Question: 116

C. confidentiality

D. authentication

Answer: A

Question: 116 Which element of a web application deployment descriptor <security-constraint> element is required?

A. <realm-name>

B. <auth-method>

C. <security-role>

D. <transport-guarantee>

E. <web-resource-collection>

Answer: E

Question: 117

Given:

1. <%-- insert code here --%>

2. <html>

3. <body>

4. Today is: <%= new Date() %>

5. </body>

6. </html>