• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applet query related to reflection API

 
Manoj Garg
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

1)
As i understand object of Applet class is made using reflection API. Please enlighten me if something wrong i understand.

2)
We can not have every class as Applet because our webserver actually calls these methods so it can't remember all of them. Even it doesn't know your class name... thats why SUN guys made the Applet/JApplet class and you extend it also there are very few methods which you can override in your class and they are executed in a sequence by webserver. Am i correct till here..

Is there any relation b/w reflection APIs and Applet/JApplet class.
Means who remembers the methods(init, start...).

Can i please have a brief description stating the relation b/w reflection APIs and webserver.

Thanks.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Manu", you may have missed that we have a policy on screen names here at JavaRanch. Basically, it must consist of a first name, a space, and a last name, and not be obviously fictitious. Since yours does not conform with it, please take a moment to change it, which you can do right here.

As i understand object of Applet class is made using reflection API.

Probably. The JVM gets the name of the Applet class as a string out of the applet tag, after all. What follows is most likely a Class.forName(...).newInstance() call. I suppose one could call those methods reflection, evee though they predate the Reflection API.

We can not have every class as Applet because our webserver actually calls these methods so it can't remember all of them.

The web server has nothing to do with instantiating applets. It sounds as if you are talking about the JVM running in the web browser. But even then I don't understand what you mean by this.

Even it doesn't know your class name... thats why SUN guys made the Applet/JApplet class and you extend it also there are very few methods which you can override in your class and they are executed in a sequence by webserver. Am i correct till here..

The JVM does know the class name - it's part of the applet tag. Google for "applet life cycle" to find a more in-depth explanation what's going on with the methods of the Applet class.

Is there any relation b/w reflection APIs and Applet/JApplet class.

See my first point. It's very unusual to be thinking or talking about reflection in the context of applet instantiation; what prompted this question?
[ January 02, 2009: Message edited by: Ulf Dittmer ]
 
Manoj Garg
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf, thanks for the response..

I am leaving the concept of reflection apis for the time being.

I accept JVM knows the class name then why do we store the reference of this object in Applet/JApplet class (parent one) and can call only methods which are there in the parent. I beleive we define any new method in our class extending Applet then this is of no use as with the parent reference it can't be called. What is the idea behind that..

The JVM gets the name of the Applet class as a string out of the applet tag so can we as an end user get the actual class name.. It seems answer is not.

Thanks
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why do we store the reference of this object in Applet/JApplet class (parent one) and can call only methods which are there in the parent. I beleive we define any new method in our class extending Applet then this is of no use as with the parent reference it can't be called.

I'm not following your train of thought. What is "the reference of this object" - which reference? which object?

The class extending Applet can indeed define whatever methods it needs to, and your code can call them whenever it needs to do so. Why do you think they couldn't be called? And what do you mean by "parent reference"?

can we as an end user get the actual class name.. It seems answer is not.

A call to getClass().getName() within the class extending Applet will provide you with its fully qualified name.
 
Manoj Garg
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf,

Those methods can be called by my code..thats right..
But i meant to say can they be called as similiar to life cycle methods - init, start, stop, destroy...
obviously our code doesn't call these special methods.. may be they are called by JVM.
But why can't JVM call other methods too?
As i understand this applet object is stored in a reference Applet/JApplet class so call parent class (its done by JVM)
And with the reference of parent you can't call the methods which you don't have in parent class thats called run timing binding as i know.

Please shed some light.

Thanks
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But i meant to say can they be called as similiar to life cycle methods - init, start, stop, destroy...

A method is a method, no matter whether it's part of the applet lifecycle or not. One calls them by getting a reference to an object and invoking them. I guess I'm not understanding what you're getting at.

But why can't JVM call other methods too?

Because the JVM doesn't know about them. As far as the JVM is concerned, it's an object of type Applet, so it can call those methods, but not others.

As i understand this applet object is stored in a reference Applet/JApplet class so call parent class (its done by JVM) And with the reference of parent you can't call the methods which you don't have in parent class thats called run timing binding as i know.

That sounds about right.
 
Manoj Garg
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ulf.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manoj,

You mention the notion of the JVM calling the lifecycle methods of your applet. But in reality, it's nothing so magical as that. The applet lives inside an "applet container", which is these days, generally, the Java Plug-in. At the heart of the Java Plugin is just some plain old Java code which does something roughly like



Maybe this will help you to understand the situation a little better.
 
Manoj Garg
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Ernest!
Really Appreciate this community where we get the answers so quickly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic