Does anybody know how can we use Java to prepare a C HeaderFile

This is a discussion on Does anybody know how can we use Java to prepare a C HeaderFile within the C++ Programming forums, part of the General Programming Boards category; Hi, This is the first time I post here. I am a regular C++ programmer for the past 4 years ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    4

    Does anybody know how can we use Java to prepare a C HeaderFile

    Hi,
    This is the first time I post here. I am a regular C++ programmer for the past 4 years and currently pursuing my Engg Studies.

    Well, one of my friend knows a bit abt java, and we heard that we could use JAVA to build header files which can be used in C++

    Does anybody know abt it. The Websites we searched, could not come up with something good.

    Plz provide me with some info.

    Thanx

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    What exactly is your goal? What would these header files achieve?
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    4
    Actually, what we wanted is a complete merging of C++ and Java Technology so that we could produce something which C++ and Java could not do it alone. As a matter of fact, we know a bit abt Java and C++ and hence wanted to use both 2 produce something new.

  4. #4
    lyx
    lyx is offline
    Amateur
    Join Date
    Sep 2003
    Posts
    228
    Are you talking of the JNI? I don't know much about it but at least I can say that it is designed to be used with C, not C++. Yet, you can use C++ but you cannot just mix languages functionnalities just like that. For instance, a C++ class could not be used by a Java one, the contrary is possible. However, it is not done in the "natural" way.

  5. #5
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    ... Sounds like a unmaintainable mess to me...

    And, I really don't know if it can be done. Heck, you can't even mix-'n-match header files between two different C++ compilers! (There are multi-platform libraries that work on multiple compilers.)

    You might be able to use a DLL (or other 3rd program) to interface between the C++ and Java parts of the program. I think the DLL could be created in just about any language... Well, I don't know if you can create a DLL in Java.

    [EDIT]
    Here's a crude solution: Put the common-shared variables & "status registers" in a file so that both the C++ and the Java "halves" of the program can access it. Yuch!

    Or, it is possible to put the common-shared information memory. If you know how to write kernel mode drivers (and I don't), it should be trivial to make a bit of memory exclusively available to these two program "halves".
    Last edited by DougDbug; 09-24-2003 at 09:34 PM.

  6. #6
    lyx
    lyx is offline
    Amateur
    Join Date
    Sep 2003
    Posts
    228
    No, I know there's something called JNI (Java Native Interface) which produces headers for C code use. But it is complicated to call only a method of Java in your C code and you cannot use C++ classes in your Java code. (and that because of the non-standard decoration, everyone know...)

  7. #7
    Registered User
    Join Date
    Sep 2003
    Posts
    4

    Concept of JNI

    Yeah, this is infact called the JNI scheme. This technique if exploited could do very well, b'caz the concept of dll is probably not available in JAVA. This may b simply b'caz JAVA being platform independent, could not have such a facility as such concepts cannot work in environments like LINUX, UNIX etc. Further the concept of Kernel programming is quite advanced and not yet known to many (including me). Further, that will b more complicated than JNI.

    It is unfortunate that the transfer of C,C++ header files to JAVA is not possible as it could have been a Jackpot. It would 've been very easy to exploit the Platform Independence of JAVA to promote C,C++ codes.

    Anywazz I hope some1 comes up with a more reliable soln to the problem.

    Arvind

  8. #8
    Registered User
    Join Date
    Nov 2003
    Posts
    12
    You can generate C header files from Java by:
    > javah -jni file
    Where file is your java class file after compiling the java source file.

  9. #9
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Mate this thread is 6 months old. You're living in the past.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C#, Java, C++
    By incognito in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 10-05-2004, 02:06 PM
  2. The Java language is being expanded
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 06-11-2004, 09:07 PM
  3. Java woes
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 07-06-2003, 12:37 AM
  4. How to use Java with C++
    By Arrow Mk 84 in forum C++ Programming
    Replies: 2
    Last Post: 02-27-2003, 03:12 PM
  5. C or Java as a first language
    By CorJava in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 10-23-2002, 05:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21