Java
From DmWiki
Java is a cross-platform, object-oriented language. The main feature distinguishing it from other languages is that Java applications are compiled to bytecode and in runtime they are executed via a "virtual machine", which in turn either interprets the bytecode or converts it to native code and executes it. This allows applications written in Java to be used on all computers for which a Java virtual machine exists.
Java was developed by James Gosling of Sun Microsystems (http://www.sun.com/) in early nineties, as the progression of the Oak project. As of writing these lines, Java is not yet a standarized programming language.
| Table of contents |
Availability
In order to execute a Java bytecode program, a Java virtual machine (Java VM) is required. Sun Microsystems, develops the reference implementation of Java and provides a Java Runtime for Windows, Solaris, Linux i386 and Linux x86_64 systems. The runtime is available from their front Java site for consumers, [1] (http://www.java.com/).
For Mac OS X users, Apple provides their own implementation of Java Runtime based on Sun's reference runtime. Mac OS X Panther includes version 1.3 of Java, while Mac OS X Tiger has version 1.4. Apple provides a Java Runtime for version 1.5 (dubbed Java 5 by Sun) from their site. The next Java version, 1.6 (dubbed Java 6), currently in beta, is expected to be the default Java Runtime in Mac OS X Leopard.
There is also a FreeBSD port of Sun's Java Runtime, but it is not supported by Sun Microsystems.
Development
For developers, Sun provides the Java SDK which allows developers to create programs in Java. The Java SDK includes only command-line tools, such as javac the Java Compiler, java the Java launcher (also available in the runtime), javah a tool for interfacing Java and C, appletviewer a tool to display applets and others (http://java.sun.com/j2se/1.5.0/docs/tooldocs/).
Like the runtime, the Java SDK is available at no cost from Sun's download page (http://java.sun.com/j2se/downloads/index.html). Also recently Sun Microsystems decided to release their Java implementation as open source software under the terms of the GNU General Public License. Currently only the compiler and the virtual machine are available under GPL, but it is expected that the class library will be released soon. The Java SDK which can be downloaded form the site above, includes much of the source code for Java, but it is not truly open-source: Sun offers it under a "Community Source" program, which comes with certain restrictions. For more information, see the Community Source FAQ (http://www.sun.com/software/communitysource/faq.xml).
Syntax
Java uses a syntax very much like that of C++ and includes an extensive standard library that enables, among other things, easy use of multithreading and networking. Like C++, it is strongly typed; additionally, the Java language mandates that exceptions must be caught and handled (unlike C++), and Java also includes automatic garbage collection. These features, along with the virtual machine (which can be configured to deny Java programs access to operating system functions like reading and writing files), mean that developing safe and robust Java applications is often easier than in other C++-based languages since the program can be executed in a sandbox.
A minimal Java application is
package com.mycompany.mypackage;
public class MyProgram
{
public static void main(String[] args)
{
System.out.println("Hello, World!");
}
}
This produces the classic Hello, World! message.
Game development
When it comes to game development, Java is ideal for small and medium desktop games. Also since all mainstream browsers support the usage of Java Applets for embedding small Java applications in web pages, Java can be used to create web games, similar to Flash games.
Java2D
The core Java API (http://java.sun.com/j2se/1.5.0/docs/api/) provides extensive 2D graphics functionality via [Java2D (http://java.sun.com/products/java-media/2D/)] with support for antialiasing, blending, matrix operations, texture mapping, filters (such as emboss), curves and other 2D graphics features. Also since Java2D is an extension to the basic 2D graphics API (which is based on the underlying operating system's 2D graphics facilities), it can be used wherever 2D graphics are needed or provided in Java. For example, for a desktop game that runs in windowed mode, a Swing look and feel can be made that utilizes Java2D to provide a custom quality user interface for the game.
LWJGL
A negative aspect of using the core Java API is that there is no or minimal hardware acceleration. Fortunatelly, this can be overcome with the use of native libraries which provide additional classes to the programmer. For game developers, one of the most famous native libraries for game development is LWJGL (http://www.lwjgl.org/). LWJGL was developed by Caspian Rychlik-Prince, the lead programmer of Puppy Games (http://www.puppygames.net/) and it has been used in many commerical games (http://www.lwjgl.org/projects.php), including award winning Titan Attacks from the author of LWJGL and Tribal Trouble.
What LWJGL does is to provide basic functionality for a game, including bindings for OpenGL for graphics, OpenAL and FMOD for sound, the native input system for input and DevIL for image loading.
A drawback when LWJGL is used is that the developer has to deploy different versions of his game, for each platform supported by LWJGL (currently Windows, Linux and Mac OS X). This breaks the write once, run everywhere paradigm of Java.
JOGL
Another project to provide hardware accelerated graphics in Java is JOGL (https://jogl.dev.java.net/) (Java OpenGL bindings). Unlike LWJGL, JOGL is a JSR (Java Specification Request), JSR-231, and focuses only on OpenGL.
JOAL
Like JOGL, JOAL (https://joal.dev.java.net/) (Java OpenAL bindings) brings hardware accelerated audio to Java game developers and like JOGL it focuses only on OpenAL.
Resources
- Sun Microsystem's Java site (http://java.sun.com)
- Wikipedia : Java (http://en.wikipedia.org/wiki/Java_programming_language)
- LWJGL (http://www.lwjgl.org/)
Notable Projects for Game Developers
- Jake 2 (http://bytonic.de/html/jake2.html), a port of Quake 2 from C to Java.
