Java or C++ for Game Programming?

Discussion in 'Computer Science & Culture' started by mmatt9876, Jun 23, 2016.

  1. mmatt9876 Registered Senior Member

    Messages:
    846
    Between Java and C++ which of these two languages is better for game development? I am a beginner hobbyist programmer who knows a little bit of Java and C++ so far. I want to make my own 2D games, to start off with, and then create my own 3D games after I have some experience making 2D games.

    If you guys know of any better languages for game programming than Java or C++ please let me know. (I have heard of other computer languages like Python, Ruby, and JavaScript being used for game development but I do not know if they are better than Java or C++ for game development)
     
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. Edont Knoff Registered Senior Member

    Messages:
    547
    I like Java better, but I have used both for game development. They are different but it's really hard to label one "better" unless there are more constraints known which will help to select the one or other.

    Games have been successfully developed using a number of programming languages, so it seems the question is too broad to have a distinct answer. It depends on the type of the game. It also depends on the target hardware for the game. It also depends on the methodology you want to use. Functional, procedural, object oriented or something else.

    Why I like Java (all very personal).

    - Easier debugging (in my opinion)
    - The JDK includes a lot of very useful libraries (packages), e.g. for networking
    - The same "binary" (class files) can be run on different platforms if there is a Java runtime for that platform
    - Usually the "binary" is very compact, since much code is part of the runtime.
    - Less syntax options, thus code from different sources is more similar and easier to read.
    - I like the garbage collection feature of Java, but I know at least as many people dislike it.

    C++ benefits, as I see them:

    - In some cases, better performance, or, better ability to write high performance code
    - Lots of C++ game programming examples available
    - Templates and preprocessor allow some very "magic" tricks to expand the language
    - With Boost, a set of very good and portable libraries is available
    - If you plan on getting into the game development industry, C++ is a better start than Java.

    The use of Ruby or Python for game development shows that performance is not always the key point for game development. So the edge that C++ has there over Java is irrelevant for a number of types of games (and you can write code in Java that comes very close in performace to even good C++ code - examples of horrible slow applications exist in both Java and C++).

    If you want to make games quickly, independant of a programming language, look at tools like Game Maker, or game engines, like Unity. These include a lot of boilerplate code and free you from the grunt work, so you can focus on the actual game more than e.g. graphics, network or sound programming - they provide that for you readily.
     
    Last edited: Jun 23, 2016
    mmatt9876 likes this.
  4. Google AdSense Guest Advertisement



    to hide all adverts.
  5. Dr_Toad It's green! Valued Senior Member

    Messages:
    2,527
    I know a couple of folks who use Unity. You might give that a shot.
     
    mmatt9876 likes this.
  6. Google AdSense Guest Advertisement



    to hide all adverts.
  7. mmatt9876 Registered Senior Member

    Messages:
    846
    I want to develop iOS, Android, and Windows games. I prefer to use object-oriented languages. I am also a beginner programmer.
     
  8. mmatt9876 Registered Senior Member

    Messages:
    846
    Unity uses C#, right? Can one program games for iOS, Android, and Windows using C#?
     
  9. Edont Knoff Registered Senior Member

    Messages:
    547
    I know little about iOS. The Java runtime for Android has performance issues, so much I gathered from some talk in forums. There are Java based games for Android, but it seems, one needs a bit of extra knowledge to get around a few performance pitfalls.

    This place knows it all about game development in Java. There are some very skilled people there.
    http://www.java-gaming.org/

    Usually I focus on Windows and Linux - even that can be tricky at times, because Linux has different fonts than Windows, and if you design the UI on Windows, chances are that the texts will be clipped on Linux, it has wider fonts in average.

    So even if you can use the same binary to run on different platforms, there are still some pitfalls ... in case of C++ you'll have to deal with different compilers, different make/build systems on the different platforms, that can be a can of worms, too.
     
  10. mmatt9876 Registered Senior Member

    Messages:
    846
    Because Java can have performance issues with Android what computer languages would you recommend for Android game development?

    Thanks for the link. I am pleased to see there is a newbie section.

    How does Linux compare to Windows and Mac? Does it run better? Is it more secure?

    C++ is probably more complicated to set up and use on different computers than Java, with all the thing that you have mentioned before taken into consideration.
     
  11. Edont Knoff Registered Senior Member

    Messages:
    547
    Since MacOS X, MacOS is a unix derivative too, so it's mostly customizations and UI that make the difference between MacOS and Linux these days.

    I'm using Windows 7, Windows 10 and Linux Mint 17, and all systems look very usable to me. Vendors tend to support Windows first, sometimes exclusively, so at times you're just out of luck with some exotic hardware and Linux. Some popular software is Windows-only, but some programs are Mac-only and some are Linux-only, so it's hard to say one system is better than the others in general, but if you need one of those applications there is little to do - you need the OS it runs on. At times I'm running a virtual machine with Linux on a Windows host, this way I can use programs on both OSes at the same time.

    There are very lightweight Linux distributions, which run better on older hardware than e.g. Windows 10, but then again, it's more a configuration thing than an intrinsic advantage of Linux. On the other hand, you can't trim down a Windows 10 this way.

    Linux can be hardened to a very secure system, but afaik this can be done with Windows, too. Linux servers are often considered to be more secure, but they have been hacked too. My understanding is, that 95% of security are administrative things, make sure files/fodlers are only readable to the users/groups that really need access, have processes run on the lowest possible privileges and such - the lower the privileges of a hacked process the smaller the damage a hacker can do, same for files, the less parts of the system a hacker can read and write too, the less damage they can do - at least you can make the hackers lives way harder this way.

    Linux servers are attractive to hackers, so those are more under attack. On the desktop Linux hasn't been a prime target for hackers so far - since it has something like 5-10% of desktop installations, hackers tend look for hacks that work on more installations, and those are typically Windows PCs. In addition, Linux comes in many varieties, and this adds an additional challenge to hackers - if he can hack one Linux distribution, chances are that some other distributions don't have the vulnerability that the hacker used.

    tl;dr - Use the system that you like best, or which runs the software that you need. All the other factors are relatively minor.

    I don't develop software for Android, so I can't help there. Wikipedia says, Java is the first choice:

    https://en.wikipedia.org/wiki/Android_software_development

    And https://en.wikipedia.org/wiki/Android_software_development#Third-party_development_tools
     
    mmatt9876 likes this.
  12. Bowser Namaste Valued Senior Member

    Messages:
    8,828
    If I were to try it again, I would be programming for Android phones, which, I believe, use Java as the programming language. C++, in my opinion, is best for large projects. Check out the below link...

    https://netbeans.org/

    Everywhere I go, people seem to have their faces pointed at their phones. I think you will find a larger audience for your games there.
     
    mmatt9876 likes this.
  13. mmatt9876 Registered Senior Member

    Messages:
    846
    I have been thinking about downloading and installing Linux Ubuntu alongside Windows 10 on my PC. I like that Linux Ubuntu is a user friendly, secure, well updated, and free OS. I could do my Java and C++ programming on Linux Ubuntu, right?
     
  14. mmatt9876 Registered Senior Member

    Messages:
    846
    The iOS market is another popular market. If you learn the Swift language you can program apps for iOS. I believe you can code in Swift using Mac or Linux Ubuntu.

    https://swift.org/
     
  15. Edont Knoff Registered Senior Member

    Messages:
    547
    Yes definitely. The netbeans IDE that Bowser mentioned can be used for both, and it's available for Linux. I'm using it on Linux Mint (which itself is based in parts on Ubuntu).

    You don't need that though. gcc/make are the traditional tools for development on Linux. I like Netbeans, but it is by no means the only choice.
     
  16. mmatt9876 Registered Senior Member

    Messages:
    846
    NetBeans looks cool! Right now I am using the CodeBlocks IDE, with the MinGW components, for my C++ programming, and I use the Eclipse Mars IDE for my Java programming.
     
  17. Edont Knoff Registered Senior Member

    Messages:
    547
    On Windows, Netbeans can use MinGW too, so you don't need a new toolchain is you have MinGW already set up. The debugger integration could be better though. Netbeans came from Java development so I assume it still is better suited for Java than C++, but since many years C++ is supported too (and some other languages).
     
  18. mmatt9876 Registered Senior Member

    Messages:
    846
    I will try out NetBeans sometime for C, C++, and Java programming. I like CodeBlocks for C and C++ because you can download and install CodeBlocks with the basic MinGW components set up and ready to use. Do you have to set up MinGW in the NetBeans settings before coding in C or C++ or does MinGW set itself up after you install NetBeans, with the basic MinGW components already installed on your hard drive beforehand? (Sorry for resurrecting this topic, I had some conversation to add.)
     
  19. mmatt9876 Registered Senior Member

    Messages:
    846
    I installed NetBeans with JDK 8 and I and now I can program in Java! Now I just have to figure out how to code in C and C++ with NetBeans.
     
    Last edited: Dec 29, 2016
  20. mmatt9876 Registered Senior Member

    Messages:
    846
    If you want to code an Android game and you do not know Java then you can code it with C# using Visual Studio. I am not sure how the process of converting C# to Java works however or if you need to know Java to fix bugs.
     
  21. professorpunctual Registered Member

    Messages:
    15
    To me it's a bit of a coin flip, I've used both for game programming in the past. I would say both are fine. Try out both and see what you prefer.
     
  22. mmatt9876 Registered Senior Member

    Messages:
    846
    Thanks for the suggestion! I think C++ is more widely used for game programming but Java may be easier to create some types of games. I think you can create good 3D games with both languages but I think using C++ with DirectX gives you more power.
     

Share This Page