Java Reference
In-Depth Information
}
protected void writeState() {
try {
Integer playerId = id;
ObjectOutputStream writeOut =
new ObjectOutputStream(new FileOutputStream(
getFileRoot() + team.getName() +
System.getProperty("file.separator") + playerId.toString()));
writeOut.writeObject(this);
writeOut.close();
changed = false;
} catch (Exception e) {
System.out.println("unable to write object");
}
}
Note that we still need to put the separator character between the team name and the player
identifier string, but we do not need to do that between the result of getFileRoot() and the
team name, since the getFileRoot() added that for us.
The end result is code that will run on any operating system, since we are using the abstrac-
tions provided by the JVM (and the Java environment) to mask the differences in operating
systems and filesystems. Although we had to take a little care with our code, we don't need
separate configuration languages, build steps, or binaries for the various platforms on which
we might like our code to run. Instead, the virtual machine that runs our Java program takes
care of that for us. So we don't have to think about such things. Programming is hard enough
as it is without adding new things to think about, so this aspect of the JVM is definitely a good
part of Java.
[ 17 ] Examples of the sorts of virtual machines I'm talking about here are VMWare's products (both
server and desktop), Xen, VirtualBox, and the like. This is hardly an exhaustive list; more seem to appear
weekly.
[ 18 ] Note that files that have inner classes, which I do not discuss in this topic, will generate multiple
bytecode files.
[ 19 ] OK, I know that when you see a sentence starting with “it used to be,” you immediately brace your-
self for tales of how bad it was in the olden days. And yes, I did have to walk to school through the snow.
But this is different, and important, so read on.
 
 
 
Search WWH ::




Custom Search