File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "question" Watch "question" New topic


jeffrey z. lee
Ranch Hand

Joined: Mar 21, 2002
Posts: 40
Given that file1.jsp has the following custom tag:
<m:test times="5"/>
And the actual class file has the following setter method for variable 'times':
public void setTimes(int t){
Identify true statements:
A Code works fine
B Parameter t should be String int the method : setTimes(String t)
C The body of the method should be: this.t=Integer.parseInt(t)
D The name of the variable should be 'times'

is ans. C true? why?

jeffrey z. lee
Nazmul Huda Sarkar
Ranch Hand

Joined: Feb 01, 2002
Posts: 317
The code should work the string will be auto converted to int....

Nazmul<br />SCJP,SCWCD,IBM OOAD with UML
Howard Kung

Joined: Jul 22, 2002
Posts: 24
According to (where the question came from), the answer should be B, C. Any comment? anyone?

Howard Kung<br />SCJP 1.2<br />SCWCD<br />IBM Certified Specialist: WebSphere 4.0
Raj Paul
Ranch Hand

Joined: Jul 09, 2002
Posts: 77
Yes, the answer should be B,C
Because, in taglibs the automatic conversion is not there like java beans. In taglib we have a tag named <type> which specifies the type of the variable. default is String.
so B&C is correct

Raj Paul
Paul McKenna
Ugly Redneck
Ranch Hand

Joined: Jul 08, 2000
Posts: 1006
Strictly speaking B is the correct answer, why?
1. All values returned at page translation time are of the type String. Hence only B would result in correct compilation
2. C would not be an appropriate answer because assuming the method signature does not change, just an Integer.parseInt would not accomplish anything
3. Automatic type cast is not performed in the case of Tab library attributes. Automatic type cast is only allowed when the rtexprvalue tag is set to true in the TLD file.
Zeig Hail!

Commentary From the Sidelines of history
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
Provided that the attribute doesn't accept request-time expressions (rtexprvalue is false), automatic type translation will occur and the code will work fine.
Remember, automatic type translation doesn't take place when rtexprvalue is set to true.
As an aside, if the signature is changed (answer B), then the body of the method should be changed (as per C), provided that the instance variable is still declared as a primitive int, of course.
Maha Annadurai
Ranch Hand

Joined: Oct 27, 2002
Posts: 87
Since the given example uses a literal value for the "times" atrribute like times="5" , even if we set <rtexprvalue>true</rtexprvalue> in tld file, the code will work fine.
Literal values are always auto-converted to java standard objct types like Integer /Byte /Boolean etc.
For the above example, with rtexprvalue set to true, here are some tests you can play with.
<test:body count="1"> (will work)
Example 1
<test:body count="<%=2%>"> (will work)
Example 2
<test:body count='<%="2"%>'> (will not work)
Example 3
<test:body count='<%=Integer.valueOf("2").intValue()%>'> (will work)
Example 4
Maha Anna
I agree. Here's the link:
subject: question
jQuery in Action, 3rd edition