Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Public Class in a source file

 
Eric Lidell
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Eric Lidell
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ernest and Thomas,
Thanx for the answers.
Simon
 
Eric Lidell
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Eric Lidell
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Joel.
Btw,What does your motto mean?
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roughly translated, it reads:
"How much wood could a woodchuck chuck if a woodchuck could chuck wood?"
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I always thought it was the following.
"How much wood would a woodchuck chuck if a woodchuck could chuck wood?"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic