aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HFSJ mock exam 2 Question -Standard Actions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HFSJ mock exam 2 Question -Standard Actions" Watch "HFSJ mock exam 2 Question -Standard Actions" New topic
Author

HFSJ mock exam 2 Question -Standard Actions

deepa raj
Ranch Hand

Joined: Jul 25, 2008
Posts: 124


Which of the following lines of code, if inserted independently at Line 5, will cause the text within the c therwise tag to display? (Choose all that apply)

A. books.add("");
B. books.add(null);
C. books.clear();
D. books.add("Head First");
E. books = null;

Answer please.
[ August 07, 2008: Message edited by: deepa raj ]
Amruth Puppala
Ranch Hand

Joined: Jul 14, 2008
Posts: 295
Hi deepa raj,
somethig is missing in the question.

Add mos more clarity to the question if you haveinfo.


SCJP 5 |SCWCD 5| Started thinking about Web Services ?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

hi,what is your question?
deepa raj
Ranch Hand

Joined: Jul 25, 2008
Posts: 124
Check it now. :-)
Amruth Puppala
Ranch Hand

Joined: Jul 14, 2008
Posts: 295
ans: E. books = null
Sandeep Bhandari
Ranch Hand

Joined: Apr 16, 2004
Posts: 201
my take is also E option
I choose so because not Empty check if the variable itself is null or not

correct if I am wrong


SCJP 96% | SCWCD 90%| SCJP mock exams | My SCJP blog
deepa raj
Ranch Hand

Joined: Jul 25, 2008
Posts: 124
what about books.clear() ?
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
What happens when you try each option in your code? That is the best way to know for sure what is correct.
Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
A. books.add("");

This answer is wrong. As books is a arraylist. Even if we add blank String to it. Its size will be 1. Because it will be like this books[0]="".

B. books.add(null);

This answer is wrong. As books is a arraylist. Even if we add null to it. Its size will be 1. Because it will be like this books[0]=null.

C. books.clear();

This is the right answer because it will clear the arraylist which will eventually make it empty.


D. books.add("Head First");

This answer is wrong. As books is a arraylist. Even if we add String to it. Its size will be 1. Because it will be like this books[0]=Head First.

E. books = null;

This is wrong because here we are making the object book itself as null and adding as a null object as an attribute.

So trying to use the empty operator with it will cause FatalException.


SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog- http://rkydesigns.blogspot.com
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
Thank you - very nice explanation. I am suprised that the last option with the null did not work. I found this on the sun site regarding the empty operator and the EL

The language offers the following operators (parentheses here are used only for grouping):

binary logical operators
(<, <=, ==, >=, >, lt, le, eq, ge, gt)


binary arithmetic operators
(+, -, *, /, div, %, mod)


indexing operators
(.) and ([])


(equivalent) unary negation operators
(!, not)


arithmetic unary minus
(-)


(empty) operator, which evaluates to true if the expression evaluates to null, or evaluates to a container object that contains no items.

ternary operator for simple if-then-else
(?
Hema Nandhini
Ranch Hand

Joined: Aug 04, 2008
Posts: 31
option E is correct. I tried it and it jumps to the otherwise condition. 'empty' works for empty lists and also if the object as such evaluates to null, as Micheal said.


SCJP 1.4 (86%)<br />SCWCD 1.5 (88%)
Milind Patil
Greenhorn

Joined: Oct 19, 2003
Posts: 26
Hi,

I checked with JSP2.0 Specification (Page: 1-73 Point: JSP.2.3.7). This is what I got from it.

JSP.2.3.7 Empty Operator - empty A
The empty operator is a prefix operator that can be used to determine if a value is null or empty.
To evaluate empty A,
� If A is null, return true,
� Otherwise, if A is the empty string, then return true.
� Otherwise, if A is an empty array, then return true.
� Otherwise, if A is an empty Map, return true,
� Otherwise, if A is an empty Collection, return true,
� Otherwise return false.


I also ran the example provided.
For answers C and E, I got output as "I have not selected any favorite books."


Milind B. Patil - SCJP-1.4, SCWCD-5.0, SCBCD-5.0
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

That is the best way to know for sure what is correct.

No. Containers sometimes have their own way of doing things.


[My Blog]
All roads lead to JavaRanch
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
Thanks - I did not realize that containers can implement different behavior for the EL 'empty' operator. I thought they were allowed to implement any way they choose but be required to meet the spec.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I thought they were allowed to implement any way they choose but be required to meet the spec.

They do, but sometimes don't. Of course, they won't blunder such simple things like 'empty'. I didn't encounter much non-spec friendly behavior in SCWCD, but more in SCBCD. So trying something with a container is good, but does not guarantee 100% correctness.
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
Understood. I just had noticed that some posts were giving incorrect answers/information and thought that it would be better to have these posters discover the error for themselves. I tried to give a gentle nudge in the right direction :-).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: HFSJ mock exam 2 Question -Standard Actions
 
Similar Threads
HFJS (V2) Final Mock Question 26 is wrong?
Question 26 of HFSJ Final mocktest
Final Mock Test Question 26 Head First and Servlets
Question regarding answers in HFSJ 2nd ed mock exam
HFSJ 2nd edition Mock exam questions 6, 11,26,34,49 and 69