Love all, trust a few, do wrong to none.
Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Anayonkar Shivalkar wrote:Hi,
Perhaps below links might help you:
https://coderanch.com/t/404122/java/java/why-public-class
https://coderanch.com/t/474617/java-programmer-SCJP/certification/Why-there-has-one-only
https://coderanch.com/t/397380/java/java/One-Public-Class-Per-Source
Love all, trust a few, do wrong to none.
Matthew Brown wrote:I very much doubt it's anything to do with performance.
chaitanya karthikk wrote:
Matthew Brown wrote:I very much doubt it's anything to do with performance.
Are you saying it is something related to performance or it has nothing to do with performance.
Love all, trust a few, do wrong to none.
I want to know how it going to make it easy? Can you please tell me Mr. BoswellJames Boswell wrote:Having one class per file makes your classes easier to find and read IMO.
Love all, trust a few, do wrong to none.
chaitanya karthikk wrote:
I want to know how it going to make it easy? Can you please tell me Mr. BoswellJames Boswell wrote:Having one class per file makes your classes easier to find and read IMO.
Steve
chaitanya karthikk wrote:
I want to know how it going to make it easy? Can you please tell me Mr. BoswellJames Boswell wrote:Having one class per file makes your classes easier to find and read IMO.
Steve Luke wrote:
chaitanya karthikk wrote:
I want to know how it going to make it easy? Can you please tell me Mr. BoswellJames Boswell wrote:Having one class per file makes your classes easier to find and read IMO.
If you want to find a public class named some.package.AnImportantClass you know exactly where to find the code for that class: src/some/package/AnImportanClass.java. If you were able to have more then one public class per file, and if you were allowed to name the file whatever you wanted (rather than being forced to name the file after the one public class), then that class could be in any .java file in the right package. You would have to look through them all. Worse: you could write one big .java file which contained all the classes and you would have to look through tons of lines of code to find where AnImportantClass is.
The current mechanism promotes class-independence, makes it easier for us (the humans) to find the class (and as was previously said, may simplify the JVM code required to find and load the intended class).
Love all, trust a few, do wrong to none.
chaitanya karthikk wrote:Okay this makes sense. Suppose if I don't mention a public class, I have an option to save it with any name. What about easy in this case? Will the compiler search through the tons of lines of code?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
No I love java. I just wanted to know what are the reasons behind such kind of rules. If someone asks me the same question I don't want to put a dumb face.Winston Gutkowski wrote:
Speculation of this sort seems kind of pointless, unless you're actually trying to work out how you might fool the compiler. The rules are simple; follow 'em. If you don't like 'em, there are tons of other languages out there.
Winston
Love all, trust a few, do wrong to none.
Love all, trust a few, do wrong to none.
chaitanya karthikk wrote:2. However if class is not declared public the compiler/interpreter has to search for the entry point. So it is better to declare all classes as public in their respective files.
Okay at least the main entry point class must be declared public. Is this okay now?Matthew Brown wrote:Classes should be public or not public according to their requirements.
Love all, trust a few, do wrong to none.
So why would I want to declare a class not public. What difference is i going to make? In other words in what situations one would want to create a not public class? I could not understand this. Can you please explain?Matthew Brown wrote:Classes should be public or not public according to their requirements.
Love all, trust a few, do wrong to none.
chaitanya karthikk wrote:So why would I want to declare a class not public. What difference is i going to make? In other words in what situations one would want to create a not public class? I could not understand this. Can you please explain?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |