*
The moose likes EJB and other Java EE Technologies and the fly likes interview questions? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "interview questions?" Watch "interview questions?" New topic
Author

interview questions?

kesava chaitanya
Greenhorn

Joined: Aug 20, 2001
Posts: 28
hi
1)I have a stateless Session Bean where I want to do some database manupulations . I use a dataSource for this . Where do I place the code for looking up and getting the DataSource so that my code is most efficient? In which method will u place this piece of code ?
2)A remote method addUserInfo is added to a Session Bean. Size of aLList initialized at the client side before the invocation is 0. public void AddUserInfo(aLList : linkedlist) { UserInfo lUserInfo = new UserInfo(); aLList.add(lUserInfo); } What will be the size of this List after the method is invoked in the client side?
give me detailed explaination?
bye
chaitanya
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

1.setSessionContext() method because this method is called only once for stateless session bean.
2.size will be remain at 0
Originally posted by kesava chaitanya:
hi
1)I have a stateless Session Bean where I want to do some database manupulations . I use a dataSource for this . Where do I place the code for looking up and getting the DataSource so that my code is most efficient? In which method will u place this piece of code ?
2)A remote method addUserInfo is added to a Session Bean. Size of aLList initialized at the client side before the invocation is 0. public void AddUserInfo(aLList : linkedlist) { UserInfo lUserInfo = new UserInfo(); aLList.add(lUserInfo); } What will be the size of this List after the method is invoked in the client side?
give me detailed explaination?
bye
chaitanya


Groovy
kesava chaitanya
Greenhorn

Joined: Aug 20, 2001
Posts: 28
Originally posted by pradeep bhat:
1.setSessionContext() method because this method is called only once for stateless session bean.
2.size will be remain at 0

why the size will remain 0
[ May 10, 2002: Message edited by: kesava chaitanya ]
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

There are 2 cases here:
Ur business methods are defined in local i/f and another case is remote i/f..
case (1)
Local i/f
Objects reference are passed by value. In the method the reference will point to a new object (becoz of key word new) and then u r adding an element to the list..but this object is different from the one present in caller side.. so the size at the client will remain 0..
case 2
..in remote i/f objects are passed by value..
A copy of the list object is made and passed to the remote i/f ..so any changes made in server side will not get reflected in client side

Originally posted by kesava chaitanya:

why the size will remain 0
[ May 10, 2002: Message edited by: kesava chaitanya ]

[ May 10, 2002: Message edited by: pradeep bhat ]
[ May 10, 2002: Message edited by: pradeep bhat ]
sandy gupta
Ranch Hand

Joined: Jan 30, 2001
Posts: 228
Hi there guys,
I think that i understood the problem correctly but still do correct me if i am wrong. Mr. Bhat, wrong when u say that objects are passed by value in the remote and home i/f. It is actually the reference or the handle(pointer in c++) to THE Object that is tossed around(passed by val) and not the object itself. So when u add to a List or whatever that was, the count should increase and after the addmethod is done, if u want to say getCount, it should give u the count++.
Thanks
Sahil


Adios
JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
Why the answer to the first question is not ejbCreate? In Cavaness's "Special Edition, EJB2.0, it says that "we can optionally implement the ejbCreate method; for example, reference to a common resource such as a connection factory object."
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

It is a must to implement ejbCreate method in stateless session bean. U can do the lookup in ejbCreate.
I guess ejbCreate is the right place rather than setSessionContext().
Originally posted by JiaPei Jen:
Why the answer to the first question is not ejbCreate?In Cavaness's "Special Edition, EJB2.0, it says that "we can optionally implement the ejbCreate method; for example, reference to a common resource such as a connection factory object."
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

Hi guys,

In RMI, objects can be passed by value or by reference(when u say by reference, this means ur class implements java.rmi.Remote.. and here comes the concepts of stubs and skeletons..)
1. I/f is remote.
In the problem that we are dealing with the object is a passed by value.. a copy of the list object is made and passed to the remote class..the object at the client and server are no longer same (The object recd at the server side is a copy of the object at the client) so any changes made to the copy will not be reflected at the client simply becuase it is a different object all together ..So size will remain 0(assuming that nothing was added to the list before calling the method)
I hope u understood this.
2.Local i/f
Here when the method is called the reference to the object is passed by value(now both of them refer to the same object.
The number of elements is now 1.
Sorry for my mistake !

QUOTE]Originally posted by sandy ind:
Hi there guys,
I think that i understood the problem correctly but still do correct me if i am wrong. Mr. Bhat, wrong when u say that objects are passed by value in the remote and home i/f. It is actually the reference or the handle(pointer in c++) to THE Object that is tossed around(passed by val) and not the object itself. So when u add to a List or whatever that was, the count should increase and after the addmethod is done, if u want to say getCount, it should give u the count++.
Thanks
Sahil
 
 
subject: interview questions?
 
Similar Threads
detect the session attributes after the session is TimeOut?
relation between backing beans
How can a bean to get a object in application scope
Transaction EJB session bean
Confused ,need some help in coding