Hello,

Quick and easy question:

I'd like to learn a little by investigating the source code behind the predefined Java methods/classes/etc. For example, right now I'm learning to work with TreeSet and I'd like to know exactly what's going on behind the class-specific methods such as 'first', 'last', 'pollFirst', 'pollLast', etc.

Is there somewhere I can go to find these? Thank you!

EDIT: Also, while I'm here, what is this statement doing (using a random, probably incorrect line of code as an example)?

Object obj = (Object)toString();

In particular, what does this statement mean exactly?

(Object)

Thanks again!

Edited 4 Years Ago by Syrne: n/a

toString() returns a String representation of the Object it's called upon, or, if you have that code exactly, the toString method from within that same class.
(Object) just parses that what follows to the type Object. since a String (and actually every Java Object) will pass a is-a test when checked for Object, this parse is possible.

toString() returns a String representation of the Object it's called upon, or, if you have that code exactly, the toString method from within that same class.
(Object) just parses that what follows to the type Object. since a String (and actually every Java Object) will pass a is-a test when checked for Object, this parse is possible.

Bump, sorry you answered my second question wonderfully, but I'd still like to know where to find the source code for the predefined Java functions.

Thanks for any further help!

Bump, sorry you answered my second question wonderfully, but I'd still like to know where to find the source code for the predefined Java functions.

Thanks for any further help!

Hmm well, in netbeans IDE i know you can right click on a predefined function->Navigate->Go to Source (Ctrl+Shift+B)

To see the actual source, download the OpenJDK source. The OpenJDK code is functionally identical to that of the new Oracle Java 7.x - for source of Oracle 6.x you may have to go through a hassle to get it.

Edited 4 Years Ago by jbennet: n/a

James not necessary. Professional IDEs like IntelliJ, Eclipse and even NetBeans have option to check on source of even JDK methods calls as cOrRuPtG3n3t!x already indicated for NetBeans.
For IntelliJ it is Ctrl (Windows or Unix)/CMD(MAc OS) + left mouse click on the method. this will open class to which method belongs. If class source code available it will shot it to you, otherwise it will ask if you would like to download it (on temporary cache bases)
I'm sure someone from Eclipse world can chip in and reveal Eclipse way how to get this working

Cheers, never knew that, used it for seeing code of libs i have, never realised it worked on core Java stuff.

Cheers, never knew that, used it for seeing code of libs i have, never realised it worked on core Java stuff.

No problem. They do not teach this stuff at school :)

This article has been dead for over six months. Start a new discussion instead.