File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Public Class in a source file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Public Class in a source file" Watch "Public Class in a source file" New topic
Author

Public Class in a source file

Eric Lidell
Greenhorn

Joined: Jul 02, 2003
Posts: 20
Why should a public class be in a source file having the same name as it is having?
Is it because of Access specification?
saint4u@hotpop.com
Nothing is impossible!
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

It is just a requirement enforced by many Java
compilers (javac included) ; it's not part of the
language definition. It allows the compiler to find
classes that it may need to compile while it's in
the process of compiling another class.
[ July 14, 2003: Message edited by: Ernest Friedman-Hill ]

[Jess in Action][AskingGoodQuestions]
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Ernest is correct. This has been part of the language going all the way back to Oak. It is supposed to simplify dynamic compiling. If you are using a class in your class and that class hasn't been compiled yet, the compiler may be able to figure out where to look for it based on the source name.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Eric Lidell
Greenhorn

Joined: Jul 02, 2003
Posts: 20
Hi Ernest and Thomas,
Thanx for the answers.
Simon
Eric Lidell
Greenhorn

Joined: Jul 02, 2003
Posts: 20
I thought a source(class) had to be compiled already for it to be refered or used by another
class/program.when will dynamic compiling be used?
can u pls give me any example code /scenario?
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1821

Dynamic compiling is used by the compiler, not the JRE. If you write the following:
Test1.java

Test2.java

And then run "javac Test1.java", you will discover that the compiler compiled both Test1 and Test2 classes.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Eric Lidell
Greenhorn

Joined: Jul 02, 2003
Posts: 20
Thanks Joel.
Btw,What does your motto mean?
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1821

Roughly translated, it reads:
"How much wood could a woodchuck chuck if a woodchuck could chuck wood?"
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
I always thought it was the following.
"How much wood would a woodchuck chuck if a woodchuck could chuck wood?"


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Public Class in a source file