Write up on Tech Geek History: Java & Game Console Development; Why Not?

Literature Review

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. 

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.

Content of the Problem

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++. 

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.

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.

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. 

Java today is regarded as one of the most popular programming languages. It has a wide range of uses including complete applications, applets, and web pages. The versatility, compatibility, and scalability of Java make it a go-to language for most programmers. 

But the question many programmers ask is if Java can be used for game development and if so if it is the best choice compared to other programming languages. These are the main reasons why Java is used as a programming language.

1. Java runs on Virtual Machine

Java runs on a virtual machine regarded as the Java Virtual Machine (JVM). This ensures that the game can run on various hardware platforms. The Java Virtual Machine acts as a compiler for generating machine code. It allows the game code produced on one system to run on any other Java-enabled system without any alterations. A technical definition for the Java Virtual Machine is that the JVM is the specification for a software program (in this case, a gaming program) that executes code and delivers the runtime environment for that code.

Class files having the same names are produced by the Java compiler as part of the compilation process for a .java file. The .class file generated performs a series of tasks when executed.

The Java Virtual Machine can also be used to optimize and manage program memory. This is useful in game development as the code file takes a lot of memory. As a game developer using Java, the most familiar interaction with a running JVM is to check the memory usage in the heap and stack, while the most common adjustment is tuning the JVM’s memory settings.

When using Java to develop games, it is important to know the three aspects of the Java Virtual Machine. They are the JVM specifications, the JVM implementation, and the JVM instance. All these categories are properly explained when you register for good 

The JVM specification gives prominence to the fact that its implementation details are not defined within the specification, in order to make room for maximum creativity. All the JVM has to do is to run the Java game code correctly. The JVM implementation is basically implementing the JVM specifications outcomes in an actual gaming software program. Finally, the JVM instance works after the JVM specifications have been implemented and released as a gaming software product. It is the downloaded gaming program that has been run and tested. 

2. Java supports Multi-Threading

Multithreading allows you to get the best performance out of your CPU while at the same time using less memory. It enables two or more parts of your program to run simultaneously without interference. If you are working on a computer, multithreading runs multiple applications and gives processing power to them. Most gaming software requires multithreading and Java greatly supports multithreading applications. 

Java development supports Multithreading by the use of a Thread class called Java Thread. As a gaming developer, Java Thread allows you to create a lightweight process that performs some tasks. This means that with Java, you can create multiple threads in your gaming program and start them. The Java runtime will perform the task of creating machine-level instructions and work with the OS to execute them in a parallel format. You can create threads in Java either by extending the Thread class or by implementing the Runnable interface. 

For game development, multithreading in Java also provides you with two major advantages. The first one is that you save a lot of time because it allows you to perform multiple operations together. The second one is that the threads are independent. This means that no matter the number of threads, it will not block your ability to perform multiple operations simultaneously. Also, an exception in one of the threads does not affect the remaining threads. 

If you want to use Java as your programming language for game development, then you understand Multithreading in Java.

3. Java supports Socket Programming

Sockets in programming act as a communication link between two different processes. In Java, socket programming is used for communication between the applications running on different Java Runtime environments. It can either be with no connection or be connection-oriented. Generally speaking, a socket is a way to create a connection between a server and a client. 

Socket Programming connects two nodes on a network for the purpose of communicating with each other. One of the sockets (called a node) listens on a particular port at an Internet Protocol (IP), while the other socket extends itself in order to form a connection. A socket in Java is bound to a port number so that the TCP layer can recognize the application that the data is meant to be sent. 

As a game developer using Java, Socket programming is very valuable in designing multiplayer games.

Java is used for game development due to several features and advantages that make it suitable for creating games, especially for mobile platforms and certain desktop applications. Here’s why:

Features Of Java :

1. Platform Independence

Java’s Write Once, Run Anywhere (WORA) capability allows developers to create games that can run on various platforms without significant modification. This is achieved through the Java Virtual Machine (JVM), making it ideal for cross-platform game development.

2. Rich Libraries and Frameworks

Java provides a variety of libraries and frameworks tailored for game development, such as:

LibGDX: A popular cross-platform framework for creating 2D and 3D games.

JavaFX: Useful for creating GUI-based games.

jMonkeyEngine: A 3D game development engine for more advanced games.

These tools simplify complex tasks like rendering graphics, handling physics, and managing input.

3. Ease of Learning and Use

Java’s relatively simple syntax and strong object-oriented features make it accessible for new game developers. Its modular approach allows for better game structure and maintainability.

4. Mobile Game Development

Java is the primary language for Android development, making it a go-to choice for creating mobile games. The Android SDK (Software Development Kit) is heavily based on Java, which ensures smooth development and deployment on Android devices.

5. Strong Community and Support

A vast developer community and extensive documentation ensure that game developers can find resources, tutorials, and support when needed.

6. Robust Performance

While not as fast as C++ in raw performance, Java offers sufficient speed for most 2D games and many 3D games. JVM optimizations and Just-In-Time (JIT) compilation significantly enhance performance.

7. Memory Management

Java’s automatic garbage collection reduces the risk of memory leaks, a common issue in game development, allowing developers to focus more on gameplay mechanics and less on memory management.

8. Multithreading

Java’s built-in multithreading capabilities allow games to handle multiple tasks simultaneously, such as rendering graphics, processing player input, and managing AI, enhancing the gaming experience.

9. Integration with Backend

Many modern games require online connectivity for multiplayer or leaderboard functionalities. Java’s strong server-side capabilities make it easy to integrate games with backend systems.

Conclusion

Java has established itself as a reliable and versatile choice for game development due to its platform independence, robust performance, and extensive library support. The ability to write code once and run it anywhere makes Java ideal for creating games that can reach a broad audience across multiple devices. Its powerful object-oriented features, garbage collection, and efficient memory management contribute to smoother performance and scalability, even for complex game development mechanics. Additionally, frameworks like LibGDX and jMonkeyEngine provide developers with the tools to create engaging 2D and 3D games efficiently. For developers seeking flexibility, ease of debugging, and cross-platform capabilities, Java remains a solid and popular option in the game development industry.

Leave a Comment

Your email address will not be published. Required fields are marked *