Now when we read a character stream it is always 2 bytes (transfering two by two or byte-byte?)
When we write in a binary stream,no data transformation occurs for example an int is written as 4byte(because that's what it is in ram), a character 2 bytes etc.
Also the integer 5 would be stored as 101. Why is 101 and not 00000000 00000000 00000000 00000101 as long as it commits 4 bytes per int?
No, a character does not always take up two bytes when read from or written to a stream. How many bytes a character uses depends on the encoding.
If you use ASCII, a character is always 1 byte. If you use UTF-8, then the number of bytes per character is variable (at least 1 and at most 4 bytes).
In Java I/O, there are two kinds of classes: streams and readers / writers. Streams (InputStream and OutputStream) are used for reading and writing binary data (i.e. you use them to read the exact contents of a file on disk, for example). Readers and writers are used to read or write text. Readers and writers convert the bytes from and to characters, using a character encoding.
An int in Java is always 32 bits in memory, regardless of which bits are set to 0 and which bits are set to 1.
In memory, a char is a 16-bit Unicode character. But when you write that character to a file, it has to be converted to a representation, using a character encoding. ASCII is just one of the available character encodings. Ofcourse you can't encode all Unicode characters in ASCII - you'll lose information when you use ASCII.
michael delta wrote:5 is 101,if i read an integer 5 i would read 3 bytes of zeros and a "byte of 5" right?
An int is 32 bits = 4 bytes in memory, if the int would have the value 5 then that would be three bytes with a value of zero and one byte with a value 00000101 (in binary). But note that it's not as simple as that - the order in which those four bytes are stored can be different. Different kinds of processors store integers in a different order in memory, see endianness.