Captain Cooper

Greenhorn
+ Follow
since Jul 14, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Captain Cooper

Some1 suggested ... in the "I/O and Streams"


No, it's a good question, I think. For InputStream there's the fact that we need to be able to return a special value to indicate an end of stream. So all possible byte vaues are mapped to the 0-255 range, and -1 is used to indicate end of stream - meaning we need more than 256 values, and the return type needs to be larger than byte. And the same situation for a Reader means that the return type for read() needs to be larger than short. It seems that int is the logical candidate for both - Java was written with the assumption that the natural word length on any machine it runs on, would be at least 4 bytes - so there's no performance difference in using an int where only a short or byte was needed. As for OutputStream and Writer though, I don't see any good reason why their write() methods should expect ints. Maybe it's just for consistency with the read() methods. Maybe it's because int operands are so common, that they didn't want to force an explicit cast whenever write(x) is used. But that seems a weak reason to me. It would be better if users were forced to write the cst, so they'd realize that bits could be lost in the operation. Perhaps someone else knows a better answer...


Sounds convincing?
Redirecting from Big Moose Saloon -->> I/O and Streams
It may sound very dumb ... asking such a basic question. Anyway, I'm really curious to know if someone could please share w/ me ... why do one of the read()/write() methods deal w/ int while working w/ "byte" in OutputStream?


How come the Version 1 works But Version 2 does not?
VERSION 1
<code>
class Base {
void amethod(long l) {
System.out.println("Base long");
}
}
public class Scope extends Base {
public static void main(String argv[]){
Scope s = new Scope();
s.amethod(1);
}
void amethod(int i) {
System.out.println("Scope int");
}
}
</code>
VERSION 2
<code>
just twist the two signatures of amethod(...) and it does not compiles for a method call from main() like s.amethod(1); However, in that case if you put s.amethod(1L) that works!
</code>
my point is why is it not necessary to specify 1L in the 1st version?
NB: I'm using jdk1.3

[This message has been edited by Captain Cooper (edited July 15, 2001).]
It may sound very dumb ... asking such a basic question. Anyway, I'm really curious to know if someone could please share w/ me ... why do one of the read()/write() methods deal w/ int while working w/ "byte" in OutputStream?
20 years ago