Java and C ?

Discussion in 'Java' started by =?ISO-8859-1?Q?Andreas_R=F8sdal?=, Jun 2, 2004.

  1. 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.
     
    =?ISO-8859-1?Q?Andreas_R=F8sdal?=, Jun 2, 2004
    #1
    1. Advertising

  2. On Wed, 2 Jun 2004 15:58:42 +0200, Andreas Røsdal wrote:
    > 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

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    Gordon Beaton, Jun 2, 2004
    #2
    1. Advertising

  3. Andreas Røsdal wrote:
    > 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?


    You can call C code from Java (and Java from C) via JNI:
    http://java.sun.com/docs/books/tutorial/native1.1/index.html
     
    Michael Borgwardt, Jun 2, 2004
    #3
  4. =?ISO-8859-1?Q?Andreas_R=F8sdal?=

    Takeshi Guest

    Do a google search for "SWIG"

    Andreas Røsdal wrote:
    > 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.
    >
    >
     
    Takeshi, Jun 8, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Kintner
    Replies:
    0
    Views:
    861
    Michael Kintner
    Nov 30, 2003
  2. Ilias Lazaridis
    Replies:
    0
    Views:
    593
    Ilias Lazaridis
    Feb 1, 2005
  3. Roberto Faenza
    Replies:
    4
    Views:
    370
    Luc The Perverse
    Feb 25, 2007
  4. manish sahu
    Replies:
    3
    Views:
    1,020
  5. Isaac
    Replies:
    0
    Views:
    385
    Isaac
    Jan 20, 2011
Loading...

Share This Page