Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Other JSE/JEE APIs and the fly likes Getting started with JNI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Getting started with JNI" Watch "Getting started with JNI" New topic

Getting started with JNI

Joe Areeda
Ranch Hand

Joined: Apr 15, 2011
Posts: 331

I have a need to use some C libraries that use a proprietary network transfer transfer protocol. So becoming proficient with JNI is in my future.

I've about exhausted my Google skills but I have learned how to pass Java Objects back and forth, I think. I've been working on a few C++ Objects and their Java counterparts.

What I'm missing, or should I say, the most obvious thing I'm missing, is an understanding of the scope of a C++ object and how to keep it across Java calls.

What I'm thinking is to create a Connection object and a BufferedReader object. There may be more than one of these active at a time. There will be a corresponding Java Object and C++ Object so the Java interface is clean and Java-like.

But, how do I give the pointer to these C++ Objects to Java so subsequent calls can refer to them? I assume if I do a new CObject of some sort that that object will live until I call it's destructor.

I would really appreciate a link to something that describes this process, or any advice how to start.


It's not what your program can do, it's what your users do with the program.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10815

Moving to a more appropriate forum where JNI questions are usually discussed

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
I agree. Here's the link:
subject: Getting started with JNI
jQuery in Action, 3rd edition