Jump to content

Couldn't find code reference in Java.

Gat Pelsinger
Go to solution Solved by Ulvhamne,

that native keyword tells you that it's written in a compiled language, such as C/C++. You can probably download the source code to make it available. It might even be written in assembly. 

 

Edit: This might be the code:
https://github.com/openjdk-mirror/jdk7u-jdk/blob/f4d80957e89a19a29bb9f9807d2a28351ed7f7df/src/share/native/java/lang/fdlibm/src/e_pow.c

I just write a normal Java program to display the value of Math.pow(2, 3). I ctrl + left clicked the "Math" text which opened the Math.class file. I went to see the definition of the pow function, but only to find out that it uses StrictMath.class to return the value from there. But in StrictMath.class, the only reference to pow is this code -

public static native double pow(double var0, double var2);
 
Where is the actual code that calculates the power? The is no definition of the function!

Microsoft owns my soul.

 

Also, Dell is evil, but HP kinda nice.

Link to comment
Share on other sites

Link to post
Share on other sites

Is the source code even real? There is always this comment on above that it was decompiled.

Microsoft owns my soul.

 

Also, Dell is evil, but HP kinda nice.

Link to comment
Share on other sites

Link to post
Share on other sites

that native keyword tells you that it's written in a compiled language, such as C/C++. You can probably download the source code to make it available. It might even be written in assembly. 

 

Edit: This might be the code:
https://github.com/openjdk-mirror/jdk7u-jdk/blob/f4d80957e89a19a29bb9f9807d2a28351ed7f7df/src/share/native/java/lang/fdlibm/src/e_pow.c

Link to comment
Share on other sites

Link to post
Share on other sites

On 12/4/2023 at 3:50 PM, Gat Pelsinger said:

Is the source code even real? There is always this comment on above that it was decompiled.

Yes, the source code is real. But a lot of lower level library functions may call though to native code for performance reasons.

 

The JVM does not include source code, so it has to decompile the .class file instead, hence why you see that information. So the code you get may not look exactly like what was written by the developer (e.g. no comments), but it will be equivalent.

 

As was said above, the "native" keyword tells you that the actual implementation is in native code. The class essentially only a acts as an interface between Java and the native implementation.

Remember to either quote or @mention others, so they are notified of your reply

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×