Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: method Date: Sun, 28 Aug 2011 12:00:15 -0400 Organization: A noiseless patient Spider Lines: 42 Message-ID: References: <8fe8db85-d553-4b7c-90a6-56b9b4b938d9@bl1g2000vbb.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 28 Aug 2011 16:00:52 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="f8igmItKsWs6nM5YanFxAA"; logging-data="2193"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18VYzv3qRbm3O/hlK8dNAFE" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:6.0) Gecko/20110812 Thunderbird/6.0 In-Reply-To: <8fe8db85-d553-4b7c-90a6-56b9b4b938d9@bl1g2000vbb.googlegroups.com> Cancel-Lock: sha1:wrAFC7GlawtTFU4GH6XyKfr2O/o= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7435 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 esosman@ieee-dot-org.invalid