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 :D.
Cheers,
cgkanchi
Printable View
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 :D.
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:Quote:
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 :D.
Cheers,
cgkanchi
but in the stable version it gets called like soCode:Scanner varName = Scanner.create(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.Code:Scanner varName = new Scanner (System.in);
Knew I'd make a mistake like that... I was taught input using the cs1.jar package so good eye.Quote:
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
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...
You were correct in you assumption. Now you can scan from Files, String and Readables in addition to streams.Quote:
Originally posted here by hypronix
But yeah, it was first released in 1.5 beta 1, used to get called as:
but in the stable version it gets called like soCode:Scanner varName = Scanner.create(System.in);
Code:Scanner varName = new Scanner (System.in);
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...