In: Computer Science
we discussed how C library translates a C lib function such as open to sys_open. It is easy to understand how this works for a C program. However, does this still apply to Java programs? State your reasoning with evidence.
Yes, this also applies to Java Programs as well because system calls are the only way that an OS allows access to any program.
The standard pattern says that some methods in a Java class are
labelled as "native"
. When the JVM meets a call to a
native
method, JVM calls into C/C++ code that is part
of the JVM executable. The native method is implemented in the
following way:
Parameters or arguments from Java, translated into C / C++ compatible form.
Call to the standard C / C++ library function with the parametsr/arguments it needs.
The library function makes a syscall.
The Operating System does its work and the syscall returns.
The standard C / C++ library function returns.
The native method implementation translates the results into Java objects and returns them to the caller of the Java method.
When applied to Java, this is the reason why some OS-specific features show through, A Java program developed on the windows platform, may fail on the Linux platform (Though it is not always true).