Error:
class <ClassName> is public, should be declared in a file named <ClassName>.java
Explanation:
The class name of your application, applet, or class is not the same as its filename. The filename of your application, applet, or class source code must be the same as your class name, with a .java extension.
Checklist:
- Did you spell the class name and the file name exactly the same, including capitalization?
- Is the extension of your file .java? Be careful that the extension is not .txt or .java.txt
Example:
With the following statement in a source file named average.java (Note that average starts a lowercase 'a'):
4 public class Average // classname starts with a capital 'A'
...
the Java compiler would generate the following error:
average.java:4: class Average is public, should be declared in a file named Average.java
public class Average
^
In this case, the best solution is to rename the file with a capital A to comply with Java naming conventions.