File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Execution sequence Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Execution sequence" Watch "Execution sequence" New topic
Author

Execution sequence

Rahul Kumar
Greenhorn

Joined: Aug 01, 2006
Posts: 16
Hi all,,


I want to know the execution sequence..

Whethere the sequence i hav written is correct or not..
1) First static variables
2) Static block
3) Main method
4) Non Static variables..

If anybody has any good link kindly share it...


Praveen Babu
Ranch Hand

Joined: Jul 30, 2006
Posts: 138
Hi,

The Sequence is right but there is one more thing you might want to know
that is , after main method the non-static blocks(eg., blocks like {System.out.println();} ) are executed.Also, first the static variables are initialized with their default values(say 0 for int) then static blocks are executed in order of apperance and then the static variables are executed in order of their appearance

See the code below which shows the same.



and the o/p is:

---------- o/p ----------
static one
static two
5
one
three
two
hmm...


Bye & Regards,
Praveen

[ August 10, 2006: Message edited by: praveen babu ]

[ August 10, 2006: Message edited by: praveen babu ]
[ August 10, 2006: Message edited by: praveen babu ]
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
Initialization
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Execution sequence
 
Similar Threads
Constructor
initialization..
Reg. class initialization
Object Initialization
Need Help