This week's giveaway is in the Java/Jakarta EE forum.
We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line!
See welcome thread
Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why this object invoke this method?  RSS feed

Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is an question puzzled me all the time.The "HelloHome" is a interface extends javax.ejb.EJBHome and this interface has a method "public Hello create()...". The Hello is another interface extends javax.ejb.EJBObject and has a method "public String getHello()...".The HelloEJB is a class implements SessionBean and add a method "public String getHello(){ return new String("hello");" In testing code:"HelloHome home=(HelloHome)javax.rmi.PortableRemoteObject narrow(objRef,HelloHome.class);Hello bean =home.create(); out.println(bean.getHello());".I really don't know why the "bean.getHello()" will work property.Because the bean is a interface and nobody implement it.Does the "home.create()" create a class that implements the "Hello" interface?Someone say that is the J2EE Container implements it.But the method "getHello()" is implemented by HelloEJB other than EJBObject.I think it easy to understand if the code is:
/* in implement class */
class HelloEJB implements Hello......
public String getHello(){
return new String("Hello");
.... ...... ........ ......
/* in testing class*/
Hello bean=new HelloEJB();
/* End */
But mycode doesn't use create method.So I think the "create()" method implements the code I write above and it's the Web Container implements the create method.It's right?Have someone help me?
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!