Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

Why should we give the same name.............

Thread view: 
corejavagroups - 04 Nov 2005 08:47 GMT
In Java suppose we have a  class with class name Example.
In the class we have written the main() method.
when saving the file that contains the source code of class Example
why should we give the name of the file as same as the name of the
class that is as Example.java ?
Roedy Green - 04 Nov 2005 08:56 GMT
On 3 Nov 2005 23:47:37 -0800, "corejavagroups"
<sankar_battula@yahoo.co.in> wrote, quoted or indirectly quoted
someone who said :

>when saving the file that contains the source code of class Example
>why should we give the name of the file as same as the name of the
>class that is as Example.java ?

so that the compiler can easily  find the source code or class files
if some other class references that class.. It needs to see how the
the referenced class is defined to generate code that uses it.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Thomas Hawtin - 04 Nov 2005 09:49 GMT
> On 3 Nov 2005 23:47:37 -0800, "corejavagroups"
> <sankar_battula@yahoo.co.in> wrote, quoted or indirectly quoted
[quoted text clipped - 7 lines]
> if some other class references that class.. It needs to see how the
> the referenced class is defined to generate code that uses it.

And so that us humans stand a chance of finding the right file (in a
sensible period of time and with minimal effort).

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

Roedy Green - 04 Nov 2005 10:05 GMT
On Fri, 04 Nov 2005 08:49:00 +0000, Thomas Hawtin
<usenet@tackline.plus.com> wrote, quoted or indirectly quoted someone
who said :

>>>when saving the file that contains the source code of class Example
>>>why should we give the name of the file as same as the name of the
[quoted text clipped - 6 lines]
>And so that us humans stand a chance of finding the right file (in a
>sensible period of time and with minimal effort).

one thing I find odd is that package scope classes can piggyback on
the source code of a public class.  There is no easy way for javac to
find them. It must go looking in all the *.java classes in a package
directory.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Ross Bamford - 04 Nov 2005 10:28 GMT
> On Fri, 04 Nov 2005 08:49:00 +0000, Thomas Hawtin
> <usenet@tackline.plus.com> wrote, quoted or indirectly quoted someone
[quoted text clipped - 15 lines]
> find them. It must go looking in all the *.java classes in a package
> directory.

I believe that it uses the name of the classes anyway - if you compile a  
source file with three classes, two non-public obviously, you get three,  
properly named class files. I expect it builds up that mapping first, and  
then uses that from there.

AFAIR even 'back in the day' the source naming thing was motivated more by  
consistency and readability (and maybe an easier time for implementors)  
than the need for javac to find sources.

Signature

Ross Bamford - rosco@roscopeco.remove.co.uk

Luc The Perverse - 05 Nov 2005 01:09 GMT
>> On Fri, 04 Nov 2005 08:49:00 +0000, Thomas Hawtin
>> <usenet@tackline.plus.com> wrote, quoted or indirectly quoted someone
[quoted text clipped - 24 lines]
> consistency and readability (and maybe an easier time for implementors)
> than the need for javac to find sources.

Absolutely.   This was a deliberately introduced system to encourage better
styles of organization.

--
LTP

:)
Thomas Hawtin - 05 Nov 2005 04:27 GMT
>>>one thing I find odd is that package scope classes can piggyback on
>>>the source code of a public class.  There is no easy way for javac to
>>>find them. It must go looking in all the *.java classes in a package
>>>directory.

> Absolutely.   This was a deliberately introduced system to encourage better
> styles of organization.

Come to think of it, allowing package private outer classes made more
sense in JDK 1.00. With no nested classes, every class was an outer
class. If you had lots of small classes involved with a single class
implementation then there could have been huge numbers of tiny files,
mostly consisting of import statements.

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

Luc The Perverse - 05 Nov 2005 06:48 GMT
> Come to think of it, allowing package private outer classes made more
> sense in JDK 1.00. With no nested classes, every class was an outer class.
> If you had lots of small classes involved with a single class
> implementation then there could have been huge numbers of tiny files,
> mostly consisting of import statements.

You are not implying that that is better though?

--
LTP

:)
ChrisWSU - 04 Nov 2005 12:59 GMT
What? in a sensible period of time with minimal effort?
oh right this isnt C ;)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.