Now that’s odd… Java really IS different


My friend Harrison sent me a  Java file that was giving him trouble. He wanted to read in an Integer from in a command-line program. He found the method readInt() in the class Console. But it wouldn’t compile:

for ( i = 0; i < 5; i++)
System.out.println(“Array[“+ i +”] = “+ array[i]);
String name = null;
int age = 0;
age = Console.readInt(“Enter Age:”);
}
}

PersonTest.java:74: cannot find symbol
symbol  : method readInt(java.lang.String)
location: class java.io.Console
age = console.readInt(“Int Enter Age:”);
^
1 errors

I did a little searching and found suggestions that he was going in the right direction:

   char letter = Console.readChar("Enter a letter: ");
   double d = Console.readDouble("Enter a real number: ");
   int i = Console.readInt("Enter an integer: ");
   String name = Console.readLine("Enter your full name: ");

http://faculty.cs.wwu.edu/martin/Software%20Packages/BreezyGUI/breezyguijavadoc/breezygui/console.html

hahaha! Turns out breezygui.console isn’t the same as console… the base language doesn’t actually have the readInt method, or readChar or readDouble. But apparently C# and or J++ and/or some dialect/library for C++ DO have a Console class with a readInt, readChar and readDouble members…

SO… you have to be VERY careful what the on-line document you’re counting on really says. It might have the method you want but only in a library you don’t have, or in another language completely. Ooof! is this fun or what???

Of course I showed Harrison how to get integer, double and char values he wanted. That’s what friends are for.

So be careful what you read and believe. Including this!

Advertisements

2 responses to “Now that’s odd… Java really IS different

  1. Thanks Bill! So, St Thomas was right!! Seeing is not always believing! Touching or in our case, compiling is!:P

  2. Hi Harrison,
    I think Smokey Robinson put it as, “Believe half of what wou see, some or none of what you hear…” no doubt this is biblically influenced.

    happy 4th!

    Bill

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s