Does a class need to have the same name as it's file.
Ex. class.mysql.php and inside it having class mysql (same)
Ex. class.fish.php and inside it having class mysql (diff)
Also can the format for a class file name be name.class.php or does it have to be class.name.php?
Thank You
The filename must have the same name as the public class name in that file, which is the way to tell the JVM that this is an entry point. Suppose when we create a program in which more than one class resides and after compiling a java source file, it will generate the same number of the .
Class names are always written in UpperCamelCase . The unqualified class name must be meant literally even without the namespace. Class names must be nouns, never adjectives. The name of abstract classes must start with the word “Abstract”, class names of aspects must end with the word “Aspect”.
In Java, the java file name should be always the same as a public class name. While writing a java program first it is saved as a ". java" file, when it is compiled it forms byte code which is a ".
Class names should be descriptive nouns in PascalCase and as short as possible. Each word in the class name should start with a capital letter, without underscore delimiters. The class name should be prefixed with the name of the “parent set” (e.g. the name of the extension) if no namespaces are used.
There is no link between the file name and the class name, you can name the classes in a file anything you want, have multiple classes or have no classes at all. However, it is a good idea to develop a consistent convention to indicate what the file contains via its file name.
Edit:
See Jason McCreary's answer below as some of these conventions have changed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With