Learning Java
Jun 10th, 2008 by Brian A. Thomas
There is a phone platform coming out called Android, which is a project of the Open Handset Alliance. A number phone manufacturers are going to be making mobile phones based on the Open Handset Alliance specification, all of which use Android. To program for Android, you need to know Java, and so I am starting on a path of learning Java. I chose C# over Java eons ago as I was mostly interested in Windows programming, so Java’s ability to compile on one machine and run on many others, even if they weren’t Windows machines, be they Linux, Mac or whatever, wasn’t a concern. Most mobile phones use Java for their games and applications. Apple’s iPhone is cool, but to program for it, you have to have a Mac, so no programming for the iPhone. Plus the iPhone’s market is limited right now do to the exclusive AT&T deal (you can unlock the phone and run it on T-Mobile for example, but most people won’t go through that much trouble). nVidia has a chipset coming out, but for the moment, none of the Tegra based phones are for Android, but Windows Mobile based phones (and other handheld devices). nVidia is a member of the Open Handset Alliance, so they may support somebody making a Tegra based phone that conforms to the Open Handset Alliance and Android. This will be cool since they seem to have the best graphics of the phones.
There are a couple of caveats however as I embark on learning Java. First, while most Java programs can be ran on many platforms, this doesn’t seem to be the case with Android’s implementation. While the language itself is the same, you can’t compile a program that will run on both Android and say a Windows machine, another cell phone, or something like that, and vica-versa. The problem is they apparently use a different virtual machine to run on than all other implementations. They did this so it would run better on a mobile platform as I understand it. It isn’t clear to me, but it looks like since the language is the same, you could do two compiles, one for Android and one for everything else, but I may be wrong on that part… of course if you use Android specific APIs, then it won’t work on anything else.
Anyhow, I am presently staring on reading Head First Java, 2nd Edition (I am just borrowing that copy, so I don’t have a good hardcopy of my own yet…). Early into the first chapter we do an exercise where we do the “99 Bottle of Beer on the Wall”. The program compiles and runs fine, but, as they note, the output isn’t 100% correct. It took me a while, but I found it.
I won’t revel the answer here, but I’ll drop hints, just in case somebody hits this via a Google search and is looking for some hints.
The code block below doesn’t have the answer, but gives to big a hint, so try for the first one if you can advert your eyes from the code block… ![]()
First hint:
Look carefully at the output when the count is 1.







[...] - Learning Java saved by mpsaints1012008-10-29 - 120 GB Zune saved by tushygalore2008-10-28 - NVIDIA Tegra 650 [...]