Recently I have been trying to learn C#. C# and Java have a lot in common, so it’s hard for me to notice some of the subtle differences. Today, I found out that method overriding in C# takes extra effort. In Java, you define methods and then override them in subclasses by simply declaring a method with the same name and arguments. That is not the case in C#, but it took me a while to figure out why the Java code I was converting to C# was not working correctly.
With C#, you have to add the “virtual” keyword to any method you intend to override. In subclasses, you have to add the “override” keyword. This is illustrated below for a “makeMove” method for the game of Gomoku. Continue reading
Posted in Java
Tagged c#, java
I have updated the Java code for my port of the old Super Star Trek game. I first wrote about this about a year ago. See “Java Version of Super Star Trek”.
This update has many bug fixes and enhancements, including support for a deathray, a special kind of beacon planet, an alien home world, and firing phasers and torpedos at up to three targets at once. The new code is available on the SST2k page on Wglxy.com.
Android App. I have built an Android app based on this Java code. The app is more than just destroying alien ships, which is the main objective of Super Star Trek. The app has a storyline about searching the galaxy for the aliens’ home world. If you would like to try that game, more information is available here: Beta Test for Double Star.
SST2k website. The website where I originally found the C code for Super Star Trek is no longer around. I did locate the original SST2k manual in one of the places that caches old web pages. See SST2k game instructions.
Review on Space Game Junkie. The old game was recently reviewed on the Space Game Junkie website. That website is a fun place to visit if you like space games. Brian Rubin did a four part series on Super Star Trek. The link to the first of the series is here: Super Star Trek (entry 1). If you like the game, you will undoubtedly enjoy Brian’s entertaining attempt to learn the game. If you visit his Google+ game, you will find a post from me about movement, where I try to explain why his encounters with blackholes are not as unpredictable as he thought. Continue reading
I built a version of Super Star Trek in Java. This version of the Star Trek text game is based on the work of the SST2k project.
Star Trek, a text-based computer game, has a long history. It originated back in the 1970’s and there have been many variations of it since then. According to the Wikipedia article on the Star Trek text game, the SST2k project started in 2005. It is based on the C port of Tom Almy, which was done in the early 2000s.
A link to the Java source is provided. Continue reading
This is my guide to tuning performance of Java programs. It covers both cpu time and object memory analysis. I have found that this works for Java programs and for many Android applications. In the latter case, it helps if your Android application is structured so you can turn a section of an application into a standalone test case. Since many applications have background tasks, often implemented as subclasses of AsyncTask, this is usually easy to do.
The tool I prefer to use is HPROF. It is a simple profiling tool that is available with the Java SDK. It provides a variety of tools so you can address common performance problems, like the following: (1) you are allocating too many objects, which leads to a slow app because of too much garbage collection; (2) you are allocating objects and not properly releasing them, leading to a memory leak; (3) your computations are taking too long.
The topics I cover in this article include: (a) Getting started with HPROF in Eclipse, (b) HPROF Results (cpu times, object allocation), (c) Performance tuning suggestions, and (d) Other Android performance tuning tools. Continue reading
When you need to analyze performance of a running Java program, there is a simple profiling tool already built in to the Java runtime environment: HPROF It allows you to analyze both execution time and heap allocation. It’s really basic, but gets the job done — and it’s free and easy to use. Continue reading