+ 1
Why java file name should be same as class name?
3 Answers
+ 2
Hi Gaurav,
I am not that deep into Java programming but after all naming conventions are mostly there to help you and other fellow coders to easily anticipate the role parts of your projects play.
Following the file name = class name convention, everyone knows, that she / he will find the class in that file.
In many languages classes are written in CamelCase, so everyone knows that's a class and of the suddenly a varables comes with the first letter in lower case like camelCase, it's clear that this is an instance of that given class.
Have a nice day.
PS: Here is, what Oracle says:
"""
Naming conventions make programs more understandable by making them easier to read. They can also give information about the function of the identifier-for example, whether it's a constant, package, or class-which can be helpful in understanding the code.
"""
Source: https://www.oracle.com/java/technologies/javase/codeconventions-namingconventions.html
+ 1
JVM search first that class in the code file. If it don't have then it won't compile. Java program starting point is the main method.
JVM compile a code of the file and creates a dotclass file of that class with that file_name.class now this file will be interpreted for execution and java start at execution from main method so it shloud contain the main method otherwise it error.. So we shloud save file with a class name which have main method. If the class does not contain main method then it complies but don't run...