The Java Platform and Its Legacy

Numerous texts document the benefits and advantages of using Java. This section identifies just those advantages that are helpful when developing games. Most of the advantages relate to the productivity boost gained from working with Java. This section also lists a few notorious disadvantages and possible solutions for them.

The Advantages of Java for Game Development

Platform independence: Java is a platform-independent language that allows users to write a program on the Windows , Macintosh , or Linux platforms without any serious localization requirements. This aspect is fundamental for development in Java and a key to its popularity. Platform independence means that a game written in 100 percent Java can immediately be shipped under all three platforms, thereby extending the potential market without incurring large porting fees to make the game available in traditional development. Several major Web providers have selected Java for the creation of Web-enabled games because of this fact. Being able to reach such a large potential market can make a major impact on a business’s bottom line and directly affects when a given game will begin showing returns.

Improved object-oriented architecture: Java was designed to provide a more modernized look at object-oriented programming (OOP). With the benefits of code reuse, data encapsulation, polymorphism, and inheritance, the object-oriented paradigm has taken hold in a large segment of PC games. Even with the strengths associated with OOP, one of the major benefits to using Java is that it limits inheritance and allows for the usage of only a single child class. This might not seem to be an immediate benefit, particularly to a C++ programmer. Java explicitly states that any additional customization need for a child class requires the implementation of an interface class. This requirement creates a chain of responsibility that can be logically followed. Frequently, overzealous C++ coders have been found mired in the swamp of multiple inheritance. This situation can be overcome with careful programming practices in C++, but it is already built in as a standard mechanism in Java—just one of the OOP improvements that the Java platform offers.

Easy to learn: Java is easy for new programmers to learn. This fact doesn’t necessarily benefit a seasoned programmer, but it eases the process of getting new programming hires acclimated to the development environment and code base. Because Java does not use pointers, the disadvantages (and advantages) associated with their use are gone. In some aspects of game development, this is a particular disadvantage, but as Moore’s Law continues to hold true, performance-related issues continue to subside. Another benefit is that Java does not require the programmer to explicitly delete classes when finished with them. A garbage collector is maintained in the Java virtual machine that identifies when it needs to delete these variables and safely does so without the prodding of the programmer. These aspects of the Java language come together to make a quick entry for experienced and new developers.

Improved productivity: Applications developed using Java are typically completed much more quickly and have fewer bugs. Another of the best aspects relating to Java is reflection. Reflection is a built-in mechanism on the Java platform that allows the programmer to identify key information about a given object. For example, at a game’s runtime, the programmer can query, modify, and dynamically create instances of classes that are not known until the game is actually running. This tool is particularly powerful, with its key benefit for game developers coming late in the development cycle when the product is approaching completion. Debugging is faster, and delivery of an on-time product is an easier task. This last part is, of course, directly related to the management of the team and not Java, but having solid backing from technology never hurts the ship date of any project.

The Disadvantages of Java for Game Development

Performance concerns: The old myths associated with Java relating to its performance, center on the fact that it is an interpreted language, meaning to some that it couldn’t possibly work as quickly as native code. In some cases, this was absolutely true. Early on in Java’s history, many people turned away from Java as a game development platform thinking that it could be used only within Web pages and had no real value for the commercial game market. In some situations Java is a bit slower than C++, but the inherent language benefits tend to outweigh losses due to performance. Current implementations of Java can use a Just-in-Time (JIT) compiler to overcome most of the speed issues, but when the JIT compiler is not deployed, noticeable slowdowns may occur while the code is interpreted. Recent benchmarks have pitted Java against all three of the major .NET languages and found Java’s performance in arithmetic operations to be almost identical, excluding trigonometric calculations. This result represents a huge boost for Java, allowing it to demonstrate the improvements made by the development team.

The truth is that poorly written code will perform badly, regardless of the language in which it is implemented. Many of these apparent limitations regarding Java’s performance can be overcome with a bit of tweaking and profiling, though optimizing a particular task in Java usually requires more knowledge of the platform to properly tweak than an equivalent optimization performed in C++. Many useful game-oriented optimizations for Java are discussed later in this book in Chapter 6, “Performance and the Java Virtual Machine.”

The need to get “dirty” to get performance: As new technology is released, game developers usually try to take full advantage of the new advances in the hardware, particularly on graphics cards. The near annual revisions of Microsoft DirectX frequently present developers with the latest access to hardware- and performance-related features. When a particular hardware or software feature is not implemented on the Java platform, Java developers may be required to get “dirty” through the use of the Java Native Interface (JNI) to take advantage of some of the features that are openly available to C/C++ developers. The JNI allows the programmer to make native function links back to Java so that they can be explicitly used through a Java interface. Although the presence of this tool is great (and is really the foundation of the entire language), it does require time to become productive with it. It can also break the platform independence that was listed earlier as an advantage. Chapter 11, “Java Native Interface,” discusses the methods for using this technology for typical gaming applications.

Lack of an accurate high-precision timer: Time calculation is critical in game programming. It controls how quickly the game should render, how frequently an object should animate, and numerous other game-play-related features. The lack of this timer has put many Java game developers at a distinct disadvantage. One common, partially successful solution was to tell the main execution thread to Sleep(). This solution is inaccurate and is not a real solution. Another workaround was to use the JNI to map a local timer such as QueryPerformanceCount, which uses 64-bit representations of time. This solution works but requires that developers “get dirty,” as was mentioned in the previous section. This local timer solves only the problem local to the current implementation. Of all concerns related to programming games using Java, the lack of a supported high-precision timer is the largest single disadvantage.

Security Model for Java Classes

An additional disadvantage regarding the use of Java is the ease in which class files can be decompiled and the source code contents stolen. Java compiles code into a class file, which is really partially compiled byte code that will be finalized when the program is run on the platform of choice. This means that the .class file can be opened and its contents displayed or potentially modified. This has been a large concern among many developers who don’t want to see their work lost or don’t want to deal with client-side hacks that allow for cheating in multiplayer games. This disadvantage can be easily overcome with the use of code obfuscators. Code obfuscators take existing and functional code and make it unreadable to anyone. With regard to commercial games, code obfuscators are imperative to prevent the theft of source code.

Conclusion

This list of advantages and disadvantages relating to Java is by no means exhaustive. These issues tend to manifest themselves during the game production cycle and must be mentioned. Additional advantages and disadvantages are discussed in the next section for each genre; they are related to the process of creating a game of each given type while using Java. A prospective Java developer shouldn’t let any myths influence his opinion of the technology until he has had a chance to explore the platform fully.



Practical Java Game Programming
Practical Java Game Programming (Charles River Media Game Development)
ISBN: 1584503262
EAN: 2147483647
Year: 2003
Pages: 171

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net