-
October 16th, 2004, 11:34 AM
#11
hypronix, I've never seen the Scanner class before. Is it a new class added in Java 2 v5? I haven't yet explored it .
Cheers,
cgkanchi
-
October 16th, 2004, 11:40 AM
#12
Originally posted here by cgkanchi
hypronix, I've never seen the Scanner class before. Is it a new class added in Java 2 v5? I haven't yet explored it .
Cheers,
cgkanchi
Yup! Wouldn't work on anything else, but if you tried that code [I did ] you'd see it runs smoothly... I haven't been exposed to any other form since I've just started out studying Java about a month ago [had the first midterm two days ago ]. But yeah, it was first released in 1.5 beta 1, used to get called as:
Code:
Scanner varName = Scanner.create(System.in);
but in the stable version it gets called like so
Code:
Scanner varName = new Scanner (System.in);
I s'ppose you could pass some other argument to it [not just System.in] but that's the only one I used so far.
/ \\
-
October 16th, 2004, 12:41 PM
#13
Originally posted here by cgkanchi
;TT :
It should be buf.readLine() for String input. BufferedReader.read() only works for int's and char's.
Phonedog911:
Strange. I tried it out and get the same thing. Both are supposed to be equivalent. Looks interesting... I'll play a bit and get back to you.
Cheers,
cgkanchi
Knew I'd make a mistake like that... I was taught input using the cs1.jar package so good eye.
-
October 17th, 2004, 02:15 AM
#14
thanx for the input, the teach has taught us to only use a buffered reader when you need to parse the input into an integer, we've been using system.in.read() for characters and he really should have said something if he wanted us to do it this way...
-
November 7th, 2004, 07:07 AM
#15
Member
Originally posted here by hypronix
But yeah, it was first released in 1.5 beta 1, used to get called as:
Code:
Scanner varName = Scanner.create(System.in);
but in the stable version it gets called like so
Code:
Scanner varName = new Scanner (System.in);
You were correct in you assumption. Now you can scan from Files, String and Readables in addition to streams.
As far as the visible change, from method call to constructor, they were using a factory to create them before, meaning that the one method (create()) did all of the hard work for you, my guess is that they changed it from an extendable or abstract class/interface into a final class and decided to make the constructors public because they can't be extended now, and besides a factory isn't necessary in a final class, because the purpose of a factory is to return an instance of the proper sub-class.
If you would like to know more about factory patterns or any of the many other software design patterns and their many benefits check out some of these sites:
http://www.dofactory.com/patterns/Patterns.aspx
http://hillside.net/patterns/
http://www.cs.wustl.edu/~schmidt/patterns.html
and many, many more...
--BigDick
\"When in Rome, eat Rome!\" -Godzilla
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|