ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

Why we need the java file name and public class name in that file as same ?

user-image
تم إضافة السؤال من قبل Jayakumar P
تاريخ النشر: 2014/03/10
Shashank Gupta
من قبل Shashank Gupta

It is not mandatory to make the file name and class name same but if you make it then it will increase the readability of the code.

Shruti Srivastava
من قبل Shruti Srivastava , Guest researcher , PRI Wageningen University

I was about to say, that it is simply a must. But I looked at the JLS, and it is not that strict. From the JLS's perspective, it is left to the compiler to choose whether to set such a restriction or not.

Practically spoken - common compilers do have that restriction, it's much easier for the compiler to find a compilation unit or for a classloader to find a class file with such a restriction in place.

Shadab Hussain
من قبل Shadab Hussain , Software Engineer , Odesk

Hello JayaKumar,I think this is simply a convention which helps JVM to find the Source Files.This restriction is not by Java Language Specification, its compiler's duty to handle souce code in files. common compilers do have that restriction, it's much easier for the compiler to find a compilation unit or for a classloader to find a class file with such a restriction in place.

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟