• 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

about native

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question 150)
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

Compilation error - implimentations can never be native.
Compilation error - method not found in local libraries.
Runtime Exception - method not found in local libraries.
Compilation successfull but runtime error is thrown if and only if the method someMethod of class One_impl is called.
the ans is 4th. why? i donot know much about native method.is it important in the real exam? if it is ,where can i get the tutorial stuff online?
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as the exam is concerned, I think that you should know the correct way to declare a native method. By providing the native modifier you are saying that its implementation is provided outside the JVM. So the method is declared similarly to an abstract method or interface method (no implementation body).
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to add to Jim's comment. The compiler doesn't look for the implementation of a native method so no error will be raised if the method is declared correctly.
The runtime will not look for a native method until it is explicitly invoked; at which point it will ask the operating system to supply the implementation. If the method is not on the system; a runtime error will result.
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
Co-author Mike Meyers' Java 2 Certification Passport
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic