Thread: Java and C++ for game programming

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    18

    Java and C++ for game programming

    I'm taking some java classes right now, and was wondering if I would be able to integrate applications from both languages?

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Yes. Use JNI to call C / C++.
    Mainframe assembler programmer by trade. C coder when I can.

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You can but I would not have any clue why you would want to. If you want to make a game in Java then use Java. If you want to make one in C++ then use C++. I have no idea how using both and will help you.

  4. #4
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Quote Originally Posted by Bubba View Post
    You can but I would not have any clue why you would want to. If you want to make a game in Java then use Java. If you want to make one in C++ then use C++. I have no idea how using both and will help you.
    agreed. And if you just want C++ for the rendering capabilities, there are libraries out there that already implement the JNI bindings for OpenGL.

  5. #5
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Yes except it's probably going to end up faster to have a C/C++ "rendering" library, that calls OpenGL. Since there is probably more calls to OpenGL than the rendering library. Because calls through the JNI adds HUGE overhead.

    You may want to check out Jake2, a Java port of the Quake2 engine. Most of the 40% slowdown is caused by allocations and calling the OpenGL bindings through JNI.

    Either way, I agree with the others. Use C++ or Java, not both . Although it'd probably be cool to write the map editor in Java.
    Last edited by zacs7; 10-18-2008 at 05:24 PM.

  6. #6
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    As long as you use native controls... just please boycott java controls.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  7. #7
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    > As long as you use native controls... just please boycott java controls.
    Second.

  8. #8
    Registered User
    Join Date
    Jul 2008
    Posts
    71
    Howbout the best way to communicate c++ and java program,is it rpc-xml???
    yeah so nobody accuse me of going off topic,hmmm let say i want to create game A in C++ and game B in java..what library should I use so they both talk to each other???
    it's rpc-xml the way to go?

  9. #9
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    No, that'd be extremely slow. Depends on how much, and how frequently you need to send data between A and B.

    The fastest option is still JNI, but it is slow compared to native calls. For example C++ calling a C library function.

  10. #10
    Registered User
    Join Date
    Jul 2008
    Posts
    71
    JNI i guess is the way to go then...
    thanks.

  11. #11
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    I agree with zacs7 in that you want to be making as few calls through the JNI as possible. Although, unlike everyone else, I don't see why you should not use both C++ and Java.

    For anyone wanting to play around with the JNI this Netbeans tutorial got me going with it:
    http://cnd.netbeans.org/docs/jni/beginning-jni-win.html

  12. #12
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Quote Originally Posted by Mario F. View Post
    As long as you use native controls... just please boycott java controls.
    SWT all the way. Native widgets, platform independent, and if a platform doesn't support the widget you want to use it's emulated.

  13. #13
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I agree with zacs7 in that you want to be making as few calls through the JNI as possible. Although, unlike everyone else, I don't see why you should not use both C++ and Java.
    Normally you would choose a language based on how it is going to help you reach your long term goals. I don't see what Java brings to the table in the context of a game that you could not do just as well and faster in C++. Java would certainly bring a lot of GUI functionality, however, most in-game GUIs are either using pure Direct3D or they are using some type of flash API. It may actually take more time to streamline and stabilize a C++/Java game than it would just to do it either in pure Java or pure C++.

    So my question to the OP is what is Java bringing to the table that C++ isn't bringing you. Or on the other hand what is C++ bringing to the table that Java isn't?

    Before you start some mixed language program it might be a good idea to research the pros and cons of doing so. It could save you tons of dev time and a lot of headaches in the long run.

  14. #14
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Yeah, you have a point there. It may not be suitable for the project.

Popular pages Recent additions subscribe to a feed