aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes abstract 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 "abstract native" Watch "abstract native" New topic
Author

abstract native

Ram Reddy
Ranch Hand

Joined: Feb 20, 2007
Posts: 88
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?
Chandu Sree
Greenhorn

Joined: Oct 04, 2007
Posts: 22
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

Joined: Feb 20, 2007
Posts: 88
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
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18117
    
  39

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 ]

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Kelvin Chenhao Lim
Ranch Hand

Joined: Oct 20, 2007
Posts: 513
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.


SCJP 5.0
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: abstract native
 
Similar Threads
Native Methods.
One more from Khalid
interface and abstract methods.
Confusing SCJP question!
Questions on for Kathy Sierr or Bert Bates