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 / First Aid / April 2004

Tip: Looking for answers? Try searching our database.

Compile Order

Thread view: 
LookinBob - 15 Apr 2004 10:50 GMT
If the compiler reads left to right, top to bottom, and every
application needs to have a main method, why is it OK to put the main
method near the end of the program instead of immediately following
the class?

Bob
Christophe Vanfleteren - 15 Apr 2004 11:36 GMT
> If the compiler reads left to right, top to bottom, and every
> application needs to have a main method, why is it OK to put the main
> method near the end of the program instead of immediately following
> the class?
>
> Bob

What makes you think that? That's not how most compilers work. They build an
abstract source tree (AST) which is some internal representation of your
source code. Order in the source code makes no difference for most of these
things.

And wether or not a class has a main method has nothing the do with the
compiler. The compiler doesn't care about that, main is just another
method.

It is the Java runtime (java.exe) that looks for the main method of the
class you tell it to execute.

Signature

Kind regards,
Christophe Vanfleteren

Bryce (Work) - 15 Apr 2004 17:25 GMT
>If the compiler reads left to right, top to bottom, and every
>application needs to have a main method, why is it OK to put the main
>method near the end of the program instead of immediately following
>the class?

Order makes a difference in Delphi... Not Java... Try writing a
function that references a variable, and declare the variable below
the function...

--
now with more cowbell
Roedy Green - 15 Apr 2004 22:33 GMT
>If the compiler reads left to right, top to bottom, and every
>application needs to have a main method, why is it OK to put the main
>method near the end of the program instead of immediately following
>the class?

Because Java is compiled in multiple passes, once to discover the
symbols and discover their types, then another to fix their locations,
then another to resolve the precise offsets for references.  (YMMV).

In Wirthian languages, he wanted one-pass compilation, so forward
references were a problem.  They are not in Java.

You can even do forward references in a primitive one pass compiler,
like Forth, by making notes to yourself about forward references that
need to be patched later as soon as they are known.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.


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.