Why Is Java’s Use in the Gaming Industry Limited?

Game development is a flourishing industry and Java is not the best choice. Let’s find out why.

May 21, 2021

Gaming as an industry is proving to be an experiment lab for developers with no limits known. With developers rapidly shifting to other development tools, let us understand why there are limitations to the use of Java in the gaming industry from Alex Yelenevych, co-founder and CMO at CodeGym.cc.

Java is a great and versatile development tool. In theory, you can create anything on it. However you won’t find high-profile Triple-A video games made in Java with the exception of perhaps Minecraft. The Java version of Minecraft still exists. Numerous mods are created for it, and this is its huge advantage for enthusiastic players and novice programmers. Nevertheless, the bedrock Minecraft version, rewritten in C ++, is currently being developed most actively. Why is that? Is this the intrigue of Microsoft that owns Minecraft and oversees C++? Not really. In this article, I’m going to explain why Java is in game development, but not as much as it could be.

Gamedev Industry and Programmers

First, let’s talk about the gamedev industry. It’s kind of a specific one, I have to admit. Created for entertainment, it requires very serious work of programmers. Perhaps this is one of the most difficult options for programmers. For many aspects, game developers need to know mathematics and physics, have good scientific intuition, imagination, and be well oriented in multithreading. 

However, times are changing, and development tools are improving. Now there are even no-code solutions that allow people without programming skills to make their own game. At the same time, serious AAA-projects, network or standalone, require huge teams and are developed, and then supported for years as they need very different programmers. 

Learn More: How To Create Optimal Patch Management Experiences Through IT

10 Things Programmers Need in Game Development

1. Game engines: These are special libraries and tools that prescribe the physics of the game, how objects move, what happens when they collide, and so on. 

2. Artificial Intelligence (AI): The creation of computer agents using AI methods (mostly for enemies or NPC behaviour).

3. Graphics and sound programming: Graphics for managing the use of graphics content and computer memory; development of a graphics engine, integration of models, textures for working on the physics engine. Sound for everything about music, voices and sound effects integration. 

4. Gameplay: Programmers implement various game mechanics and features with this gameplay.

5. Scripts: Develop and maintain a high-level command system for various in-game tasks such as AI, level editor triggers, etc.

6.Backend: This is needed for the game with a server part. For example, if you need to organize in-game purchases in the game, and so on.

7. User interface:  These are programming menu items, visual interface, help and feedback system.

8. Work with input devices: Handle and customize how to work with different input devices such as keyboard, mouse, controllers, gamepad, and so on.

9. Network communications: To control the input and output of data for local networks or for the Internet

10. Game development tools: Needed for the production of auxiliary specialized software that accompanies game development, often to help designers and screenwriters.

Learn More: How the Slowdown of Moore’s Law Has Fueled the Rise of Computational Storage

What’s Wrong With Java for Gamedev? The Technical Aspect

Many programmers have heard the expression “Java is slow”. In fact, this is not quite the case for a long time, but there are some aspects that affect the performance of the language:

  • Traditionally for Java, the efficiency of code maintenance is more important than its optimality. And many libraries are written with this idea in mind. Is this solvable for games? Yes, you need to write your own libraries or use productive ones (and they are there too).
  • Java is not as close a friend for assembly language as C or C ++. That is, it is very difficult to attach some low-level functionality to your application for the sake of speeding it up.
  • Java itself is less compact than C ++ and uses more memory.
  • If you are dealing with GPU buffers, then Java does not provide a language feature to help you ensure they are properly locked and unlocked or destroyed, which C ++ does.

Every Java programmer can add a point or a few into this list. However, the biggest problem is usually said to be the non-deterministic garbage collector.

Non-deterministic garbage collector is a necessary price to pay for stable automatic memory management and it is one of the most controversial and changing areas of the Java world. 

The main approaches to garbage collection are reference counting and reachable object graph traversal (mark-and-sweep, copying collection). The first approach has difficulties with circular references, in Java the second is mainly used.

Most collectors rely on a weak generational hypothesis. The hypothesis assumes that young objects die more often. To do this, the heap is divided into regions according to the lifetime of objects — generations. They are garbage collected separately.

An important concept for garbage collectors is Stop The World pause. This is a complete halt of program threads for safe garbage collection and other system operations. It happens in special places in the program called safepoints.

All this means that Java, unlike C++, cannot guarantee the operation time. In Java (such as in Python or C#), at some point, it turns out that too much memory is used, and the garbage collector is called. In all languages ​​that have garbage cleaning, it will happen at the most inopportune moment. Therefore, C++ should be used in code where latency is critical. Also С++ is a solution for efficiency in terms of resource use. If it is possible to make the interface simpler, you can use Java, but for a complex one use C++. 

Learn More: Are Your Data Lakes in Trouble? What You Can Do About It

What’s Wrong With Java for Gamedev? Historical Aspect

In theory, one could “hack” Java, change something in the Java Virtual Machine, take off the garbage collector and use it to create highly productive apps. But why? I remember a few years ago someone made a fast transaction system in Java in a similar way, and it was really fast. However, it was more of an experiment.

There are some historical things in Java that prevent it from becoming #1 for game development.

Patterns: In fact, historically, the paradigms and approaches of Java programming are sharpened primarily for business applications, but not for games. Java evolves and changes, but still, for the most part, it remains within the rigid framework of OOP principles. Games based on C++ are most often written in “C with classes” style due to the criticality of the operation response. It happens, of course, that someone who had Java or C# as their first language enters a С++ game project and applies a “pure” OOP style. Here it’s not so effective, and this is gradually changing. Gamedev has its own patterns, and they are closer to architecture.

As I said above, in Java, the readability and maintainability of the code is valued over its optimized code. In game development, in most game projects, this approach is not suitable.

Gaming platforms: Ironically, the Java slogan “Write once, run anywhere” doesn’t quite work in the world of video games. The most popular game consoles simply don’t have a Java Virtual Machine. There are no fundamental or technical limitations for porting JVM on a console. Architecturally, modern consoles are general-purpose computers. So basically anything that works on your PC should work on a console after porting.

However, game console developers (Microsoft, Sony, Nintendo) most often restrict the use of universal virtual machines on their platforms for security reasons. For example, virtual machines allow you to run code that wasn’t in an executable file. That means it wasn’t tested and approved during game publishing. Also some bugs or vulnerabilities in the virtual machine’s security could put users at risk through poorly validated virtual machine scripts or deliberate hacker’s attacks.

In addition, the virtual machine can also allow users to bypass signature checks. Such checks ensure that only approved software is running on the device, so the platform owner receives a share from it. If something goes wrong, it could threaten the business model of the console manufacturers.

Hence, it is technically possible, but there are reasons why the console makers don’t want to have VM-software on their platforms.

Engines, Tools and Libraries: For C++, in addition to engines, there are a huge number of libraries designed for games. For example SDL (Simple DirectMedia Layer) or SFML (Simple and Fast Multimedia Library). They can be screwed into Java, but working with them in C ++ is much more convenient.

Still, even if C++ is an industry standard, there are not so many games made on pure C++. 

Game engines are the kings today, sometimes even no-coding (or almost no-coding) kind. Among such “kids” can be noted RPG Maker, an engine and development environment. It is very limited, but you can write JavaScript (or Ruby in previous versions) scripts in it to extend the capabilities of the engine. Sure RPG Maker creations don’t shine with graphics or performance, but even a beginner can write a simple game with this tool.  However it is also used for professional development. For example, a long-term construction Omori was released recently, which was developed by a small team for 7 years, and this game has already become very popular on Steam. An even more interesting option is Game Maker Studio with its own C-like GML language.

Or let’s say there is C# language, which in a sense was born out of Java, adopting most of its principles. That means that these languages ​​are somewhat similar. If developers can do something with one, they can do it with another. There is also a virtual machine and a garbage collector. However, game development in C# is going well because there is a wonderful Unity game engine built in C++ and C# and it uses C# for scripring. The best of Unity is the fact that it was made by programmers and for programmers with an understanding of their needs. That’s why Unity has a very convenient settings system and visual development environment. In addition, Unity is developing in close strategic partnership with Microsoft and works great with the Visual Studio environment. There are tons of Unity tutorials and workshops online today, including from the developers of the engine. C# is way easier for a newbie than C++. Therefore, it should come as no surprise that Unity’s popularity and the number of projects, both professional and educational, are on the rise. Of course, for “fast” games, Unreal or the other C++ engine will most likely be used.

Why Isn’t C++ Everywhere, Since It’s so Good?

  • C++ is a powerful tool that makes it easy to “shoot your own foot”. Just imagine how dangerous direct memory access can be in the hands of an inexperienced novice (or, on the contrary, a very experienced hacker, haha).
  • Writing a program in C++ is a long and thorough business. If you write large, complex object oriented programs, you will write them 5 times faster in Java than in C++. In addition, maintenance will be much easier.
  • Training a competent C++ specialist is a messy and a headache. The basics of the language can be learned at university, but they often do not teach how to use this powerful language correctly. You can learn the intricacies of the language only in practice, preferably on a project with Code Review, and it will take at least a year and a half to grow one C++ developer, which is much longer than in the case of Java or Python.

That’s why in areas where speed or energy-efficient resource consumption is not critical, but the speed of development and its safety are important, they prefer to use higher-level languages.

Where Is Java in Game Development?

Remember, closer to the beginning of this long article, I listed the types of games, as well as the types of work that game programmers can do. I mentioned it for a reason. In fact, even AAA projects can use Java, for example, if the game has a server side. These can be in-game purchases or something else, where a possible small delay is not critical. Java can also be used for scripting or for building development tools.

Java is quite often used for the server side of browser games, as well as for mobile games for Android. Personal Indie projects are also open to those who love Java and are ready to get to grips with the LibGDX or JMonkey engine.

Learn More: The Power of Data: How Organizations Can Improve Data Management in Cloud

If Not Java, Then What?

If you, love Java like we do, but are looking toward game development, there are options for development in this industry, albeit not as many as in the case of C++ or even  C#. Technically, for most games (and most games are just games that do not belong to the AAA segment), Java’s capabilities are more than enough. Much more restrictions are due to the vector of language development and the market itself. You don’t need to be a science fiction writer to imagine a scenario with a Unity-like engine that would appear in Java instead of C#, and then things would turn out differently. However, Java has many excellent uses in other industries. And if you want to make your own Java game, well, take a closer look at LibGDX or JMonkey. 

Did you enjoy reading this article? Let us know your thoughts in the comment section below or on LinkedInOpens a new window , TwitterOpens a new window , or FacebookOpens a new window . We would love to hear from you!

Alex Yelenevych
Alex Yelenevych, Co-founder and CMO at CodeGym.cc, an interactive educational platform where people can learn Java programming language from scratch to Java Junior level.
Take me to Community
Do you still have questions? Head over to the Spiceworks Community to find answers.