Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

native methods ...?  RSS feed

 
Mahesh Bhatt
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
Can somebody please tell me about native methods. Do we use them in real life programming, if yes, how ?
 
Abdulla Mamuwala
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Prashant

What are native methods ?

Native methods are methods that are implemented in another programming language (such as C/C++ or assembly language).

Do we use them in real life ?

Yes, we do use them in real world programming.
For example, look at the following program,



Now, look at the line that is highlighted, this is the syntax for specifying a native method in Java. We have publicas an access modifer and void because the above method returns nothing.

Now the question is, Why do we use the above native method in the class Calculator ?

Say, you have aldready implemented a matrix multplication function in C language, you do not want to implement it again in Java language, therefore you use the above native method.

Generally, you use the JNI interface to do all the dirty work of calling C functions in Java.

In the world they might be having huge algorithms coded in C/C++ they want to use with Java language, the solution is using native methods.
 
Francis Siu
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are native methods ?
I think that native method which involves the basic function call of the operating system. For example, in C++ or C programming, #include <window.h>, we are using the header file which provides some basic function call(some of these are system call) for us to develop some program.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!