I'm using Java/Eclipse, and I wonder how to check how the methods do things.
Like, when I write
Math.sqrt(16)
It returns the value 4, but how? How does this method actually do that? What's the logic behind it? Is there a way to look them?
I'm using Java/Eclipse, and I wonder how to check how the methods do things.
Like, when I write
Math.sqrt(16)
It returns the value 4, but how? How does this method actually do that? What's the logic behind it? Is there a way to look them?
If you using any kind of IDE like InteliJ IDEA or Geany, you can simply have access to a imported or in-built method by clicking on the method name while pressing the control(CTRL) key. Then you can see what is inside that code. If there are more methods in that code, do the same for them too. Then you will be able to understand how that method is working.
When considering it in Object oriented programming for your example, here we didn't create a object to work the method. It means Math class has a static method named sqrt which can take a number as an argument and its return type is declared as number too.
The standard library is implemented within the JDK. OpenJDK is under the GNU general public license, and it is the implementation of the JDK upon which most other implementations are built. You can find its source code on GitHub here. It's a bit difficult to navigate, but the implementation of the sqrt
function can ultimately be found here. It is extensively documented. More information about the sqrt
implementation and other Java math implementations can be found within the answers to this question.