This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
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 Head First Android this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Execution sequence" Watch "Execution sequence" New topic

Execution sequence

Rahul Kumar

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

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

Bye & Regards,

[ 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
It is sorta covered in the JavaRanch Style Guide.
subject: Execution sequence
It's not a secret anymore!