The Choice of Java
"The Java Roguelike Development Guide"
Issue One - The Choice Of Java
andrew.d.joiner@googlemail.com
It is fair to say that the vast majority of roguelike games are implemented in the C/C++ programming language. C/C++ are very common languages that most programmers know how to use, it has a variety of curses libraries to choose from, and a fairly extensive list of functionality.
It is not common, however, to find many roguelike games which have been programmed in the Java programming language. The big problem with Java, of cause, is its modern GUI sensibilities. There is no official curses support with Java, and the event model is strictly limited to non-blocking events. However, if these deficiencies can be removed, then Java becomes a viable roguelike programming language, and in fact, becomes one of the better prospects for long-term roguelike development. See Java Curses Implementation for more information on solving this Java problem.
So the question is, why Java? One reason is the excellent object-orientated paradigm that Java takes right to its core. OO-Programming is essential for creating larger scale programs, because it is more intuitive and easier to maintain. Things that were are a nightmare to represent in C, such as an efficient Item data structure, are a breeze in Java.
The Java API is also excellent. Many foundation classes are provided, which allow the programmer to get on with implementation, rather than keep reinventing the wheel. Linked Lists, Vectors, Trees, Random Numbers, Strings. While all of these things can be implemented in the C languages, in Java they are already implemented, and very easy to use.
For example, the following code shows how easy it is to use a Linked List ADT in java;
import java.util.LinkedList; public class ListExample extends LinkedList { // constructor() public ListExample() { super(); // create a new Object reference Object o = new Object(); // add to the list this.addFirst(o); // remove from list this.removeFirst(o); } }
This is just a crude example of how easy Linked Lists are to use in Java. This ability is all based on the fact that every Java class is a sub-class of Object. Object is the root Java class, and because Java has very strong OO features, inheritance of Object is automatic for all classes.
Java is a recommended programming language to learn, especially for roguelike programming, since it is so straight-forward to use. The algorithmic syntax of Java is almost identical to C, which makes it very easy to learn Java if you already understand C. The basic Java algorithmic constructs are the same as C;
- if, else if
- for
- do, do while, while, break
- switch, case, break
For example, a for statement in Java
String string = "0123456789"; for (int y = 0; y < 10; y++) { System.out.print(string.charAt(y)); }
The syntax of the for statement should look familiar to a C programmer, except that the loop-variable can be declared inside the loop instead of outside it. For more information on Java programming, there are many excellent tutorials online:
- The best would probably be the official one from Oracle: http://docs.oracle.com/javase/tutorial/
- There's also an introductory tutorial on MIT Open-Course (It uses Think-Java which is available as a Open-Book online): http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-092-introduction-to-programming-in-java-january-iap-2010
- Thinking in Java is a free e-book by Bruce Eckel. It goes into the depths of the Java Programming Language, its got a high amount of detail but it makes sure that you learn every bit about Java by the time you finish this book, that's why its not recommended as your first read. Link: http://www.saeedsh.com/resources/Thinking%20in%20Java%204th%20Ed.pdf