+ 1

Is it necessary to same the file name and class name in the Java applet program?

20th Feb 2019, 8:40 PM
Gopal Agarwal
Gopal Agarwal - avatar
7 Réponses
+ 3
Gopal Agarwal No, I think not. But maybe it depends also on your IDE. In eclipse main method must be public. And I am not sure if it would be a wise idea to make the main class private and to choose a different file name for the main class. (if it is possible at all)
21st Feb 2019, 9:28 AM
Denise Roßberg
Denise Roßberg - avatar
+ 2
Gopal Agarwal Your main class have to be public. Other classes not. (If you normally use one class --> public / class = filename) http://www.dmc.fmph.uniba.sk/public_html/doc/Java/ch8.htm quote: " Although your applet can have as many additional "helper" classes as it needs, it's the main applet class that triggers the execution of the applet. That initial applet class always has a signature like this: public class myClass extends java.applet.Applet { ... } Note the public keyword. Java requires that your applet subclass be declared public. Again, this is true only of your main applet class; any helper classes you create do not necessarily need to be public. "
21st Feb 2019, 9:06 AM
Denise Roßberg
Denise Roßberg - avatar
+ 2
Denise Roßberg If i do this The program will run but applet will not initialise
21st Feb 2019, 9:52 AM
Gopal Agarwal
Gopal Agarwal - avatar
+ 1
If your file contains a public class, yes. File name and class name must be the same. No public classes --> not necessary. https://www.geeksforgeeks.org/myth-file-name-class-name-java/amp/
20th Feb 2019, 9:33 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
If the class does not public in program then the applet is not initialise. Denise Roßberg
21st Feb 2019, 8:46 AM
Gopal Agarwal
Gopal Agarwal - avatar
+ 1
Output will not appear in applet.
21st Feb 2019, 8:49 AM
Gopal Agarwal
Gopal Agarwal - avatar
+ 1
Denise Roßberg If I do not make main class public And do not keep the file and class name the same. Then will the program run ?
21st Feb 2019, 9:15 AM
Gopal Agarwal
Gopal Agarwal - avatar