wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Difference between BufferedInputStream and InputStream ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Difference between BufferedInputStream and InputStream ??" Watch "Difference between BufferedInputStream and InputStream ??" New topic
Author

Difference between BufferedInputStream and InputStream ??

Bikash Paul
Ranch Hand

Joined: Dec 04, 2001
Posts: 342
Hi,

Can any one pls tell me What is the difference between BufferedInputStream and InputStream ?

Another Question is :

I have a below class and when i print the object that class then what it prints?

Reference of that class or byte code of that class ?

It is printing :
Object **** x@cac268

Thanks & Regards
Bikash
[ June 18, 2004: Message edited by: Bikash Paul ]
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
InputStream is an abstract class with a read() method intended to read one byte at a time from a file.

BufferedInputStream is not abstract, so you can actually create an instance. Its read() method still returns one byte at a time but it reads ahead internally to fill a buffer. That way, most calls to read() are non-blocking. The byte is already in the buffer and is immediately returned to the caller.

Your Test class does not override the toString() method it inherits from Object. That default toString() method creates a reasonably unique String for each unique object. From the API spec:
The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

getClass().getName() + '@' + Integer.toHexString(hashCode())
As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)


The '+' operator calls the toString() method of an object when it is concatenating an object to a String. System.out.println() just prints the resulting String.

I tested your code on SDK 1.4.2 and got:
Object **** Test@7ced01


[ June 18, 2004: Message edited by: Mike Gershman ]
[ June 18, 2004: Message edited by: Mike Gershman ]

Mike Gershman
SCJP 1.4, SCWCD in process
Bikash Paul
Ranch Hand

Joined: Dec 04, 2001
Posts: 342
Hi,

First of all thanks for the answer of my first question.

But for my second question i want to know that when we prints a object
(without override the toString() method inherits from Object) of a class then what it prints?

Is It prints unsigned hexadecimal representation of the hash code of the object?

or

Is It prints object representation of the class in bytecode ?

Thanks & Regards
Bikash
[ June 18, 2004: Message edited by: Bikash Paul ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

The Javadocs APIs are the best source of information for how a method like "toString()" behaves. From the Javadocs:


The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

getClass().getName() + '@' + Integer.toHexString(hashCode())



Note that the Javadoc for Object.hashCode() states that


As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)


[Jess in Action][AskingGoodQuestions]
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
Object.toString() is the class name + '@' + the object's hash in hex.

The object's hash can be the object's address, but it is just defined as a reasonably unique identifier of the object.
 
Consider Paul's rocket mass heater.
 
subject: Difference between BufferedInputStream and InputStream ??
 
Similar Threads
Difference between String variable and String Object ???
difference between BufferedInputStream(or output) and other i/ostreams,regarding buffers.
Unicast and Multicast object ???
java io UTFDataFormatException: Invalid byte 1 of 1-byte UTF-8 sequence
a question on the variable types..