File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes about native Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "about native" Watch "about native" New topic

about native

wei liu
Ranch Hand

Joined: Dec 06, 2001
Posts: 56
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 it important in the real exam? if it is ,where can i get the tutorial stuff online?
Jim Hall
Ranch Hand

Joined: Nov 29, 2001
Posts: 162
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).
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
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

Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
I agree. Here's the link:
subject: about native
It's not a secret anymore!