547:202 Blog 02 (9/13/2009)

After another week, we’re finally starting to get into some Java programming. We learned about the basics of almost all Java applications, specifically the naming conventions for the class files and the main function, public static void main(String[] args). We also learned about the basics of variables and which ones we would be using primarily throughout the course.

On my own I rediscovered one of the banes of my original Java programming endeavors, the dreaded String class and the ways to make comparisons. I spent a good 30 minutes trying to get a simple application to work, basically a loop until certain input is received. Basically it was a do-while loop that kept asking for (and repeating back) input until it receives /x. Basically, I set a BOOL variable, exit to false. While exit is false, keep getting input, checking if the input is /x, and then outputting the input if it was not /x. When it becomes /x, exit gets set to true, and the program exits out. The difficulty came from forgetting that if you have a string a (that you defined), and a string b (which is input), and want to check if they are equivalent, you cannot simply do a == b. This will always return false, since a and b are not the same object nor do they reference the same location in memory. You must reference the String class function equals, by either doing a.equals(b) or b.equals(a). This will return true if a and b are equivalent. This was very frustrating because in every other language I program in (Python and PHP primarily) you can simply do a == b to check equivalence for everything.

As for next week, I am hoping to see some slightly more complex Java applications and learn how they work and how to write them. I know we won’t be getting into things as complex as arrays, pointers, and things of that nature just yet, but I am kind of excited to get there sooner rather than later.

I also had a brief thought about the assignment we’re doing in our groups. Does the professor want us to make it wait for space as input and then proceed to the next group of text for the flash card program? I do not know how (or even if Java is capable of doing this) to make a Java program wait for a keypress, unless the keypress is specifically enter. The Scanner class always waits for enter before continuing forward, so I will have to ask about this on Monday.