• 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 method

 
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
native method won't have body, it can't be declare in Interface
native Indicates a method is written in a platform-dependent language,
such as C.
can anybody tell me how to use it and what senerio it is use?
K&B book say "Interface methods can�t be native, static, synchronized, final, private, protected or abstract. They are implicitly public, abstract and non-static."
[ July 19, 2007: Message edited by: Aaron Raja ]
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Aaron Raja:
...can anybody tell me how to use it and what senerio it is use? ...


These details are outside the scope of the SCJP exam. For the exam, you basically need to know that native methods have a body defined outside of the JVM (typically making them platform-dependant). A library with native code is loaded via System.loadLibrary("library_name"), and must be available to the JVM at runtime when the method is called. Since "native" has to do with implementation, it cannot be used with abstract methods.

To get an idea of how this might work (and again, this is more than you need to know for the exam), see this topic in the intermediate forum.
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Aaron Raja:
... Interface methods can't be native, static, synchronized, final, private, protected or abstract...


Correction: Interface methods are abstract. (The keyword can be used, but is not needed because it's already implicit.) Also, add strictfp to the list.

Note that the above restrictions result from the need for abstract methods to be implemented in a subclass. So keywords that dictate implementation (e.g., native or strictfp) or prevent a method from being overridden (e.g., static or final) do not work with "abstract." Also since interface methods are implicitly public, they can't have another access modifier (private or protected).
 
reply
    Bookmark Topic Watch Topic
  • New Topic