Paul Clapham wrote:Well, anything in the Java API which needs to interface with features of the operating system ultimately has to involve native code. And since these features include basic things like working with threads and allocating memory, that means that Java programs couldn't run without using native methods.
"Il y a peu de choses qui me soient impossibles..."
David Jason wrote:For that reason, I think C++, C or even assembly are better because they let you see how things work at low-level or system level.
You also learn things like garbage handling.
David Jason wrote:
The only advantage of java which makes it more attractive would be security and portability ?
"Il y a peu de choses qui me soient impossibles..."
David Jason wrote:
The only advantage of java which makes it more attractive would be security and portability ?
David Jason wrote:For that reason, I think C++, C or even assembly are better because they let you see how things work at low-level or system level.
You also learn things like garbage handling.
The only advantage of java which makes it more attractive would be security and portability ?
Paul Clapham wrote:For example as far as I know, C and C++ accept the operating system's version of floating-point arithmetic without question and don't allow the user to see what goes on inside that. Are there C++ programmers who reject that kind of paternalism and write their own floating-point arithmetic routines?
"Il y a peu de choses qui me soient impossibles..."
Stevens Miller wrote:Now, internal to some of the standard Java classes I suppose it is possible that there are native methods, but I have never found evidence of that.
Stevens Miller wrote:I don't think you can get into the internals of primitive types in Java like that.
Are any of those "real" native methods, Jesper? I don't know much about intrinsics, but the ones I spot-checked (Object.hashCode(), the trig functions in StrictMath) all appear to be built into the JVM, rather than compiled into libraries you load at run-time. There are a few .c and .h files, but those appear to be for startup, not object support.Jesper de Jong wrote:
Stevens Miller wrote:Now, internal to some of the standard Java classes I suppose it is possible that there are native methods, but I have never found evidence of that.
There certainly are. You can find the source code of the classes of the standard library in the file src.zip which is in your JDK installation directory. If you look through those, you'll see that some classes do have native methods.
Those routines do convert bits back and forth to equivalent floating values, but you have to have a bit of faith. The doc on intBitsToFloat, for example, says it will give you "the float value corresponding to a given bit representation. The argument is considered to be a representation of a floating-point value according to the IEEE 754 floating-point 'single format' bit layout." Now, the Java Tutorial does say the primitive values are stored just the way you would expect them to be stored (IEEE 754 is used for floats, for example), so I think you are correct that these conversion routines, in the end, amount to the same thing as being able to change the bits directly. You just have to trust the routine to make it happen the way you expect. (No problem for me, but if someone wants to see what's happening at the hardware or bytecode level, that may not satisfy them.)Jesper de Jong wrote:
Stevens Miller wrote:I don't think you can get into the internals of primitive types in Java like that.
Not as directly as in C (mainly because there are no pointers), but you can fiddle with the bits of floating-point numbers; see for example the methods Float.floatToIntBits() and Float.intBitsToFloat().
"Il y a peu de choses qui me soient impossibles..."
Stevens Miller wrote:Are any of those "real" native methods, Jesper? I don't know much about intrinsics, but the ones I spot-checked (Object.hashCode(), the trig functions in StrictMath) all appear to be built into the JVM, rather than compiled into libraries you load at run-time. There are a few .c and .h files, but those appear to be for startup, not object support.
Jesper de Jong wrote:
Stevens Miller wrote:Are any of those "real" native methods, Jesper? I don't know much about intrinsics, but the ones I spot-checked (Object.hashCode(), the trig functions in StrictMath) all appear to be built into the JVM, rather than compiled into libraries you load at run-time. There are a few .c and .h files, but those appear to be for startup, not object support.
I don't know where those native methods are implemented. If you look into the bin directory of Oracle's JRE for Windows, for example, you'll see that there's a whole list of DLLs there. I guess that the native methods in the standard library are called via the exact same mechanism (JNI) as when you'd create a native method and corresponding native library yourself. There's for example a nio.dll which probably contains native method implementations for stuff in Java's NIO API.
"Il y a peu de choses qui me soient impossibles..."
Jesper de Jong wrote:Ok, but that's a discussion about the implementation details of the JVM you're using. It could very well be there's some optimization in Oracle's JVM, I really have no idea. If you'd really want to know, you could dive into the source code of OpenJDK. But it's not going to be an easy project to comprehend.
"Il y a peu de choses qui me soient impossibles..."
"Il y a peu de choses qui me soient impossibles..."
"Il y a peu de choses qui me soient impossibles..."
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |