Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

abstract native

 
Ranch Hand
Posts: 88
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

i declared a method as abstract and native.
But in eclipse i am getting compile time error, native method should be public or protected.

code as follows

package Test1;

public abstract class Parent
{
protected int i = 10;
public void goUpHill(){};

protected abstract native void cImplementation1();

public abstract native void cImplementation3();
}


1) we cannot declare a native method as abstract?

2) but it is allowed me to declare as private method without implementatioin.

private native void cImplementation();

when the implemetation for this provided?
 
Greenhorn
Posts: 22
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

1) Abstract and native cannot be applied together as abstract means its implementations is provided in the subclass(that is no implementaion is provided and next implementing class has to provide) but in case of native ,we mean that implementation is already provided just use it.So there is no meaning in specifying both together.

2)As I said native implementation is already provided ,you can use private modifier to it.

Hope this would help you


Best Regards
 
Ram Reddy
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks chandu.

But can any one tell me how the JAVA API calls the native methods and will be implemented them.?

i am some what confusing about native methods , how java can implement these methods internally?

thanks
 
author
Posts: 23919
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by rami marri:
thanks chandu.

But can any one tell me how the JAVA API calls the native methods and will be implemented them.?

i am some what confusing about native methods , how java can implement these methods internally?

thanks



It's just a different call stack. Normally, methods are compiled to byte codes and it is part of a class. Native methods are different in that they are not directly part of the class -- instead the JVM looks for them, in libraries, which has been loaded eariler.

To write your own native methods, you simply run your java class file (with the native methods specified) through the javah program. This will generate you a C/C++ include file -- which declares the interface for you to code the method in C/C++.

You then compile your function into a share library -- and likely go back to the original class to add a static initializer to load that library.

Henry
[ November 27, 2007: Message edited by: Henry Wong ]
 
Ranch Hand
Posts: 513
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by rami marri:
But can any one tell me how the JAVA API calls the native methods and will be implemented them.?

i am some what confusing about native methods , how java can implement these methods internally?



Hi Rami,

You'll have to read up on the Java Native Interface (JNI) to answer your question. This isn't a simple topic, so here's a link to an old but still useful page describing the basic mechanisms involved:

http://www.acm.org/crossroads/xrds4-2/jni.html

Note that JNI is way beyond the scope of the SCJP, so you definitely don't have to know any of this for the exam.
 
This tiny ad is guaranteed to be gluten free.
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic