Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sample test question

 
jim yin
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
28) When using a SAX2 parser, a developer wants to get called back by the parser when problems occur. Which of the following can be used to accomplish this goal?
a) Implement the ErrorHandler interface.

b) Implement the DocumentHandler interface.

c) Implement the ContentHandler interface.

d) Subclass the DefaultHandler class and override methods for events of interest.
Multiple Select - Please select all of the correct answers (this question has 2 correct choices).

d) is correct. Is a) correct? In order to do that, we also need to implement b) and c), right?
41) While analyzing an XSLT stylesheet for performance it was noticed that the following XSLT statement occurred frequently:
<xsl:for-each select="//book[author='Smith']">
To improve the performance of the stylesheet, the XML developer's approach would be which of the following?

a) <xsl:variable name="SmithBooks" select="//book[author='Smith']"/>
...
<xsl:for-each select="$SmithBooks"/>

b) <xsl:key name="book-author" match="book" use="@author"/>
...
<xsl:for-each select="key('book-author', 'Smith')"/>

c) <xsl:variable name="books" select="//book"/>
...
<xsl:for-each select="$Books[author='Smith']"/>

d) <xsl aram name="books" select="//book"/>
...
<xsl:for-each select="$books[author='Smith']"/>

Multiple Select - Please select all of the correct answers (this question has 2 correct choices).
The answers I could think of are a) b), but d) is also correct?
[ October 04, 2002: Message edited by: jim yin ]
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jim,
You are right. The answers for the SAX question are "a" and "d". ContentHandler is the replacement interface for deprecated DocumentHandler. DefaultHandler class is like an adapter class that provides some minimal default implementation for the following interfaces - ContentHandler, DTDHandler, EntityResolver and ErrorHandler. Hence in order for your class to be able to react to SAX events, it is sufficient if you just subclass the DefaultHandler and override the methods of interest (methods pertaining to ErrorHandler Interface in our case). Ofcourse, you need to do a setContentHandler() for your derived class object to the parser XMLReader (something like registering your class object for SAX events, you choose how to react to them by defining the behaviour in your overridden implementation of the methods of interest).
So, the bottom line here is that we should implement the ErrorHandler interface.
ContentHandler and DocumentHandler interfaces have no knowledge of ErrorHandler.
I need to recollect some lost memories in order to answer the second one I need to revisit some of the topics again.
 
Svetlana Petrova
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the first question answers c) and d) are correct. Your may either implement ContentHandler in your class or subclass DefaultHandler class, which implements all methods in the ContentHandler with do-nothing methods, so you only have to override methods you're interested in. (See XML in a Nutshell, chapter 17 - SAX).
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The requirement here is
"a developer wants to get called back by the parser when problems occur"
I think ContentHandler interface has nothing to do with addressing the behaviour when an error occurs. Since the DefaultHandler class implements the ErrorHandler interface with do-nothing methods, the options would be "a and d". I don't think "c" comes into picture. Please correct me if i'm wrong.
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
About 41 -
I think a and d are right.
b is wrong since it treats author as an attribute while the predicate in the original code treats author as an element.
c has a syntax error (books versus Books).
In between a and d, d seems to be a stronger solution since we narrow down the selection upfront.
Cheers,
Dan
 
Svetlana Petrova
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you read the question, please, pay attention to the words:
"a developer wants to get __called back__ by the parser when problems occur." (problems, not errors, btw.)
_Callback_ is a keyword here. And ContentHandler interface is a callback interface. You would use ErrorHandler interface in order to provide custom handling for particular classes of errors a parser detects.
BTW, it's a question for which I've already figured a right answer. As I've mentioned before I've figured 38 correct out 44.
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Svetlana,
I'm still not convinced with your answer. I'm reading your words carefully again here
================================================
"a developer wants to get __called back__ by the parser when problems occur." (problems, not errors, btw.)
_Callback_ is a keyword here. And ContentHandler interface is a callback interface. You would use ErrorHandler interface in order to provide custom handling for particular classes of errors a parser detects.
=================================================
I would like to look at the word "callback" along with "when problems occur". I agree that ContentHandler is a callback interface, but strongly feel that it has nothing to do with problems (i don't know how to look problems differently from errors and warnings as defined in the ErrorHandler interface).
I also agree with the below quote of yours -
"ErrorHandler interface in order to provide custom handling for particular classes of errors a parser detects."
Can anyone please try to validate our thougths?
Thanks.
 
Svetlana Petrova
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still think that the answer is in the question itself.
When parser reads a document piece by piece, and if a _problem_ occurs, parser still may throw a SAXParseException or a SAXException, which your programm may handle the way you want. You don't need an error handler in this case. You still have a way to catch exceptions while parser walks through. Correct?
 
Svetlana Petrova
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops! I didn't mention in a previous reply, that I'm talking about a case when your class implements a ContentHandler and parser sets a ContentHandler.
"XML in a Nutshell" gives a real good example of this.
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see your point, but i still cannot digest ContentHandler doing something(getting a callback) when problems occur. So do you mean that we need not do a setErrorHandler() on the parser and still think of addressing when "problems" occur in the parsing process? (like handling the exceptions using try-catch around the xmlReader.parse() kind of stuff).
I think it boils down to what we define as a problem and what as an error in the parsing process.
 
jim yin
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My thought:
ContentHandler does not handle error or warning or fata errors, these are handled by ErrorHandler. This is the problem. In order to handle above problems, we have to implement ErrorHandler methods.
 
jim yin
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only way to check it out now is to do it again
 
Svetlana Petrova
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep. I was talking about catching SAXParserException and SAXException from ContentHandler methods.
And I agree that it depends on what they mean using word "problems".
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Friends,
We had a very good discussion. So what is the consensus on this? Shall we go for voting and go as per the no. of votes Just kidding.
Friends, please join here and resolve the dead-lock. Till then i'll take a nap
Thanks.
 
Svetlana Petrova
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jayadev,
You won! You're right!
I just repeated the test with exact same answers I used before, except this one about ErrorHanlder/ContentHandler. So I made selections a) and d) and I've got now 40(!) correct out of 44.
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Svetlana,
I really appreciate your commitment in taking the whole test to check the validity of this. I look at this as if we all won, i.e., in our commitment towards our final goal of getting the concepts clear and as a result getting thru the exam.
Thanks a lot.
 
jim yin
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Svetlana Petrova:
Jayadev,
You won! You're right!
I just repeated the test with exact same answers I used before, except this one about ErrorHanlder/ContentHandler. So I made selections a) and d) and I've got now 40(!) correct out of 44.

Great. How about we make efforts to get all questions right?
 
Svetlana Petrova
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You see there are a couple of questions (4 in fact ) that IBM really screwed up in this test version. All I have to make with them just playing and trying to hit the right answer.
Here are examples:
====================
41)
A development team has moved an XML application from the development server to the staging server. While testing the XML application on the new server, the application returns a message indicating that there is an "invalid entity reference" error in the DTD. The MOST likely cause of this error is:

a) The DTD was not compiled on the new server, and the parser is failing to recognize the entities in the XML document instance.

b) The DTD references external entities that were not migrated.

c) The DTD needs to be converted to an XML Schema that uses tokens instead of entities.

d) The parser is incompatible with the XML application.

e) The application must be recompiled on the new server.

Single Select - Please select the best answer (one and only one choice must be selected).

===
42)
A development team has moved an XML application from the development server to the staging server. While testing the XML application on the new server, the application returns a message indicating that there is an "invalid entity reference" error in the DTD. The MOST likely cause of this error is:

a) changes to the XML transformation between technical manual and ordering DTDs or XML Schemas.

b) a change to the XML rendering rules for technical manuals.

c) an enhancement to the DTD or XML Schema for technical manuals.

d) adjustments to the part number linking approach.

Single Select - Please select the best answer (one and only one choice must be selected).

============
THEY simply appended answers from question#41 to #42 (?!!).
The same thing with the following:
===
13)
Processing instructions can be used for all of the following EXCEPT:

a) a method for passing the name of a stylesheet.

b) Use ID and IDREF attributes to represent bi-directional relationships.

c) Copy the data in a relationship into the element for the row containing the foreign key.

d) Copy the data in a relationship into the element for the row containing the primary key.

Multiple Select - Please select all of the correct answers (this question has 2 correct choices).

17)
A developer needs to convert records from a relational database into XML. Each row in a table is represented as an element in the document How can the developer represent relationships in the database?

a) Use ID and IDREF attributes to represent unidirectional relationships.

b) Use ID and IDREF attributes to represent bi-directional relationships.

c) Copy the data in a relationship into the element for the row containing the foreign key.

d) Copy the data in a relationship into the element for the row containing the primary key.


Multiple Select - Please select all of the correct answers (this question has 2 correct choices).
=========
#17 makes some sense, #17 doesn't. But for #17 I'm still not sure about right answers. Do you have any ideas?
 
jim yin
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
41) b, 42) d. For other two, I really have no idea
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
13)a (not at all sure about other one for this) 17)a,c
 
jim yin
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jayadev and Svetlana: Pls check ur mails.
 
Svetlana Petrova
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,
Is there any way to post file with IBM Test Q & A I've made. So far, I figured 42 out 44 questions, and I need a help with the last 2, not answered. It's really hard to tell now which one is not correct. I think that I've got only 1 in doubt. Than that means that there is another question which I think is correct, but it's not.
Together we could figure out it faster, I think.
Thanks a lot,
Svetlana.
 
jim yin
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe moderators can help you out.
 
Vasan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jayadev,
for 13 u voted for a. But we can pass the name of the stylesheet in procession Instruction.
so my vote goes for c. pls correct if iam wrong.
vasan
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vasan,
I have absolutely no idea as to how to justify options other than "a" for this question. Please explain with an example as to how we can go for "c". As for "a", it is using that <?xsl-stylesheet...... href="test.xst"?> stuff.
Thanks.
 
Svetlana Petrova
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
I've got them all 44 correct now!!!
And even if it may not make any sense, but the correct answers to #13 are A and D.
As I mentioned before, this question with answers together appears to be a mess. I had to play with different combinations before finally I hit the right one.
Take care,
Svetlana.
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good job Svetlana. Yeah! i'm still not being able to figure out the meaning of option "d" for question13 in the first place
 
Svetlana Petrova
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For #17 the answers are A and D also. But they make sense. If you take a look at W3 "Schema Part 0,Primer" Recommendation, you'll find a good example, report.xsd schema. You'll see from the schema, that they create ID/IDREF elements and also they create elements to have unique values of @code and @number attributes.
This example gave me a hint.
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fellows,
About 28 -
I simplified the Sax.Counter class to show the usage of DefaultHandler and ErrorHandler.
Here is the code.

Cheers,
Dan
 
Vasan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jayadev,
pls see the question "Processing instructions can be used for all of the following EXCEPT"
we can pass the stylesheet name thro the processing instruction as u have explained. so my choice goes to b,c
correct if iam wrong
Vasan
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think u r right. But can you please explain how "d" is appropriate choice for PI usage.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic