- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Why the java file name should be always the same as a public class name?
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" file as such that if we made our program file similar to the class it will be comfortable for us to understand without any ambiguity. We are allowed to use any name for a filename only when class is not public. In the case of a public class, we can’t use a different file name.
- 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 file as classes reside in our program. In this condition, we will not able to easily identify which class need to interpret by java interpreter and which class containing Entry point for the program.
- Related Articles
- Should a constructor always have the same name as the class in java?
- Why the constructor name is same as the class name in Java?
- Can we define a method name same as class name in Java?
- Can a method have the same name as the class?
- Using predefined class name as Class or Variable name in Java
- Why should public wifi be avoided?
- How many public classes of the same name it can have in Java?
- What is the difference between simple name, canonical name and class name in a Java class?
- Can we define multiple methods in a class with the same name in Java?
- Display the package name of a class in Java
- Get the unqualified name of a class in Java
- Get the fully-qualified name of a class in Java
- Get the name of the file and path in Java
- Name the force which always opposes motion.
- Get file extension name in Java

Advertisements