• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

question about jsp:useBean from mock test by anand chawala

 
Ranch Hand
Posts: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question for Java Beans.
The contents of beans class are as follows:-
package projsp;
public class trying
{
private String name;
private int age;
public void setName(String n)
{
name=n;
}
public void setAge(int a)
{
age=a;
}

public int getAge()
{
return age;
}
public String getName()
{
return name;
}
}
The contents of test.jsp file are as follows:
<%@ page language="java" import="projsp.*" %>
<jsp:useBean id="test" class="projsp.trying" />
<html>
The Name is <getProperty name="test" property="name" />
The Age is < jsp:getProperty name="test" property="age" />
</html>
If a user types in http://servername:8080/test.jsp?name=Anand&age=22 the out put is
Options given are:
1.Name is Anand
Age is 22
2.Name is Null
Age is 0
3.Name is Null
Age is Null
4.It gives a compilation error as the roperties are not set prior to retrieving them

The correct answer given is 3.
But When I tries the above example on my PC using tomcat4 I got the result as
The Name is
The Age is 0
so What exactly is the correct answer? is it 2? if I consider blank is null?
thanks,
Trupti
[ November 09, 2002: Message edited by: trupti nigam ]
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I haven't tried the example but it seems to me you're right. A primitive instance variable is instantiated with the default value for it's type.
Anand was wrong.
Adrian
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ranchers,
I was shocked with this question. Primitive int members take a default value 0 and objects null. Unfortunately the question maker is mistaken. I think its only a slip of question making.
Thanks
 
Is that a spider in your hair? Here, threaten it with this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic