Results 1 to 5 of 5
  1. #1
    arnab321 is offline Member
    Join Date
    Oct 2008
    Posts
    40
    Rep Power
    0

    Default Whats the difference between these two?

    ****1st case:

    InputStream in;
    DataInputStream stin;
    HttpConnection hcon = (HttpConnection)Connector.open("http://example.com");

    in = hcon.openInputStream();
    stin = new DataInputStream(in);
    //read data from stin


    *****2nd case:

    InputStream in;
    DataInputStream stin;
    HttpConnection hcon = (HttpConnection)Connector.open("http://example.com");

    in = hcon.openInputStream();
    //read data from in



    well, im new to these terms.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Only the difference is the following line of code.

    Java Code:
    stin = new DataInputStream(in);
    So did you read about DataInputStream on Java doc?

  3. #3
    arnab321 is offline Member
    Join Date
    Oct 2008
    Posts
    40
    Rep Power
    0

    Default

    I meant whats the difference between execution of the two codes. Whats the purpose of opening a datainputstream on an inputstream? What advattage or disadvantage does it provide?
    I read about datainputstream in the doc but understood nothing except the number of functions it provides

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Read the API docs for DataInputStream and InputStream and maybe you'll find out.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by masijade View Post
    Read the API docs for DataInputStream and InputStream and maybe you'll find out.
    Yep, that's what I told too my friend. But seems to me, he's not clearly read the API. Or else, he cannot understand what Java doc says.

    Simple extraction from the API.

    public abstract class InputStream
    extends Object

    This abstract class is the superclass of all classes representing an input stream of bytes
    public class DataInputStream
    extends FilterInputStream
    implements DataInput

    A data input stream lets an application read primitive Java data types from an underlying input stream in a machine-independent way. An application uses a data output stream to write data that can later be read by a data input stream

Similar Threads

  1. Whats wrong with my maths???
    By soc86 in forum New To Java
    Replies: 4
    Last Post: 11-03-2008, 06:52 PM
  2. whats my next step
    By thirumurugan.sethu in forum New To Java
    Replies: 4
    Last Post: 10-02-2008, 10:03 PM
  3. Cannot understand whats wrong
    By Lehane_9 in forum New To Java
    Replies: 1
    Last Post: 03-06-2008, 08:57 PM
  4. Whats wrong with my code???
    By Soda in forum New To Java
    Replies: 2
    Last Post: 12-06-2007, 01:54 PM
  5. whats the difference between Java core,J2EE......
    By prince24 in forum New To Java
    Replies: 2
    Last Post: 07-11-2007, 07:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •