• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

doubt with static block?

 
Ranch Hand
Posts: 74
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone,

here i'm going to share one question about static block , actually when i wrote a class having static data member declaration and when tried to disassemble the code by using javap tool then i got something confusing ....let me first write a sample code then you guys easily able to aware about my issue..

here i'm writing one Test class which have a static data member declaration only..

and now here,after disassemble the code using by javap is...

here is fine i have no question regarding above but when i have bellow code.


then after disassembling the above code i found following.

it insert static block here so i'm a bit confused that's why i have a question in my mind that...
1- it is ok, if we do't write any constructor in a class then by default compiler insert a default constructor
2-so can we say here that compiler also insert a static block in the case of static data member declaration with assignment but when i decompile the code and i saw that compiler is not doing this thing
3-only in the above mention condition means if any class having static data member declaration ,disassembler shows the static block.
4-so what is mean here to insert static block and who is responsible for compiler or disassembler(javap)??
please clear my doubt with your valuable answers..
-----------------------------------------
vivek
 
Greenhorn
Posts: 9
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vivek,
I think it is obvious. Static blocks are used to initialize static members of class. It is the first thing to be executed, so when you write -- static int x=10; it is initialized with static block.

 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should not try to learn anything from decompiled code. Who know what relationship it will have to the original code.
 
reply
    Bookmark Topic Watch Topic
  • New Topic