aspose file tools*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "about native" Watch "about native" New topic
Author

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 method.is 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: http://aspose.com/file-tools
 
subject: about native
 
Similar Threads
native
native
can anyone explain me what is happening here
interface question
why a runtime error is thrown if and only if the method someMethod of class One_impl