Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)
Can anyone help me what are native methods in Java and where we can implement this?

1 Answer

0 votes
by (26.7k points)

Native methods helps you to call a complied dynamically loaded library with an arbitrary assembly code from Java and then getting the result back to Java. This will also helps us to write the faster code on a critical section. You can take a below code as a reference:

public class Main {

    public native int intMethod(int i);

    public static void main(String[] args) {

        System.loadLibrary("Main");

        System.out.println(new Main().intMethod(2));

    }

}

I hope this will help.

Want to know more about Java? Prefer this tutorial on Learn Java.

Want to become a Java Expert? Join Java Course now!!

Browse Categories

...