File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why comment in applet java program

 
Amey Ambulgekar
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 3742
16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47216
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have got rid of the image by changing > to &gt; etc., in the title.
 
Amey Ambulgekar
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20368
43
Chrome Eclipse IDE Java Windows
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Steve Luke
Bartender
Pie
Posts: 4181
21
IntelliJ IDE Java Python
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joanne Neal
Rancher
Pie
Posts: 3742
16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47216
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
“There isn’t anything like a Dame” . . . and don’t go calling Joanne Sir
 
Tim Moores
Bartender
Pie
Posts: 2488
4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 4181
21
IntelliJ IDE Java Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic