Results 1 to 4 of 4
  1. #1

    Red face About Scanner and BufferReader in java


    mga master unsa kalahi-an ani nla? kai sa amo school buffer reader man gud gamit then kasagaran mga tut sa net kay scanner man...btw OOP amo subject karon...

  2. #2
    Elite Member
    Join Date
    Jun 2010
    Gender
    Male
    Posts
    1,018
    Though wala ko kagamit sa scanner...

    The main difference is your iteration (ang pagbasa nimo line by line) of the data.

    Sa scanner kay explicit kaayo og klaro kaayo unsaon nimo og kuha sa next line.

    Ang BufferedReader kay implied ra nga kahinanglan ka mo iterate siya og daghan pa ni siya og makalibog sad gamay nga code.

    Something like this.
    Code:
    while( (currentLine = bufferedReader.readLine() ) != null){
           System.out.println(currentLine);
    }
    So meaning whatever imu declarations sa taas.
    You'll have to learn or you eventually find out that it gets a null value when it reaches the end of the stream.
    Compared sa Scanner, it knows it is the end of the stream when it gives you false when calling next().

    Pero same ra ang ilang usage, of going through a stream of data.

  3. #3
    Your best source of info when it comes to the ins and outs of a programming language is an API. for Java, naay Java API (online, you can also download to view it offline). I think, instructors should teach you guys how to use API or explore it first before dipping you to archaic constructs in Java. Shocking na in the beginning but when you get to know the details from API, sayon ra sabton.

    Here are the links from the online Java API:

    Scanner (Java 2 Platform SE 5.0)

    BufferedReader (Java 2 Platform SE 5.0)


    See the clear difference? Scanner is in util, BufferedReader is in io. hihihi

    I haven't use Scanner yet, kay I'm fine with BufferedReader.

    Differ pud ilang Constructor parameter(s).

    For Scanner, you only need System.in where as for BufferedReader to get input from user, you have to create BufferedStreamReader object from System.in object. Scanner just takes System.in mao dali ra cya, if you just aim for that simple task.

    Lain2 pud ang methods. ang scanner kay maka specify ka daan kung unsay expected input like nextLong(), meaning ang next na iread kay dapat Long.

    ang BufferedReader kay simple ra kaayo. read, read, readline, mark, etc.. gamay ra ug methods 9 ra. ang scanner kay pila man to uy, kapoy ihap.

    If you use BufferedReader, you still have to cast the input to an int if your expecting a number kay String man ang ireturn sa readline() method sa BF.

    sakto ba nga Java-men?

  4. #4
    Elite Member
    Join Date
    Jun 2010
    Gender
    Male
    Posts
    1,018
    @aozora

    Tama!
    Daghan ba java-men diri?...pero sakto imo

  5.    Advertisement

Similar Threads

 
  1. Replies: 133
    Last Post: 05-07-2013, 10:45 PM
  2. Replies: 5
    Last Post: 10-25-2010, 11:25 PM
  3. Looking for a private tuitor in JAVA and DATA Structure PROGRAMMING
    By cyepoohs in forum Networking & Internet
    Replies: 2
    Last Post: 10-25-2010, 11:14 PM
  4. For Sale: Epson cx3700 3 in 1 (printer, scanner and photocopier)
    By spunk20 in forum Computers & Accessories
    Replies: 5
    Last Post: 05-17-2010, 10:12 AM
  5. Completely stumped by scanner error in java
    By Kirksp08 in forum Programming
    Replies: 3
    Last Post: 04-13-2009, 09:39 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top