This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Why comment in applet java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why comment in applet java program " Watch "Why comment in applet java program " New topic
Author

Why comment in applet java program

Amey Ambulgekar
Ranch Hand

Joined: Nov 22, 2011
Posts: 36
hello..

i have 2Q's in my mind while studying JAVA APPLET.

Q1) The Q is that in java applet program why we give comment to <applet tag> which is used for HTML ?

example::



Q2) why in applet program we can't have main() method.? what is main reason for that..??

Please tell me.

Thanking you
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3419
    
  12
Amey Ambulgekar wrote:Q2) why in applet program we can't have main() method.? what is main reason for that..??

You can have a main method. It just wont be used as the entry point to the program.
It's a long time since I wrote an applet so I can't remember what the entry point is, but I guess that the reason that it is different to an application entry point is something to do with the way the code is run from the browser.

And can you remove the < > from the title please. It is causing an image to be added instead of the text.


Joanne
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37936
    
  22
I have got rid of the image by changing > to &gt; etc., in the title.
Amey Ambulgekar
Ranch Hand

Joined: Nov 22, 2011
Posts: 36
Joanne Neal wrote:
Amey Ambulgekar wrote:Q2) why in applet program we can't have main() method.? what is main reason for that..??

You can have a main method. It just wont be used as the entry point to the program.
It's a long time since I wrote an applet so I can't remember what the entry point is, but I guess that the reason that it is different to an application entry point is something to do with the way the code is run from the browser.

And can you remove the < > from the title please. It is causing an image to be added instead of the text.


Sir Joanne Neal,

first of all Thank you for quick reply..

and secondly, i have removed < > tag from my subject..ok..

Now well, i got it that, why we don't use main() method in an applet because, it is executed by Browser right..?

and about Q1 why we give comment in applet java program..? and how its is executed.. and where it is define in java.?

Thank you again...
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

Amey Ambulgekar wrote:Q1) The Q is that in java applet program why we give comment to <applet tag> which is used for HTML ?

Some programs, like Oracle's own appletviewer, can use those to open the class without needing an HTML document. For instance, if I make your class public (required for appletviewer) and compile it, I can see the applet by just executing appletviewer MyApplet.java.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4165
    
  21

And as for your first question: Why do you put the Applet tag in a comment in the Java Code:

1- You don't have to do that.

2- One reason you might want to do that is that you can copy the Applet tag code and past it into HTML when you are ready to write the web page where the Applet gets run from.

3- I wouldn't be surprised if some IDEs might be able to find the applet tag in the comment and use it to run tests inside the IDE. But that would be an IDE feature not something that would be needed by the language.


Steve
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3419
    
  12
Amey Ambulgekar wrote:Sir Joanne Neal

I haven't been knighted (yet) and even if I had I'd be a Dame
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37936
    
  22
“There isn’t anything like a Dame” . . . and don’t go calling Joanne Sir
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Rob Spoor wrote:Oracle's own appletviewer

I'll need more time to adjust to saying "Oracle's..." instead of "Sun's"...
Amey Ambulgekar
Ranch Hand

Joined: Nov 22, 2011
Posts: 36
Steve Luke wrote:And as for your first question: Why do you put the Applet tag in a comment in the Java Code:

1- You don't have to do that.

2- One reason you might want to do that is that you can copy the Applet tag code and past it into HTML when you are ready to write the web page where the Applet gets run from.

3- I wouldn't be surprised if some IDEs might be able to find the applet tag in the comment and use it to run tests inside the IDE. But that would be an IDE feature not something that would be needed by the language.


Hello Steve Luke,

Thank you for your reply and i got the answer of that. Thanks again...

but as you said we can write applet tag code in separate HTML file and HTML file will use ".class" of that applet right.?

but if we place ".class" file of that respective applet program in one folder and applet tag code of HTML in another folder . So how linking will take place.? my be by Package or it should be in same folder ..? will it give error about applet java program.. that it is not found or something...

Thanking you..
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4165
    
  21

You can put the applet class file in a different folder than the HTML code. The codebase attribute is a URL to the location where the class files can be found (it acts like the -cp flag for the java launcher. If the applet is in a different folder, then you use the URL to that different folder. Additionally, if your class is in a package then the codebase should be the base of the classpath, and the code attribute should be the fully qualified name (with the .class extension). So if you had an class in package my.package, with the name MyApplet.class, in the relative folder /resources/java/, then your applet tag might look like this:


Read more about the applet tag here: http://www.w3.org/TR/1999/REC-html401-19991224/struct/objects.html#h-13.4
And here: http://docs.oracle.com/javase/7/docs/technotes/guides/plugin/developer_guide/using_tags.html
 
Consider Paul's rocket mass heater.
 
subject: Why comment in applet java program
 
Similar Threads
doubt related to applet and frames
Listeners and Adupters
Using JSObject in Applet
invoke method with reflection
Diff between Thread and Runnable Interface