Advertisement

Java's Weaknesses in Game Creation

Started by August 31, 2018 01:05 AM
11 comments, last by Vaclav 5 years, 9 months ago

I recently transferred to a new college that teaches Java as part of it's Computer Science core classes. I've heard Java isn't that great when it comes to making games, and I was wondering what its weaknesses are compared to more popular game-creation languages, and if any of its weaknesses have a work-around of some sort. Specifically, I'm interested in Artificial Intelligence and Procedural Generation.

Java certainly wouldn't be my first recommendation for game development, but it's not as bad for game development as a lot of people seem to think or make it sound, and you can certainly create games with it if you wish to do so.

Games made with Java include Minecraft, and versions of the Runescape MMORPG prior to 2016 (when the game was largely ported to C++).  A lot of Android games and apps are also written in (or partially written in) Java.  There are engines and frameworks such as jMonkeyEngine and LWJGL available for writing games with Java. 

 

Although there are some specific benchmarks showing otherwise, in general an experienced programmer will be able to squeeze better performance out of C++ than they will from Java.  Because it's standard in the professional world, there are a lot more libraries, engines, tools, and resources (articles, tutorials, books, etc.) available for C++.  As a general preference, a lot of people prefer the more modern design of C# if they want a similar "managed" language.

 

This is honestly a pretty brief answer without a lot of detail, but I hope it helps to give you a bit of an idea. :)

- Jason Astle-Adams

Advertisement

That helps, thank you! Is it just worse because it's slower and has less stuff built around it?

The design of the language itself and the included libraries is also a bit clunky - but that is to at least some extent a matter of personal preference.

Honestly, if you're a beginning programmer, you're not likely to be in a position where you would actually be able to write optimal code in any language for quite some time, and the skills you learn working in Java are largely transferable to other languages.  If you're feeling up to it, you could supplement your learning by self-studying a lower level language such as C++ in your spare time.

- Jason Astle-Adams

I think of myself as a beginner, but since I'm entering level 300 CS courses this semester, I am not as new as others. I am not sure where to place myself in terms of experience. Semi-experienced beginner maybe? I know Python relatively well, and I have basic knowledge such as functions, classes, etc in C++, but I lack much experience or skill in the language.

So far, my crowning achievement is using my own time to write a brute-force voronoi-diagram generator in Python/Pygame. That experience taught me that Python runs very slowly when it has to deal with large data-structures.

By, optimal code, do you mean finding algorithms that run as fast as possible? I am not very good at that yet. Is that why you are suggesting I might want to study C++?

12 hours ago, RidiculousName said:

So far, my crowning achievement is using my own time to write a brute-force voronoi-diagram generator in Python/Pygame. That experience taught me that [I used a bad algorithm.]

Seriously, though, Java is very solid for anything which is not compute-heavy, and even then it can go a long way. Meaning, if you could scale your algorithm's performance up by using SIMD, and that algorithm is critical to your program, you would be better off with using another language, because even the libraries which give you SIMD intrinsics will require a lot of handshaking back and forth as a performance penalty.

If, however, your program is not extremely compute-heavy (e.g. most of the real work done per second is done by the GPU), or if it is heavily I/O bound (e.g. most of the time is spent waiting on the network or on the disk), or you just want to learn Java... use Java. It's a useful, high-composability language, with a very good JIT compiler built into nearly all of its runtimes, and with a very large (if spread-out) community of libraries available.

 

Disclaimer: I learned C++98 and Smalltalk in school, graduated 12 years ago, used Java near-exclusively for all professional and personal projects for 8 years, and am now primarily a JavaScript/WebGL programmer who does C++17 stuff in his free time.

RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.
Advertisement

For things like homebrew, demo, or even entry-level indie games, I think Java is fine for the job. In fact I'd been doing games in Java for quite sometime. 

The most frequent complaint about Java would be the Garbage Collector, which is quite unpredictable when it decided to wake up and work. And when it decides to work, the whole program might stop executing for a while. This is fine for business application, but for game it could cause drop frames.

Another thing would be ... it's a heap-base, reference-heavy languages by nature. That means it's not very cache-friendly. It could suffer from performance hit. Again this is not something I'd care until the problem is apparent. Small/Simple game is fine with Java.

http://9tawan.net/en/

2 hours ago, RidiculousName said:

So far, my crowning achievement is using my own time to write a brute-force voronoi-diagram generator in Python/Pygame. That experience taught me that Python runs very slowly when it has to deal with large data-structures.

Python has no particular problems with large data structures, you should just avoid having to traverse many different objects all the time. Each reference traversal makes a random jump in memory access, and your CPU caches hate it if you do that. CPUs running at 1% of max speed due to lack of data from very slow main memory kills performance in any language.

In addition, brute force trying every combination brings down every program eventually. You can't beat exponential growth in required computing power by finite processing speed. The only question is when does it become intolerably slow. Switching to a better implementation post-pones that point a little bit, but only in small amounts. At some point, even drastic improvements like doubling the processing speed gets completely dwarfed by a small increase (like 1 or 2) in the number of elements to investigate. Exponential growth is really a killer. The only way to win here is by not doing brute force, ie it needs a smarter data structure or a smarter algorithm (or both) so you limit the growth in the amount of work that needs to be done.

 

Python is not the fastest thing on the planet when it comes to running code, but on the other hand, it is often very quick and simple for writing code. (That is, you trade authoring time with processing time.) Python does force you to consider smarter solutions earlier, but picking a different programming language does not eliminate that problem. At best it is a small postponement in problem size before you are forced to do that anyway, exponential growth in required computing power does catch up very rapidly.

I am moderately experienced with Java and I love the language, it is the most popular (arguably) language in the world, has rigid but proper and effective structure, great support and libraries, and honestly the speed thing is a non-issue for 95% of applications. If you are using heavy 3d rendering or very heavy sprite movement densities, you might have some slow downs but even still, tests have shown Java to be very close to C++ in most performance situations. It's true C++ is faster, but honestly, the difference isn't affecting much. 

I myself am just going back to Java for games after having left HTML5/JavaScript browser development. I find returning to Java to be refreshing as the language is structured in such a way that it almost forces me to program well, and quickly tells me when I don't! Instead of some other languages making me debug for 9 hours over a missed parenthesis. 

Let me know how your development goes if you decide to stay with Java and I will help where I can. 

On 8/31/2018 at 4:05 AM, RidiculousName said:

 I'm interested in Artificial Intelligence and Procedural Generation.

As someone heavily into Procedural Generation, I personally think it's just slow.  I used to hate Java when it first came out. This was mainly because some managers where I worked tried to force us to use it for things it wasn't suited for.  Since then I've mellowed on Java a bit and I've seen some pretty good benchmarks for it. 

However.... benchmarks aside whenever I actually try to write some high performance code in Java it ends up being a lot slower.  I generally program in C++ these days and I'm someone that likes to pull out all the stops. This means things like designing heaps and memory management, reference counting systems, yada, yada . I use all sorts of tricks that just aren't available in Java......Bottom line is at the end of the day Java tends to crawl for me.

I know there are a lot of successful applications including certain types of games written in Java. I guess it just comes down to what your needs are. If most of the performance sensitive code comes from external libraries perhaps Java is OK. However if you end up having to code it yourself, IMO using Java is way sub-optimal.

This topic is closed to new replies.

Advertisement