Firstly, this applies only to public classes; Package-private classes can be included in files of any name. For public classes, this is an agreement, in the same order as placing files in directories that reflect the structure of your packages, and using the extension .java.
This is done so that the Java compiler can find classes without examining all the Java files in the folder.
, : Java , , , , Java . Java - .