• Advertisement
Sign in to follow this  

Java vs. C++ for my game?

Recommended Posts

It seems like this sort of questions is amazingly popular. I see two similar ones just in the first page here.

But I am so excited about this that I'd like to share my own situation and get some personal advice from you in this crucial first step.

Please :)
__________________

I would like to develop my own game. I have a game idea which I like and I am also acquainted with programming to some level.
I am a QA engineer and my boss would love it if I learned Java.
 
My game will be a 2D top view spacecraft fighter. Initially, single player but I have ideas for multiplayer.
Imagine: Asteroids but with capital ships, alien ships, moving between universes.
PROBABLY swap the vector graphics for raster... That rotate and scale as the player is moving around and
zooming in and out.
It will graphically be quite old fashioned. There's a semi-complete game from 20 years ago that inspired me: Hell Fighter
 
I don't know much of any programming language. I use Java here and there but it's mostly googling around for ready code.
 
Do I need to learn C++ or Java?
The upside of Java is that it is going to be useful at work and it is easy to learn and work with.
The upside of C++ - and maybe I am wrong!!! - is that it performs much better and my code will be protected from copying.
 
I fear that eventually I'd have to use C++, because of performance. But how much performance do I actually need?
Projectiles will be plenty and they will be free, with genuine collision detection (not like Warcraft, where projectiles are
merely animation)

Share this post


Link to post
Share on other sites
Advertisement

Maybe start out with Java and eventually port to C++, when game features and load exceed Java's performance limits?

Share this post


Link to post
Share on other sites

Java will be fine for the type of game you suggest. You can probably use that with LibGDX for what you want. https://libgdx.badlogicgames.com/

What about code security? If I keep the game in Java, wouldn't people be able to read the code, clone the game, induce cheats?

Share this post


Link to post
Share on other sites

Sounds like Java is the way for you to go, if it's useful to you professionally then that's a big deal and Java will do the job just fine (do you know Minecraft was coded in Java?). As Kylotan mentioned, look into using LibGDX, it's a game library for Java.

Compiled code security is virtually a non-concern for the vast majority of applications for the vast majority of developers. And because Java is compiled (and so is C++) the original source code is not available to be read. Of course if you go and host your source on github then anyone can see it anyway.

Share this post


Link to post
Share on other sites

And because Java is compiled (and so is C++) the original source code is not available to be read.

 

This is only partially true. You can decompile Java and get something very similar to the original source code. Obfuscating can help, but I don't know how well that works in practice (there are tools for de-obfuscating Java). C++ is, practically speaking, impossible to decompile. You can disassemble it, which could be enough for a cheater, but actually turning the executable back into working code is a huge task that I don't think any cheater will care to try.

Share this post


Link to post
Share on other sites

You can disassemble it, which could be enough for a cheater, but actually turning the executable back into working code is a huge task that I don't think any cheater will care to try.
He/she doesn't need to, the disaasmbly shows the byte values of the program, so you can easily find that in the binary, and change the code by changing that to whatever instruction it should do instead.

Share this post


Link to post
Share on other sites

You can decompile Java and get something very similar to the original source code.

Yes it is true that certain original symbols (e.g classnames and method names) are maintained in the compiled .class files and because Java maps pretty well to the underlying bytecode it means that decompiling bytecode to Java can produce a fairly faithful reproduction of the logic structure.

What I should have been saying is more along the lines of: Because Java is compiled to bytecode rather than interpreted from source, it means the original sourcecode including all symbols, comments, use of generics, etc is not shipped as-is to the client in plaintext for anyone to trivially read in their favourite text editor.

Share this post


Link to post
Share on other sites

It's quite true that via decompilers you can get fairly workable code out of .class (or .dex) files. Which is much better than what you can get from say, a decompiler and a native lib, which basically will just declare a bunch of variables with register names, assemble something resembling a function declaration with a bunch of void*, and call it a day.

With that said, even if you're making a native game, you have to work out a way so the server can verify the information the client is sending. You can't rely in "oh it's a native file so users wont modify it!" and not check what the client is telling you. So whatever you chose, you'll have to do the legwork all the same and make up a scheme that lets you verify what the client is telling you.

Now if the game is single player, do you honestly care that much that people modify the game? Let them eat cake. 

Share this post


Link to post
Share on other sites

I would focus on the game first and not worry about things like security, especially since you are not only learning a new language one way or another, but also since this'll be your first game.

If you feel that Java is more useful to you professionally, then go ahead and use Java. Either language can be used to code a game. There can sometimes be reasons to choose one language over another, but in your case, I don't think those reasons matter much. At this stage, it's more about comfort than anything else. 

Share this post


Link to post
Share on other sites

Yes, I felt that this is the way forward but with all the excitement in my head, I had my doubts. 
It was so amazing to read such cleverly thought out answers to such a personal matter, that you've been asked 100 times this week.

Thank you very much!

Share this post


Link to post
Share on other sites

I would suggest C++. If you're wanting a job later, there's some things to consider. The below quote is from a job recruiter, and based on my professional experience I found this true and helpful in my career, i.e. dropping into unmanaged (native) code for writing performance enhancers where it'd be slow if written in Java/C#, and just being better aware of performance issues (C# and Java's runtimes were built using C++). Those who specialize in C#/Java tend to be limited as sandbox users, though that's fine depending on the project. While reading, keep in mind that C# is similar to Java. If you're just doing this for a hobby and don't plan to do game development or software development, like many here enjoy indie/hobby work, Java is a good choice, and C# is closely related and better coupled with the Windows operating system and has a better JIT compiler for performance. While C#/Java hobbyists might not like the quote, it's not meant to offend, but it's what at least one recruiter looks for. Good luck with your games!

 As a recruiter I look for C++ for several reasons:

0: Employers ask for C++ more than C#, and a lot more than Java.

1: It is evidence that you're smart. C++ is harder than C#

2: It is evidence that you've had a better education, people who do weaker courses do weaker languages, on average.

3: It shows you are a member of the set of people who do things to computers, more than someone who computers do things to. As Daniel rightly says, C++ allows you to hurt yourself badly which is good if you aren't broken by it.

4: C++ is the code they have most of their important work in.

5: C++ is a richer framework in which to express your ideas in code. Fully understand C++ and you understand very nearly everything in Java, C# , VBA et al.

Some employers will accept C# rather than C++, in fact some C# employers ask for C++ when they actually want C#, because on average C++ programmers are so much better clued up. I've even had that for Python developers.

 

 

Edited by redshock

Share this post


Link to post
Share on other sites

 

As a recruiter I look for C++ for several reasons:

0: Employers ask for C++ more than C#, and a lot more than Java.

1: It is evidence that you're smart. C++ is harder than C#

2: It is evidence that you've had a better education, people who do weaker courses do weaker languages, on average.

3: It shows you are a member of the set of people who do things to computers, more than someone who computers do things to. As Daniel rightly says, C++ allows you to hurt yourself badly which is good if you aren't broken by it.

4: C++ is the code they have most of their important work in.

5: C++ is a richer framework in which to express your ideas in code. Fully understand C++ and you understand very nearly everything in Java, C# , VBA et al.

Some employers will accept C# rather than C++, in fact some C# employers ask for C++ when they actually want C#, because on average C++ programmers are so much better clued up. I've even had that for Python developers.

 

Sounds like that recruiter may have been a recruiter for a bit too long, and has become out of touch with the industry. It's true that knowing C++ is a good thing, it's true that knowing the basics of memory management will carry you even still into the realms of writing better managed code. But just because some knows C++, doesn't mean they know how to code well with it.

 

1: It is evidence that you're smart. C++ is harder than C#

 

It sounds like he's never been on our Code Horrors forum.

 

 

2: It is evidence that you've had a better education, people who do weaker courses do weaker languages, on average.

 

I respectively disagree. Once again it sounds as though this recruiter has never been put on a two day deadline to create an app that performs extensive AD automation. C++ compared to something like PowerShell/Python is a nightmare for these tasks. I'm sorry, it is. Different tools for different jobs. Just because your stuck on hammering a nail into the wall with a screwdriver doesn't make the screwdriver inherently a bad tool, it just makes you look like an idiot for using it for that purpose. 

 

 

C++ is the code they have most of their important work in.

 

This is highly subjective. True C++ is a go to language for low-level tasks, but the recruiter makes the foolish assumption that this automagically equals delegation of an "important" workload. This is not always the case.

 

 

5: C++ is a richer framework in which to express your ideas in code. Fully understand C++ and you understand very nearly everything in Java, C# , VBA et al.

 

It also sounds like he's never used anything but C++

 

In summation, the last people you wanna quote are recruiters. Especially this one. C++ has it's purposes, as does Java, as does C#, and as does many other languages. It's legitimately sad to see a recruiter who is supposed to be bringing new blood into the industry has this attitude.

Share this post


Link to post
Share on other sites

Redshock's got some fair points but I think they could be framed a little better...

I would suggest C++. If you're wanting a job later

... in the AAA games industry.
Yes that's true, the games industry is fueled on C++ by and large.

Having said that, the OP did highlight that he already is employed in QA and is looking to do this as a hobby not as a job. So these are maybe not things the OP need worry about right now.
 

dropping into unmanaged (native) code for writing performance enhancers where it'd be slow if written in Java/C#, and just being better aware of performance issues (C# and Java's runtimes were built using C++).

Absolutely, there's no question that knowing C++ is beneficial to a developer for these (and other!) reasons.

At the same time to be a well-rounded and knowledgeable developer it is of the utmost importance to know other languages too such as Java/C#/Python/Scala/F#/javascript/etc. And it doesn't really matter which order these are tackled in.
 

Those who specialize in C#/Java tend to be limited as sandbox users, though that's fine depending on the project.

That is somewhat true depending on how you define 'sandbox' but it's not very limiting in practice unless you're writing something low-level like a driver or operating system.

Even C++ has a logical VM 'sandbox', defined by the standard, and this does not map directly to the underlying physical machine architecture either.
 

If you're just doing this for a hobby and don't plan to do game development or software development, like many here enjoy indie/hobby work, Java is a good choice, and C# is closely related and better coupled with the Windows operating system

I think this is the real take-away point that is on-topic for this thread.
I would just temper it by pointing out that there are many software development opportunities out there for languages other than C++. I myself currently work as a back-end Java developer by day.
 

C# [snip] has a better JIT compiler for performance.

Actually Java's Hotspot JIT uses a lot of advanced techniques to decide what/when/how to JIT. The JIT compiler in .Net is actually comparatively basic. This is an area where Sun/Oracle have invested a lot more time than Microsoft. Microsoft have spent that time building the language itself and the tooling around it. So it's horses for courses really.
 

While C#/Java hobbyists might not like the quote, it's not meant to offend, but it's what at least one recruiter looks for.

Of course! No offence taken. It's just a viewpoint. It's one I happen to disagree with but no reason to take offence all the same.

What I see is actually a very good demonstration that recruiters don't know what they're talking about when it comes to programming. I would not what that guy doing my company's recruitment.

Share this post


Link to post
Share on other sites

Redshock's got some fair points but I think they could be framed a little better...

I would suggest C++. If you're wanting a job later

... in the AAA games industry.
Yes that's true, the games industry is fueled on C++ by and large.

Having said that, the OP did highlight that he already is employed in QA and is looking to do this as a hobby not as a job. So these are maybe not things the OP need worry about right now.
 

dropping into unmanaged (native) code for writing performance enhancers where it'd be slow if written in Java/C#, and just being better aware of performance issues (C# and Java's runtimes were built using C++).

Absolutely, there's no question that knowing C++ is beneficial to a developer for these (and other!) reasons.

At the same time to be a well-rounded and knowledgeable developer it is of the utmost importance to know other languages too such as Java/C#/Python/Scala/F#/javascript/etc. And it doesn't really matter which order these are tackled in.
 

Those who specialize in C#/Java tend to be limited as sandbox users, though that's fine depending on the project.

That is somewhat true depending on how you define 'sandbox' but it's not very limiting in practice unless you're writing something low-level like a driver or operating system.

Even C++ has a logical VM 'sandbox', defined by the standard, and this does not map directly to the underlying physical machine architecture either.
 

If you're just doing this for a hobby and don't plan to do game development or software development, like many here enjoy indie/hobby work, Java is a good choice, and C# is closely related and better coupled with the Windows operating system

I think this is the real take-away point that is on-topic for this thread.
I would just temper it by pointing out that there are many software development opportunities out there for languages other than C++. I myself currently work as a back-end Java developer by day.
 

C# [snip] has a better JIT compiler for performance.

Actually Java's Hotspot JIT uses a lot of advanced techniques to decide what/when/how to JIT. The JIT compiler in .Net is actually comparatively basic. This is an area where Sun/Oracle have invested a lot more time than Microsoft. Microsoft have spent that time building the language itself and the tooling around it. So it's horses for courses really.
 

While C#/Java hobbyists might not like the quote, it's not meant to offend, but it's what at least one recruiter looks for.

Of course! No offence taken. It's just a viewpoint. It's one I happen to disagree with but no reason to take offence all the same.

What I see is actually a very good demonstration that recruiters don't know what they're talking about when it comes to programming. I would not what that guy doing my company's recruitment.

 

Good points. C#'s new RyuJIT compiler for 64-bit is quite impressive, but I'm sure Java's has matured over its longer lifetime. 

Share this post


Link to post
Share on other sites

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  

  • Advertisement