tag:blogger.com,1999:blog-8712770457197348465.post5121095949259877972..comments2024-03-28T02:47:19.159-07:00Comments on Javarevisited: When a class is loaded and initialized in JVM - Java Examplejavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-8712770457197348465.post-18685852404901590552016-02-02T04:43:55.101-08:002016-02-02T04:43:55.101-08:00For your point : 3) If Class initialization is tri...For your point : 3) If Class initialization is triggered due to access of static field, only Class which has declared static field is initialized and it doesn't trigger initialization of super class or sub class even if static field is referenced by Type of Sub Class, Sub Interface or by implementation class of interface.<br /><br />Readers pls consider below example to help your Natrajhttps://www.linkedin.com/in/natraj-chigarambatla-2719515bnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-9405797888590379192015-10-21T07:26:51.846-07:002015-10-21T07:26:51.846-07:00Hello!
I guess expression "If Class initiali...Hello!<br /><br />I guess expression "If Class initialization is triggered due to access of static field, only Class which has declared static field is initialized and it doesn't trigger initialization of super class or sub class" is not true as it says. Because all super classes will be initialized, but not subclasses.<br /><br />public static void main(String[] args) {<br /> Anonymoushttps://www.blogger.com/profile/09098104491051197546noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-46351042900387789962014-12-27T22:55:30.065-08:002014-12-27T22:55:30.065-08:00In Java, class variables are initialised in the fo...In Java, class variables are initialised in the following order:<br /><br />Static variables of your superclasses<br />All static variables of this class are set to their default values.<br />Static variables, and static initialisation blocks, in declaration order.<br />Instance variables of your superclasses<br />All instance variables of this class are set to their default values.<br />InstanceSARAL SAXENAhttps://www.blogger.com/profile/01084233786047386880noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-6687483149424684802014-05-18T03:09:59.519-07:002014-05-18T03:09:59.519-07:00Very well explained, Javin. But I would like to as...Very well explained, Javin. But I would like to ask "While accessing compile time constant, if class initialization is not triggered, then when and how that constant gets initialized ?"<br /><br />Thanks...Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-22348534541860971252012-07-28T05:51:35.942-07:002012-07-28T05:51:35.942-07:00ok, i'll check it now, thanks!ok, i'll check it now, thanks!micheehttps://www.blogger.com/profile/05937230965190972040noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-7075820621528646912012-07-28T05:35:57.888-07:002012-07-28T05:35:57.888-07:00Thanks michee, Actually child class is same in bot...Thanks michee, Actually child class is same in both class loading example. only modification I did on Parent class on second example is addition of static field "familyName". Regarding ClassLoader one,its little complex topic especially if you want to cover J2EE environment, which is I guess the place where ClassLoader magic lies :), hope to complete it soon. I have recently updated by javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-48623346664284300672012-07-28T05:00:48.607-07:002012-07-28T05:00:48.607-07:00good article, waiting for the ClassLoader one!:)
...good article, waiting for the ClassLoader one!:) <br />ps: you're missing a child class in the last example.micheehttps://www.blogger.com/profile/05937230965190972040noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-43703408291561316612012-07-26T06:04:44.448-07:002012-07-26T06:04:44.448-07:00Very nice blogs and very well understood the syste...Very nice blogs and very well understood the system.Anonymousnoreply@blogger.com