• Post Reply Bookmark Topic Watch Topic
  • New Topic

native  RSS feed

 
Anju sethi
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q.
interface one
{
public void someMethod();
}
public class one_impl implements One
{
public native void someMethod();
}

Assuming that the native method is not provided in any local library, an attempt to compile and run the above lines of code will cause:

1. compilation eror - implementations can never be native
2. compilation error - method not found in local libraries
3. Runtime Exception - method not found in loacl libraries
4. compliation successful but runtime error is thrown if and only if the method someMethhod of class one_impl is called.

Please tell me what is the answer and why
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I do not get why you did not test this by yourself, so I guess there is an underlying question that you did not asked correctly.

This is the output, you can test it yourself...



It happens because you have not loaded the library with the method implementation with System.loadLibrary.

Such a library could be a dll or so file implemented in C/C++ containing the code of someMethod().

You can use javah command line tool to generate the C header files with the necesary definitions to implement the native methods declared in your class in C/C++.

Regards,
Edwin Dalorzo.
[ January 15, 2006: Message edited by: Edwin Dalorzo ]
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this homework of some kind that you should be figuring out by yourself?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!