Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > method

Reply
Thread Tools

method

 
 
fattaneh
Guest
Posts: n/a
 
      08-28-2011
hi everybody
is every body knows which method executes before main() and static()
 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      08-28-2011
On 8/28/2011 11:03 AM, fattaneh wrote:
> hi everybody
> is every body knows which method executes before main() and static()


Your question is unclear, and suggests a good deal of confusion.
I'll try to clear up what I think may be confusing you -- but, of
course, I may have misunderstood your misunderstanding!

First, "which method executes before main()." Be aware that there
may be many main() methods in a single Java program: each class can
supply its own, and there are usually many classes. Also, since
`public static void main(String[] args)' is a `public' method, that
means any code in any class anywhere can call it, perhaps more than
once. So there is no single answer to "which method executes before
main()," because many methods may do so, many times.

But let's consider "the" main() method, the one belonging to the
class you told the Java run-time to load and execute. The run-time
performs its own initialization (exactly what goes on is unspecified,
and varies from one JVM to the next), then it loads the target class,
then it initializes the target class, and then it calls the main()
method of that class. The steps involved in getting a class ready to
run are described in the Java Language Specification and the Java
Virtual Machine Specification. Those documents contain a lot of detail,
but the brief summary is: The JVM finds the class' byte code (perhaps
by looking on the hard drive or fetching it from a network connection
or in some other way), verifies the byte code, resolves references to
other classes (which may involve loading and initializing them), and
runs the class' static initializers (if any).

Second, "which method executes before static()." Java has no
`static()' construct at all, but I imagine you're referring to the
static initializers of a class. If so, the answer is "no method,"
because the initializers execute as part of loading and initializing
the class, and this is done by the JVM and not by any Java method.

If this doesn't help, please post again with a clearer explanation
of what you're trying to find out.

--
Eric Sosman
http://www.velocityreviews.com/forums/(E-Mail Removed)d
 
Reply With Quote
 
 
 
 
Jan Burse
Guest
Posts: n/a
 
      08-28-2011
fattaneh schrieb:
> hi everybody
> is every body knows which method executes before main() and static()


The static initializers are immediately called before the
main() method is invoked for the first time. This might
be long after the class has been loaded, and also by another
thread than the thread that loaded the class.

Accordingly to the JLS an eager calling of initializers
is not allowed. This is in contrast to the linking of a
class which can be done eager or lazy after the loading
of the class and before its initialization.

http://java.sun.com/docs/books/jls/t...on.html#12.4.1

Bye

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      08-31-2011
On Sun, 28 Aug 2011 08:03:56 -0700 (PDT), fattaneh
<(E-Mail Removed)> wrote, quoted or indirectly quoted someone who
said :

>hi everybody
>is every body knows which method executes before main() and static()


Methods called in static initialisers are called first. see
http://mindprod.com/jgloss/initialisation.html

If you asking what happens at the JVM level, a method called clinit
(sp) gets called first. It contains all the static init code.
--
Roedy Green Canadian Mind Products
http://mindprod.com
The modern conservative is engaged in one of man's oldest exercises in moral philosophy; that is,
the search for a superior moral justification for selfishness.
~ John Kenneth Galbraith (born: 1908-10-15 died: 2006-04-29 at age: 97)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
method def in method vs method def in block Kyung won Cheon Ruby 0 11-21-2008 08:48 AM
invoke a method by reflection£¨the method's parameters can not be ArrayList? jerry051 ASP .Net 2 08-02-2005 10:35 AM
BC30289: Statement cannot appear within a method body. End of method assumed. Carlos Oliveira ASP .Net 0 08-19-2004 07:51 PM
Difference between Delete method and RemoveRow method CW ASP .Net 0 04-01-2004 01:07 AM
ASP.NET: BC30289: Statement cannot appear within a method body. End of method assumed. Mike Wilmot ASP .Net 0 12-15-2003 07:49 PM



Advertisments