• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

native

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this homework of some kind that you should be figuring out by yourself?
reply
    Bookmark Topic Watch Topic
  • New Topic