A method that is native
is implemented in platform-dependent code, typically written in another programming language such as C, C++, FORTRAN, or assembly language. The body of a native
method is given as a semicolon only, indicating that the implementation is omitted, instead of a block.
A compile-time error occurs if a native
method is declared abstract
.
For example, the class RandomAccessFile
of the standard package java.io
might declare the following native
methods:
package java.io;
public class RandomAccessFile
implements DataOutput, DataInput { . . . public native void open(String name, boolean writeable) throws IOException; public native int readBytes(byte[] b, int off, int len) throws IOException; public native void writeBytes(byte[] b, int off, int len) throws IOException; public native long getFilePointer() throws IOException; public native void seek(long pos) throws IOException; public native long length() throws IOException; public native void close() throws IOException; }
native
MethodsAdding or deleting a native
modifier of a method does not break compatibility with pre-existing binaries.
The impact of changes to Java types on preexisting native
methods that are not recompiled is beyond the scope of this specification and should be provided with the description of an implementation of Java. Implementations are encouraged, but not required, to implement native
methods in a way that limits such impact.