By Ryan on February 11, 2010
My Computer Science discovers interesting things sometimes. Recently we were doing a little practice with Exceptions and try-catch blocks. One of our projects was to handle division by zero and not crash the program. That sounds like a ordinary project, but as it turns out, it was a more surprising than anyone would have ever [...]
Posted in Java | Tagged division, double, Java
By Ryan on January 19, 2010
Back to the old Java Grid Stone this week, but hey, it’s fun anyway. This time, it’s Matrix Multiplication. I failed to find sufficiently explained information about this horrid excuse for Java, so I want to help everyone else out.
In java, you’re typically dealing with matrices of int or double. The code I provide below [...]
Posted in Java | Tagged Java, matrix, multiplication, Tips
By Ryan on December 11, 2009
If you have a 64-bit operating system, you might consider taking advantage of the 64-bit version of Java and Eclipse. Once you have installed the 64-bit Java, you’ll probably go to Eclipse.org to grab a copy of your favorite IDE. But it work right.
You’ll need a 64-bit version of Eclipse to work with your 64-bit [...]
Posted in Java, Tips | Tagged 64-bit, eclipse, Java
By Ryan on December 8, 2009
Our favorite development tool, Eclipse, makes it slightly confusing to read files properly inside of a Java program.
To start with, I make a file as anyone would, just a quick right click in the Project Tree, then New and finally to File as in a blank file.
One would assume that a non-java would exist [...]
Posted in Java | Tagged eclipse, Error, Java, read, text file
By Ryan on December 2, 2009
I encountered this error today from copying and pasting a code snippet that was from one of our PDF textbooks.
illegal character /160
After making sure that our brackets matched, methods weren’t variables, variables weren’t methods, we didn’t know what was going on. Everything looked good and clean. So we decided to do the unthinkable: we retyped [...]
Posted in Error, Java | Tagged character, Error, illegal, Java
By Ryan on November 30, 2009
Sometimes you need to use an ArrayList. It can be when you’re lazy or when you want flexibility. Eventually, you’ll want to get away from the ArrayList and use your stores objects as standard object array. Doing this isn’t very complicated but it is slightly hidden.
We’re going to pretend for a moment that we have [...]
Posted in Java | Tagged array, arraylist, Java, objects
By Ryan on November 28, 2009
My computer science teacher encountered this strange string while working with another student one day after class. The assignment was using Scanner and stepping through a string by delimiter.
java.util.Scanner[delimiters=\p{javaWhitespace}+][position=0][match valid=false][need input=false][ source closed = false ][skipped=false][group separator=\,][decimal separator=\.][positive prefix=][negative prefix=\Q-\E][positive suffix=][negative suffix=][NaN string=\Q?\E][infinity string=\Q∞\E]
Doesn’t that looks like a scary mess? Actually, it’s not so bad, [...]
Posted in Java | Tagged Error, Java, message, scanner
By Ryan on November 21, 2009
Most methods in java have a defined accessibility. There are public, private and protected. These access modifiers are there to keep the API clean. For instance, a method might be called, getNumberOfHousesInMinnesota but there may be too much code for just one method. A programmer might split that method into sub-parts and declare the helper [...]
Posted in Java | Tagged Java, methods, private, protected, public, variables
By Ryan on November 18, 2009
A regular constructor for an object is run once. It is only run when the object is created, it is initialized. All constructors are named based on the class’ name, if I have a class called Computer, my constructor’s method is also Computer. This is a normal constructor and this causes a plain vanilla initialization. [...]
Posted in Java | Tagged initialization, instance, Java, static
By Ryan on November 15, 2009
Java is silly sometimes. There are times when code will work fine, or at least seem too, even when it looks wrong.
Example 1: if
For example you can end an if statement with a semi-colon. Wait, you say you’re not supposed to end those with a semi-colon? That’s right, you normally don’t. You would expect [...]
Posted in Java | Tagged block, for, if, Java, Syntax