Win a copy of Getting started with Java on the Raspberry Pi this week in the Raspberry Pi forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Liutauras Vilda
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Piet Souris

Byte streams and the super keyword

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(1) I wrote a java program involving the use of the FileInputStream class to read from a plain text and executable file. As expected, being a byte stream, the
generated result was a series of integers representing the individual bytes read from the stream. The sample results look like this:

49 43 182 0 23 54 4 178 0 20 187 0 11 89 21 4 184 0 26 183 0 16 18
......................and so on. The integers spans rows. I use my program to determine the byte count. Of course i know if I'm to read the plain text file and
view it as it really is i.e. see the text in the result i should use a FileReader character stream. My concern for this question is not character streams. I'm
interested in knowing how the individual bytes got resolved into integers of varying ranges. I'm aware that byte data type have a range of 0-255 for unsigned
integers and that's why non of the output integers exceed that range safe for the -1 integer value that marks the end of the file. Most interestingly, the numbers
of the integers exceeds the number of words making up the plain text. How did the integers of varying ranges came to be? Are the individual integers a result of
each individual character of the text. Is there a provision for the spacing between the words that make up the text. What are the zeros in the outcome
representing? I'll appreciate a clear explanation.

(2) One of the established rules of implementing proper object formation via inheritance is to make a call to the superclass constructor the first statement
after defining the subclass constructor. Something i want to get clearly is that, if the superclass portion of my subclass object get initialized via call to
super(a,b); does this actually translate to the automatic initialization for this instance variables for the subclass portion of the code even if this variable
have private access in the superclass? If the subclass constructor is used as a means of initializing the superclass portion of the code, is the subclass
constructor actually initializing itself with these values as well since it has access to the variables by inheritance? Is it typical that the superclass and subclass
constructors can intitialize themselves differently (with different values) for the same kinds of attributes(variables)? I'll appreciate a clear answer to this
question putting into consideration the access level from the superclass.

Olakunle Oni

.
 
author
Posts: 23939
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Olakunle Oladipo Oni wrote:(1) I wrote a java program involving the use of the FileInputStream class to read from a plain text and executable file. As expected, being a byte stream, the
generated result was a series of integers representing the individual bytes read from the stream. The sample results look like this:

49 43 182 0 23 54 4 178 0 20 187 0 11 89 21 4 184 0 26 183 0 16 18
......................and so on. The integers spans rows. I use my program to determine the byte count. Of course i know if I'm to read the plain text file and
view it as it really is i.e. see the text in the result i should use a FileReader character stream. My concern for this question is not character streams. I'm
interested in knowing how the individual bytes got resolved into integers of varying ranges. I'm aware that byte data type have a range of 0-255 for unsigned
integers and that's why non of the output integers exceed that range safe for the -1 integer value that marks the end of the file. Most interestingly, the numbers
of the integers exceeds the number of words making up the plain text. How did the integers of varying ranges came to be? Are the individual integers a result of
each individual character of the text. Is there a provision for the spacing between the words that make up the text. What are the zeros in the outcome
representing? I'll appreciate a clear explanation.
.



Most text files use ASCII as the mapping -- meaning it uses byte values up to 127 to represent characters. Google for ASCII table to see the mapping.

Other text files uses unicode, which is actually ASCII -- extended with character that takes more than one byte.


Regardless of the mapping, the characters, all of the them, including the spaces, tabs, carriage returns, etc. maps to byte representations.

Henry
 
Henry Wong
author
Posts: 23939
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Olakunle Oladipo Oni wrote:
(2) One of the established rules of implementing proper object formation via inheritance is to make a call to the superclass constructor the first statement
after defining the subclass constructor. Something i want to get clearly is that, if the superclass portion of my subclass object get initialized via call to
super(a,b); does this actually translate to the automatic initialization for this instance variables for the subclass portion of the code even if this variable
have private access in the superclass? If the subclass constructor is used as a means of initializing the superclass portion of the code, is the subclass
constructor actually initializing itself with these values as well since it has access to the variables by inheritance? Is it typical that the superclass and subclass
constructors can intitialize themselves differently (with different values) for the same kinds of attributes(variables)? I'll appreciate a clear answer to this
question putting into consideration the access level from the superclass.
.



Not exactly sure what you are asking... so will take a guess.

Keep in mind that a subclass extends a superclass -- so it has all the components of the superclass, which has to be initialized. This initialization is done with the constructors of the superclass.

Henry
 
Sheriff
Posts: 3062
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are a number of ways to encode text files, and if you use a FileReader to read one, you have to tell it which encoding to use. In an ASCII encoding, for example, each character is represented as a one byte integer. White space characters such as the single space, tab, carriage return, and line feed each have their own integer encoding just like letters, numbers, and symbols.

The limitation of ASCII is it can't represent all the world's alphabets. Other encodings are used for that, particularly UTF-8. In UTF-8, a single character may be encoded as one to three bytes, and that may be why you see 0s in your output. That 0 byte might be just one byte of a multibyte encoding.

Note that the range of a Java byte is -128 to 127, not 0 to 255 as you say. However, a byte is just an arrangement of bits. The same arrangement can be considered -1 or 255, depending how you look at it, but Java will look at it as -1 for arithmetic, comparison, or printing. You see values above 127 in your output, which means you aren't just printing bytes through System.out.print().
 
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
Low Tech Laboratory
https://www.kickstarter.com/projects/paulwheaton/low-tech-0
reply
    Bookmark Topic Watch Topic
  • New Topic