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 / May 2006

Tip: Looking for answers? Try searching our database.

two public class in a file

Thread view: 
mantu - 11 May 2006 06:44 GMT
when we write two public class in a single file its give
error.(compilation error)
so,my question is why?what's the region behind this.
Roedy Green - 11 May 2006 18:32 GMT
>when we write two public class in a single file its give
>error.(compilation error)
>so,my question is why?what's the region behind this.

When Java finds a reference to a public class it can calculate what
the name of the corresponding class file is, and look for it on the
classpath.  If it does not find it, it can find the corresponding
source file on the sourcepath.  Without the naming convention it would
have to open every file on the sourcepath looking for it.

What puzzles me is why default scope classes can be packed more than
one into a source file.  How does javac find THEM?
Signature

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

jmcgill - 11 May 2006 18:33 GMT
> What puzzles me is why default scope classes can be packed more than
> one into a source file.  How does javac find THEM?

I'm sure their names map to their source file, just like the class name
ends up doing.
Roedy Green - 12 May 2006 00:18 GMT
On Thu, 11 May 2006 10:33:55 -0700, jmcgill
<jmcgill@email.arizona.edu> wrote, quoted or indirectly quoted someone
who said :

>I'm sure their names map to their source file, just like the class name
>ends up doing.

Not if you have more than one class per file. There is only one file
name and several unrelated class names.  Same package though.

Signature

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

Oliver Wong - 11 May 2006 21:49 GMT
>>when we write two public class in a single file its give
>>error.(compilation error)
[quoted text clipped - 8 lines]
> What puzzles me is why default scope classes can be packed more than
> one into a source file.  How does javac find THEM?

   You'd only have to search a directory, as opposed to the entire
universe.

   - Oliver
Roedy Green - 12 May 2006 00:19 GMT
>    You'd only have to search a directory, as opposed to the entire
>universe.

that would also apply to public packages which are limited to one per
source file.
Signature

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

Jeffrey Schwab - 12 May 2006 01:34 GMT
>> when we write two public class in a single file its give
>> error.(compilation error)
[quoted text clipped - 8 lines]
> What puzzles me is why default scope classes can be packed more than
> one into a source file.  How does javac find THEM?

I can only guess that each file at the package level gets grepped (or
equivalent).  Shouldn't be too bad unless there are bunches & bunches of
classes in the package.  Is there any run-time penalty to this kind of
linear search?
Roedy Green - 12 May 2006 06:27 GMT
On Fri, 12 May 2006 00:34:50 GMT, Jeffrey Schwab
<jeff@schwabcenter.com> wrote, quoted or indirectly quoted someone who
said :

>I can only guess that each file at the package level gets grepped (or
>equivalent).  Shouldn't be too bad unless there are bunches & bunches of
>classes in the package.  Is there any run-time penalty to this kind of
>linear search?

It would have to for each segment of the classpath do a File.list()
with a filter for *.java.  The scan each file for class xxxx to build
a HashMap of where to find what.  It could avoid doing that if all
classes it needs to find are public or have already been added to the
"to compile" list.
Signature

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



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



©2008 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.