Java and C ?

  • Thread starter =?ISO-8859-1?Q?Andreas_R=F8sdal?=
  • Start date
?

=?ISO-8859-1?Q?Andreas_R=F8sdal?=

Hi all,

Is it possible to embed C code in Java? Could I take a simple C source
code, compile it with the Sun Java SDK, and add new Java classes to the
project?

Thanks..

Andreas R.
 
G

Gordon Beaton

Is it possible to embed C code in Java? Could I take a simple C
source code, compile it with the Sun Java SDK, and add new Java
classes to the project?

The Java native interface lets you:

- invoke class and instance methods implemented in C just as if they
were implemented in Java
- embed a JVM into your C application
- create objects and invoke Java methods from C

In either case, it is relatively simple to make calls from Java to C
or from C to Java, although depending on your existing code some
massaging may be necessary.

You use your favourite C compiler to compile your code to a shared
library or DLL. Linking takes place at runtime.

Read about JNI here:
http://java.sun.com/j2se/1.5.0/docs/guide/jni/index.html

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top