Sign in to follow this  

C++ versus Java

This topic is 4597 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have done some programming in both Java and C++. I understand that C++ is supposed to be faster and stuff, but it seems so much more complicated than Java. In the lines of code that I used to make a window pop in C++, I could program a nice little Java program. My main question is: Is C++ really that much better and worth all that extra programming?

Share this post


Link to post
Share on other sites
As usual, it depends on what you're doing. Yes, C++ is much faster, but if all you need is Pong, that's really not an issue. Java is much "cleaner" than C++, but it takes some control from you. Also, if you want to go 3D, Java sucks, unless you use a Java binding of a C++ library or engine, in which case, you are really using C++.

There have been a lot of threads about this topic.

Share this post


Link to post
Share on other sites
It all depends on what you are wanting to do really. Simple trivial stuff like making some GUIs and simple console programs, sure, Java is a lot easier to use than C++. However, let's say you wanted to make a 3d game, would you even consider Java? There are a limitless number of choices avaliable for C++ to do so, in java, all you have is Java3D really. So if you are into games, then yes, C++ is worth all that extra programming and is that much better. But for simple stuff, things like Python are much faster than C++ and Java to get done. It's up to you to get the right tool for the job. Java and C++ are for two different things pretty much. [smile]

Share this post


Link to post
Share on other sites
I think Drew_Benton said it well, its not a matter of being "better" its a matter of picking the right tool for the job. Having said that, I am born and raised on c++ and thus am a little biased. Ive done very minimal java programming, but i remember hearing that java does not support operator overloading, which would make wiriting math intensive things (with your own vector and matrix classes and such) a pain in the ass (just like straight c) cross(&u, &v, &result) is an ugly and unintuitive way to do things, and you need to unroll the order of operations yourself and lay them out line by line. Having said that its a matter of opinion and what suits your project. If you're doing GUI programming, win32 with c++ is going to be a lot of extra work, however there are people who felt GUI programming was needlessly complicated, and out of that need for faster development, has come, mfc, GTK+, .NET, ATL and other solutions.

uh... i rambled and got off topic, but theres my two cents
cheers
-Dan

Share this post


Link to post
Share on other sites
Find a good game library for c++ and it won't seem more complicated. Clanlib is great, but not much for tutorials. The examples are clear though. It takes very few lines of code to get a window up with background. SDL is also good. Try Cone3d's SDL tutorials, but skip the one on fonts and get a font library.

Share this post


Link to post
Share on other sites
I agree that for 3d games, C++ would be better. But I saw a 3d game made in Java. I can't remember what it was called, but it was a project posted by a member of programmersunlimited's forums. It looked like high quality, and he claimed on the terrain demo to get FPS of 80.

Share this post


Link to post
Share on other sites
Java defense mode, activate! :P

Quote:
Ademan555
i remember hearing that java does not support operator overloading


I've managed to get around it pretty well. Mind you I never used it too much in C++, but for all of my math-related purposes, it just hasn't been a significant issue. If it's a really pressing issue that prevents sleep at night, JFront (a preprocessor), which adds operator overloading functionality to Java is kicking around.

Quote:
Original post by Drew_Benton
However, let's say you wanted to make a 3d game, would you even consider Java? There are a limitless number of choices avaliable for C++ to do so, in java, all you have is Java3D really.


Java has plenty of options for 3D, and Java3D is certainly not the most potent. Xith3D is quite popular, as is LWJGL (Light-Weight Java Game Lib). And if you want to go low-level, then the OpenGL bindings are available for Java. If you take a look around, there are actually quite a number of 3D games that are using Java. Not only that, but they run quite nicely. :)

Share this post


Link to post
Share on other sites
Quote:
Original post by Drew_Benton
There are a limitless number of choices avaliable for C++ to do so, in java, all you have is Java3D really. So if you are into games, then yes, C++ is worth all that extra programming and is that much better.[smile]


For completeness sake, that's no longer true. LWJGL provides direct crossplatform native bindings for Opengl, Openal, DevIL, FMOD, and input. It is tailored specifically for games. Tribal Trouble is a 3D RTS built on top of LWJGL. There's also JOGL, JOAL, and JInput, which are all open source Sun projects providing cross platform native bindings to OpenGL, OpenAL, and input. There are also a couple of scenegraph engines around: Xith3D and jMonkey are both Open Source (though in light of the attention jMonkey got at the last GDC there has been some discussion of commercial licenses), and Aviatrix3D is a commercial engine in development (though the site appears to be down at the moment).

There's plenty of Java gaming resources out there, for those who are interested in them. The developers of PuzzlePirates made a chunk of their code available to those who wish to try Java game dev. You can use the released source to develop online 2D Java games for the GameGardens site. PuzzlePirates, a Java MMO, was initially distributed online only but was recently picked up for retail distribution by Ubisoft.

@BobTheElde - you have to be careful with topics like this. Most of the replies you get will be biased one way or the other, and often will be full of misinformation (for example: 'Java is slow' from the C++ camp and 'You don't need to worry about memory management' from the Java camp). Take everything you read with a grain of salt. At the end of the day, getting a product out of the door on time and under budget while meeting performance goals for each supported platform is what is important. It doesn't matter if you use C++, Java, Python, Cobol, or a hex editor. Use the resources you are most comfortable with and which allow you to work most efficiently. 'better' is a relative term, and besides which until you become a seasoned programmer most of what you write will be suboptimal no matter which language you use.

If you are doing this for fun rahter than financial gain, then don't worry about which is 'better'. Use whichwver you enjoy. If you aim to enter into the mainstream game industry one day, C++ is a must in your toolbox - so you ought to start getting used to it now. But don't limit yourself. The more languages you are proficient the more opportunities you will have in the future (and the easier it will be to learn new languages).

No matter what people say on these boards, games can be written in any language these days. When comparing Java and C++, performance 'of the language' isn't something to be concerned with. Performance 'of the application' is what's important. A naive Java programmer can easily create an application with abysmal performance, much more so than a naive C++ programmer. Once you know how to code performant apps in Java (i.e. how to avoid the common pitfalls, understanding that java is not C++ and should not be treated as such) and C++, then the issue becomes more about distribution problems (how to get the latest JRE on the user's desktop), supported platforms (if you want to go to a console, Java is out), and the available toolset (perhaps you want to license an engine that can only be used with C++).

Personally, I think Java is great. I've been using it for several years now for web apps, but I'm still not confident enough to bank a game business on it. If I were able to go retail and sell CDs, I'd do it in a hearbeat, but for online distribution I'm quite worried about how many customers I'd lose because of the overhead of the JRE. ThreeRings has been very successful with bundling the JRE with PuzzlePirates, but I think that's because it's an MMO. Oddlabs is bundling the JRE with TribalTroubal, but I'm not sure how successful they have been with it (it's a great game, though!). I've seen a handful of other indies with Java games, and no bundled JREs, who have had mediocre sales. Whether this is because the the games weren't that great, or the customers lacked the latest JRE and didn't want to download it, or because of the negative myths associated with 'Java', who can say?

I suggest you look at your goals, evaluate things yourself, and go from there. Don't rely too much on what people say on these forums (including my little bit above!). If you want advice, talk to experienced people who use both Java and C++ on a regular basis. Their opinions will tend to be more balanced and less religious than the rest. I also recommend that you take a look at D. It's shaping up to be a nice alternative to C++. Whether it's ready for production use is a matter of opinion - some are putting it to work and others are taking a wait-and-see approach.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:

As usual, it depends on what you're doing. Yes, C++ is much faster, but if all you need is Pong, that's really not an issue. Java is much "cleaner" than C++, but it takes some control from you. Also, if you want to go 3D, Java sucks, unless you use a Java binding of a C++ library or engine, in which case, you are really using C++.


Did you know that there are lots and lots of JNI calls all over the Java libraries. So using your analogy in most of the time you code in Java, you actually code in C! How are you supposed to access graphics hardware without going native? Seen many 3D-games lately which won't use OpenGL or DirectX but run in software mode instead? And no, you don't have to use binding to C++ engines as there are nicely working direct OpenGL bindings for Java and you can create one yourself if you like - but using your analogy OpenGL programming == C++ programming ???

Quote:

in java, all you have is Java3D really.

Now.. are you really really sure about this?
Actually Java3D is one of the worst choices you could make.
JME
Xith3D
AgencyFX
Auriga3D
LWJGL
Java bindings for OpenGL
Tribal Trouble

Come on guys, I'm gonna have to ask you why post at all if you're like 5 years behind the facts? Only thing I missed was the sentence that says Java is interpreted.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Come on guys, I'm gonna have to ask you why post at all if you're like 5 years behind the facts? Only thing I missed was the sentence that says Java is interpreted.


Oh I forgot to mention, Java is also an interpreted language too! [lol] Ok, jokes aside, my Java ignorance has become apparant, sorry about that misinformation. [embarrass] Ok thanks everyone for enlighting me, it's been about a few years since I did do java stuff and last time I did, there was talk about Java3D being the first (and only) 3D java library to use. I guess it's time to get back on track with what Java offers now, consider me enlightened!

Share this post


Link to post
Share on other sites

This topic is 4597 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this