• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

can anyone explain me what is happening here

 
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is from abhilashs quiz

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 error - implimentations can never be native.
2. Compilation error - method not found in local libraries.
3. Runtime Exception - method not found in local libraries.
4. Compilation successfull but runtime error is thrown if and only if the method someMethod of class One_impl is called.

i dont understand native....
 
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe it is 4, but I don't think this topic is covered that much on the SCJP. According to my K&B book for the SCJP 5, you just need to know that the native modifier is a modifier, a reserved keyword, can only be applied to methods, and its body is a semicolon indicating there is no implementation.

Edited out something I had incorrect. My apologies.
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java.lang.UnsatisfiedLinkError: One_impl.someMethod()
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankur kothari wrote:i dont understand native....


Native methods are methods that are not implemented in Java, but in some platform-specific way (for example in a platform-specific library such as a DLL, written in C, C++ or some other programming language).

The compiler won't complain when you compile this (try it yourself!), but if you try to run the compiled program and the Java runtime environment cannot find the native method in any platform-specific library, you'll get an UnsatisfiedLinkError.

You can write native methods yourself using JNI.
 
Everybody's invited. Even this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic