Java Scanner class and Standard In Troubles

January 25, 2009

I ran into a bit of trouble today with the Java Scanner class that I thought was worth mentioning. Personally I really like the Java Scanner class because it is a great way to easily read from standard input (stdin). In specific the issue I had was that I noticed the Scanner class allows you to close stdin. This is the part I found problematic. Consider the following code from

import java.util.Scanner;
public class Test
    public static void main(String args[])
     Scanner scanner = new Scanner(;

     System.out.print("Enter a number: ");
     System.out.println("Your number was: " + scanner.nextInt());


     scanner = new Scanner(;

         System.out.println("Whoops! nothing to read!");

     System.out.println("Things seemed to  have worked correctly.");

When you run this code what you will notice is that after you enter the first number the program goes straight into that if statement. This is not what we might expect however because the has<something> functions are supposed to hang until something is typed.

The reason for this is the call to scanner.close() which ends up closing standard in. To be honest I’m not sure how this would work on a Windows system, but I know it was a bit of a problem for me on my Linux box. The simple fix is to just not call .close() , but since it is normally good practice to close things you opened I didn’t think much of it when I first wrote the code. I guess we didn’t technically open stdin, so perhaps that is the correct way to look at it .

At any rate I wouldn’t call this a bug of Scanner, but simply something to look out for when using the Scanner class.

Happy coding 🙂 !

Spheriosity Alpha 3 Released!

January 13, 2009

Today I finally managed to release the next instalment of Spheriosity. For those who don’t know Spheriosity is the Java program I wrote to be an emulation of spherical geometry and it is geared toward students in higher geometry classes or anyone interested in learning about spherical geometry. The latest release has many new features. Here are a few of them:

  • Midpoint plotting
  • Ability to draw spherical circles
  • Improved line length measurement tools
  • Ability to rename points

To give it a try head on over to our SourceForge page and download away. Spheriosity requires Java3D >= 1.4 and Java >= 1.5 . For those interested in hearing more about the latest release then keep reading.

The reason that I decided to release it as alpha is because I think there are still too many features I would like to add to the next version. Also, I have been reading about XML lately and think I might change the file format over to use an XML based one for saving spheres. Changing to XML will probably not be terribly difficult, but it does involve my needing to actually do it and then write some acompanying tests. More importantly it will, yet again, break backwards compatibility with file reading.

Hopefully, the next version I release can be beta quality. Also, I am still looking for people who would be interested in helping with development. It would be great to have other people to bounce ideas off of and check the code out to make sure there are as few errors as possible. Additionally, I don’t always have time to work on the project and getting a few more people would help it have some more consistent development.

At any rate I hope everyone enjoys the latest release and if you have any feedback please let me know either via this blog or the Spheriosity SourceForge page. Thanks!

fglrx Drivers — Getting TV Out to Work

January 11, 2009

About six months ago my friend sent me a link to and one day I simply stumbled across the service Since then I have been hooked on internet television. I rarely use the normal form of watching TV, and why should I? I can watch the shows I want to watch WHEN I want to watch them. Additionally, both Joost and Hulu offer subtitled and dubbed anime, which is far more than I can get on TV. Anyway, that’s not the point of my post, but rather the reason I became interested in getting the TV Out on my ATI Radeon 9800Pro to work. As a final note I am using the ati-drivers (fglrx) version 8.561 . For you Gentoo users it is currently masked in portage so you are going to want to add “=x11-drivers/ati-drivers-8.561” to your /etc/portage/package.keywords if you plan to use them. I don’t know what version they started supporting the features I am talking about so it might work with your current setup just fine.

Sadly I must use the closed source driver, for now anyway, because Spheriosity will not run properly for me on the open source driver. I used to switch between the two drivers, but that became terribly inconvenient because I needed to maintain two Xorg.conf files since each driver has its own little nuisances. I kept reading that the closed source driver (fglrx) supported TV-Out, but I was failing to setup the Xorg.conf file correctly and I noticed that xrandr didn’t seem to work. Eventually I noticed here (scroll down a bit) that fglrx does not support the randr extension. At that point I was ready to give up, but I noticed the aticonfig tool. This has a few options that can be changed on the fly, which is exactly what I wanted. Normally I run a dual monitor configuration with big desktop and only on occasion do I want TV output. With the aticonfig tool it was quite simple:

aticonfig --query-monitor

This shows what monitors are seen by the drivers. Here is what mine looks like:

jinto@lightflame ~ $ aticonfig --query-monitor
  Connected monitors: crt1, tv, crt2
  Enabled monitors: crt1, crt2

To enable the TV you simple issue the following command:

aticonfig --enable-monitor=tv
aticonfig --enable-monitor=tv,crt1 (if you want tv and a monitor)

You may have to replace crt1 with whatever output you get from --query-monitor, but hopefully you get the idea. KDE 4.1 did seem to have some minor annoyances while switching between configurations so when I watch TV I simply use a failsafe login to avoid my plasmids from getting all messed up. Also, there are ways to adjust the size of the image being output to the TV using the --tv-geometry flag. aticonfig will complain about not being able to edit the xorg.conf file, but it seemed to change it for me on the fly so I’m not sure what the story is behind that. If you want to understand how to use --tv-geometry just issue aticonfig --help | less and it is near the top. If you are interested the tv geometry I use it is:

aticonfig --tv-geometry=43x55-1+1

What you need to use probably varies from TV to TV so unless you have a 27″ Sony Trinitron you will probably have to tweak that command 😉 .

Oh yeah… and if you want to go back to your original configuration just issue:

aticonfig --enable-monitor=crt1,crt2

Or whatever monitors you wish to active. If you only have a single monitor then all you need to do is issue the previous command without the “,crt2” part 🙂 . Good luck!

Video Game Music

January 9, 2009

It’s no secret, at least to those who know me personally, that I love listening to the music from video games. Now, I have my limits. If the game has terrible music then I simply don’t care to listen at all. Recently there has been some stunning work on video game sound tracks. The sound track to Mario Galaxy and Super Smash Brothers Brawl were absolutely breathtaking. The industry has come a long way in terms of audio. I still have a soft spot in my heart for those classic NES tunes, but I sure do like the way things have been improving.

There are even some games for the SNES that had rather amazing sound tracks. The obvious games there are Chrono Trigger, Final Fantasy III (Well VI actually, but released as III in America), and Secret of Mana. That is not to say there weren’t other SNES games with good sound tracks. In fact, there is an entire community of people who take video game tunes and remix them. The big place for that happens to be and I have spent hours upon hours on that site. They truely have some talented remixers there. Here are a few good mixes, but certainly there are hundreds more that are quite amazing:

Beyond the realm of OCRemix we have video game cover bands (as if things couldn’t get any better) ! Some of these include: The Megas, Armcannon, The OneUps, Powerglove, and The Black Mages. All of the bands mentioned even have CDs you can purchase, or most of them have options where you can download the music (for a small price). For those of us that love the video game tunes it is truely a great time. Back when I was much younger there were none of these things and the closest thing I had to listening to video game music (other than playing the games) was a Mario Kart 64 Soundtrack that I found somewhere.

Whether it’s an OCRemix or a video game cover band these guys are taking the old 8-bit tunes and turning them into musical glory. This gamer in particular finds himself frequently amazed at what they can do.

In the future I plan to blog a little more about video game music as its one of my interests. I just haven’t had the time lately 🙂 .

Replacing Power Supply Fans

January 6, 2009

For some time now whenever I would turn on my computer the fans would make that classic “I’m going to die soon” sound which is never a good thing. I didn’t really want to throw down the money to replace an otherwise working power supply so I decided that I would simply replace the fans. This was a fairly simple project, but not worth breaking your warranty over. The power supply I was working on was a 5 year old Antec 480Watt power supply, nothing special. The basic tools you would need for this project are:

  • 2 Philips head screw drivers a smallish one and a mediumish one
  • Basic soldering skills
  • Soldering supplies (solder gun, solder, flux… etc)
  • Wire Cutters
  • Wire Stripers
  • New case fans that are the same size as the ones already installed
  • Heat shrink or some electrical tape

Before I continue on I want to issue this general disclaimer: Working with electricity or devices that use electricity can be dangerous. By following any of the instructions in the rest of this post you acknowledge that you will not hold, this blog, or writer of this blog responsible for anything that happens as a result of what you read/did as a result of reading this article.

Honestly I didn’t want to have to place such a disclaimer on my blog, but I feel it is necessary. This job is simple and can be safe as long as you are careful! It’s not my fault if you start poking your screw driver around and get zapped!

One last thing before I get started. That is a note on fan selection. I had to take mine apart once to figure out what size fans I needed. In my case I had two fans: an 80mm and 92mm fan. I ordered two of these: (not two of those exact ones, but two Ventec Stealth Fans). You can order any old 12 volt case fan as long as you think it will move enough air to cool your power supply. If you are concerned that your power supply uses some fancy non-standard fan then just follow the guide up until the part where you have to cut the fan wires and you can see for yourself. Anyway, I choose these fans because they were supposed to be quiet (around 20dB). Apparently they also move enough air, or I wouldn’t be writing this post right now ^_^;

The first step in all of this is to remove the power supply from your computer. You should unplug the power supply before you start removing it. The actual removal differs from computer to computer and if you are concerned you won’t remember where everything plugs back in then take a picture or take some time to label things.Typically the power supply is screwed in to the back of the case with 4 screws. It’s easy to locate because it’s where you plug in that monster power cable that your computer needs to operate.

Once you have safely removed the power supply from the computer set it down on a flat surface and pull out your smallish screwdriver. Most power supplies I have taken apart (about 6 or 7) have four tiny screws on the top. I circled two of them in the picture below.

Power supply case screws highlighted

Power supply case screws highlighted

The other two screws are simply on the other side. Also, notice that the screw on the right was originally covered with a sticker.

Warranty Sticker

Warranty Sticker

That sticker says something about violating the warranty and I imagine that by defacing it I voided my warranty (which had long expired). If you care about your warranty stop now and put down the screw driver. If not continue on by taking the top part of the case off. I had to be careful when taking mine off because, if you didn’t notice, there is a fan attached to the top of mine. That fan has two wires that run down to the main board and there’s slack in them, but I could easily seen them being yanked out by an overzealous tug. Here is when you can figure out what size fans you want to order. Simply measure any given side of the fan (it’s a square… all sides have the same length) in millimetres and this will tell you what size it is. I had an 80mm and 92mm fan in mine. They come in standard sizes (yes… 92mm is a standard size for some reason) so they won’t be hard to find.

Here is the inside of the power supply case

Here is the inside of the power supply case

Notice that, as promised, I have two fans I need to replace. Only one of them was making funny noises, but I figured if I was going to open everything up I may as well replace both of them.

Quick Note: If you look at the picture just below I have circled the main reason playing with your power supply does include risk of electricity.

Don't let these guys zap ya!

Don't let these guys zap ya!

Those bad boys are 200 volt capacitors. If you didn’t already know a capacitor is a magic device that can store electricity. It’s doubtful that a fully charged 200 volt capacitor would kill you, but I certainly wouldn’t recommend testing that theory out. Just don’t touch it, either with a screw driver, or with your body and there is nothing to worry about 🙂 .

The next step is to detach both of the fans from the power supply case. These are standard case fans and detach with four screws each. They should be on the outside of the case as shown in the picture below.

Just to give you an idea of what to look for

Just to give you an idea of what to look for

Yes, this picture was taken with the case still screwed together, but that is because I forgot to take it with the case apart 🙂 . In any case hopefully you get the idea… you have to unscrew all the fans to remove them.

Here is a fan unscrewed from the case

Here is a fan unscrewed from the case

Now we are tasked with detaching the fan from the main board. On my power supply they are plugged in with tiny plastic plugs as you can (sort of) see in the picture below.

Remove this if you feel up for a fight...

Remove this if you feel up for a fight...

I didn’t feel like fussing with the connector to try and remove it so I just cut the wires. At the end of the day you are going to have to solder anyway 🙂 . I decided where to cut based on the next step which talks about cutting the wires on the fan. I tried to keep the final wire length the same as what it was originally, but to make soldering easier you want to have enough slack on each wire that they will cooperate nicely with you. Below is a picture of the cut wires. At the end of the day you just need to use your judgement. Remember: measure twice, cut once!

Here is a picture of the wires I cut

Here is a picture of the wires I cut

There are a few things you need to know about modern case fans. Any case fan I could find typically came with a 3 pin connector (for a motherboard) and an adapter to so you could hook it right in to your power supply. My power supply fans only used the red and black wires which are for power and ground respectively. The extra wire, usually colored yellow, is so the motherboard knows what speed the fans are spinning at. If your power supply happens to support that then solder that sucker in. Mine does not so I just cut the wire really short and figured nothing else would touch it.

Now that everything is ready, solder it all up. I am assuming you know how to solder and chances are you solder better than me. Once you have soldered you will end up with something that looks at least as good as this:

The fans all soldered in to place

The fans all soldered in to place

I would have used heat shrink, but I didn’t have any and really needed my computer to be running again. Before you reassemble everything I would suggest that you hook up your power supply just enough to get the fans spinning. This means you’ll want to hook up main board power, hard drive power, and video card (if needed). Press the power button, see if they spin, and they pull the plug so you don’t overheat anything. You want to make sure the fans will spin before you put it all back together. The last thing you want is for it to overheat without you knowing!

After you test and they work… you are done! Enjoy your new fans 🙂 .

Spheriosity Work Continues

January 5, 2009

This is just a quick update about my recent work on Spheriosity. I had promised myself that I would release a version over my winter break from college. Today I finally had time to sit down with the code and start working through a few bugs. I fixed most of the bugs that I know about, and now I have moved on into commenting and writing unit tests.

It was a bit of a struggle to motivate myself to write the current group of units tests, which is probably why they aren’t already written. I will write them though, and it will help keep Spheriosity more stable in the long run so it’s a worthwhile goal.

After the unit tests are done I plan to add one last feature which will handle midpoints of lines. This should be a snap to implement and it has been on my list for a while.

Finally, I will do a major update to the user documentation which will include a proof reading 🙂 .

After all that I will release the new version. I’m not sure whether I consider this alpha or beta. I’m going to have to give it some more consideration. It looks pretty likely that I will finish this all within the next two weeks so hopefully all goes according to plan 🙂 .