Java Foundation--native Keywords

Source: Internet
Author: User

One: Native statement

Native is a keyword in java. It is generally declared locally, and is implemented offsite with C and C + +. Its statement has several points to note:

1) The relationship between the native and the access control is not restricted.

2) must precede the return type.

3) It is generally a non-abstract class method.

4) The native method is implemented in an offsite manner, like an abstract method, so there is no method body, ending with a semicolon . such as the following 5 types of statements:

Native public void f (); That's right.

Private native void F (); That's right.

protected int native f (); Error, return type position is incorrect, return type must be after native.

public abstract native void F (); The native must not be abstract.

native int f () {} error because the method body {} exists

public static native F (); That's right. Static and native methods are positioned arbitrarily.

Two: Jni is a Java Native interface (Java Native Interface) and is a native programming interface that is part of the Java Software Development Toolkit (Java Software Development kit,sdk). JNI allows Java code to use code and code libraries written in other languages. The invocation API (part of the JNI) can be used to embed a Java Virtual machine (JVM) into a native application, allowing programmers to invoke Java code from within native code.

1. Encapsulate all your local methods into a class that calls a single DLL. For each target operating system platform, you can use a DLL that is specific to the appropriate platform version. This minimizes the impact of native code and helps to take into account the migration issues that are needed later.

2. The local method is as simple as possible. Try to minimize the reliance of your local methods on third-party (including Microsoft) run-time DLLs. Keep your local methods as independent as possible to minimize the overhead required to load your DLLs and applications. If a runtime DLL is required, it must be supplied with the application.

The following are the steps to write JNI:

A. Writing a Java class with a native declaration method

B. Compiling a Java class using the Javac command

C. Use JAVA-JNI * * * * to generate a header file with a suffix of. h

D. Implementing local methods using other languages (c, C + +)

E. Generating a dynamic-link library of files written by local methods

Java Foundation--native Keywords

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.