Here is a small game of Yahtzee I have been recently working on in Java. At the moment it takes the form of a standalone swing application, although I may port it to a Java applet for in browsers games. Full source code can be found on the GitHub repository
Although I haven’t personally installed the release, here are a couple of screenshots from a user running it in a Virtual Machine.
This shows the new ‘Metro’ UI in Windows 8. It consists of a series of tiles and widgets that link to the most common applications. I can’t really see anyone using this on a desktop computer, but I suppose it’s meant to be for mobile devices with touchscreens, which will benefit hugely from the large icons.
Here is the new desktop and start menu in the developer release. Although most of the desktop is similar to that of Windows 7, huge changes can be seen in the new start menu which has been completely revamped to fit in with the new Metro style.
One of the main changes in the new release is the new Ribbon in Windows Explorer. For more basic skilled users this could be a real time saver, as it stops people from trawling through the edit menu in order to find ‘Copy’. However on the other hand, on smaller resolutions the Ribbon can take up a lot of real estate, and won’t leave much room for the actual files to be displayed. I can see most advanced users instantly hiding the Ribbon, as most of it’s features can be accomplished with simple keyboard shortcuts.
The task manager has also been given a much needed face lift. It’s now much more graphic, and offers the user more information than in previous versions. This will also apparently be a window that many users will see, as Microsoft have recently said that most people use the task manager on a day to day basis to ‘kill’ programs. This doesn’t really say much for the developers.
Finally there is the new Metro Control Panel and a possible Metro equivalent to ‘All Programs’. I hope that Microsoft still include the old versions however, as I can see trying to navigate the control panel on a desktop computer taking twice as long as it should do.
Of course this is a very early build of Windows 8, but shows a taster of what’s to come. I find it surprising that Microsoft have made such large changes from Windows 7. Obviously Microsoft are trying to integrate the new release with Windows Phone devices, and Metro will look and feel great on a touchscreen device, but I don’t really think that it offers any use whatsoever to the majority of users sitting at their desks. Plus considering that Microsoft’s clients are mostly corporate, I can’t see the new changes being that popular with them. It will probably decrease productivity and will confuse many users, especially considering that many businesses have only just made the leap from Windows XP to Windows 7, and from Office 2003 to 2010. The leap has just been made at my college, but not without major problems. Many have had problems using Libraries, and the whole network has been down for hours at a time. Of course the problems will be fixed soon, but it doesn’t bode well for Windows 8 considering that it took the best part 8 years to upgrade to Windows 7.
Expect to see a lot more about the new release in the near future.
A few days ago Oracle announced the availability of their new Java 7 SDK. Some of of the major changes include -;
New I/O APIs (Asynchronous I/O)
Strings in switch statements
Unicode 6.0
Elliptic-curve cryptography
Translucent and shaped windows
Heavyweight/lightweight component mixing
Swing Nimbus look-and-feel
Swing JLayer component
The integral types (byte, short, int and long) can also be expressed using the binary number system. To specify a binary literal, add the prefix 0b or 0B to the number.
Any number of underscore characters (_) can appear anywhere between digits in a numerical literal. This feature enables you, for example, to separate groups of digits in numeric literals, which can improve the readability of your code.
You can replace the type arguments required to invoke the constructor of a generic class with an empty set of type parameters (<>) as long as the compiler can infer the type arguments from the context. This pair of angle brackets is informally called the diamond.
A single catch block can handle more than one type of exception. This enables you to specify more specific exception types in the throws clause of a method declaration and reduces code repetition.
The try with-resources statement is a try statement that declares one or more resources. A resource is an object that must be closed after the program is finished with it. The try with-resources statement ensures that each resource is closed at the end of the statement.
Note: The Google Finance API has now been deprecated so this code will no longer work
After testing out the code from the recent post on the Google Currency API, it became apparent that the code had one very significant bug that caused an exception to be thrown when the user enters a value that returns a result over the one million mark. For example -;
{lhs: "1 000 000 British pounds",rhs: "1.6399 million U.S. dollars",error: "",icc: true}
As you can see, instead of returning just a decimal number, it gives a number followed by a String, which caused the previous program to crash.
In this case to fix the bug, the Regex needs to be modified so that it returns not only the number, but also the new String in the same match. With this information, the number can then be multiplied to give the final result as a single decimal.
The Regex now becomes -;
rhs: \\\"((\\d|\\s|\\.)*)(\\s[^\\s]+)
(the cluster of backslashes are to escape the possible escape sequences of ‘/d’ and ‘/s’ for example)
The new Regular Expression makes use of ‘Groups’ to store the two pieces of data in the same match -; the first groups contains the number, and the third contains the String due to the way this pattern is designed (it’s probably possible to modify this, yet it doesn’t create too much of a problem and so isn’t worth the effort).
We can now produce a match from the response using the same code as before -;
Here, the number is stored as a String from the first group and the ‘spaces’ are removed (for some reason in the returned String, ‘spaces’ have a Unicode value of 160, which is called the ‘Non-breaking space’). Next, the number is converted into a decimal and the units are extracted from the match and stored in the ‘units’ variable.
As the only possible values of the ‘units’ variable are ‘millions’, ‘billions’ and ‘trillions’, we can simply test the variable against each and multiply the number correspondingly to get the overall result. Finally, we just need to round the number to two decimal places to signify a currency, and return the value. Here is the full updated code which hopefully is bug free. The full source code can be found in GitHub.
Note: The Google Finance API has now been deprecated so this code will no longer work
After I found myself using Google to translate currencies, I wondered whether it would be possible to utilise this functionality in a program. After a little research it turns out that Google offer a huge API that deals with currencies and finance. For the purpose of this post I will show you how to convert currencies, yet you can also use the API to find stock information and even market gains over a period.
Although here I will be using C#, it should be possible to use pretty much any language and get the same results.
This particular feature can be utilised through a simple URL containing the amount to convert from, the currency to convert from, and the currency to convert to. This translates into this URL -;
(which converts 1 British Pound to US Dollars) returns the following -;
{lhs: "1 British pound",rhs: "1.6121 U.S. dollars",error: "",icc: true}
The URL responds with a JSON object where the actual result is mixed in with some other information from the request, which presents a minor problem when trying to convert currencies in our program. This will be dealt with a bit later on.
First of all in our program, we to get the output of the request. I used the WebClient class, which will download the response as a String for use in our program. In the following code, the URL is constructed with parameters passed in by the user, and the string is downloaded and stored in the ‘response’ variable.
This takes care of getting the response with the answer we want, yet we still need to somehow extract the correct data from the string. In this example I will use Regular Expressions however if your prefer not to use them, or your language does not natively support them, it would be perfectly viable to loop through the response one character at a time, and parse out the result.
The Regex pattern will look like this -;
rhs: \\\"(\\d\*.\\d\*)
This pattern essentially searches for the ‘rhs’ which appears just before the result value, and extracts any numbers afterwards until any non-numeric character is reached.
Using the Regex to extract the result, we end up with the following, final code -;
Thats about it for the Google Currency API for now, however I may post snippets on how to use some other features of the extensive API’s Google offer soon.