This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes  how to see the <init> instance initialization method ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark " how to see the <init> instance initialization method ?" Watch " how to see the <init> instance initialization method ?" New topic
Author

how to see the <init> instance initialization method ?

gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 892

i have read that for each constructor there is instance initialization method whose name is <init> and return type is void. i would like to know is there any way to view those instance initialization methods generated from the source file using any tool/command-line or perhaps through IDE?


OCPJP 6(100 %) OCEWCD 6(91 %)
John Jai
Bartender

Joined: May 31, 2011
Posts: 1778
I am not aware of this concept, but can see a <init> and an empty return when I use javap -c option.

Java class:


javap output:
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 892

thanks for the reply John. i read an article on object initialization at http://www.javaworld.com/javaworld/jw-03-1998/jw-03-initialization.html?page=5 . i liked it alot. lets wait for other ranchers if there is any way to view the <init> methods.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16811
    
  19


Not really adding anything to this discussion -- but just want to mention.... that all of these years of using / debugging with Java (and working with lots of stacktraces), I have never thought that there was an "<init>" method. I just thought that is how the stacktrace code shows that you are in constructor code. Oh well.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 3860
    
    1

Henry Wong wrote:
Not really adding anything to this discussion -- but just want to mention.... that all of these years of using / debugging with Java (and working with lots of stacktraces), I have never thought that there was an "<init>" method. I just thought that is how the stacktrace code shows that you are in constructor code. Oh well.

I'd have probably thought the same way, but I was looking something up earlier to today (related to another question here) that made me realise it is real: if you look at
java.lang.Class#getMethod(java.lang.String, java.lang.Class...) you can see that <init> is treated as a special case (i.e. it's a method, but that method will pretend it isn't).
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 892

thanks for the information guys. but if the <init> method is real, which it is then there should be some way to see it ? the original question is still yet to be answered/
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 3860
    
    1

It's real in the byte-code. So the only way to see it is with a byte-code viewer, which is what John showed.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: how to see the <init> instance initialization method ?
 
Similar Threads
how to see the <init> instance initialization method ?
Initialization blocks...
Initializing Sequence
Constructor of Servlet
Difference between init() and init(ServletConfig config) methods