Author | Topic: Is my understanding of what Bill Brogdon says in his book correct? |
maha anna bartender |
posted April 10, 2000 04:43 PM
Hello all, This info from Bill Brogden's Exam cram book bothers me. He says in readUTF(..)/writeUTF(..), the first 2 bytes writen are the length of the input str . But as per JAVA 2 API it is the total no of bytes calculated for ALL chars in the String after applying the UTF-8 conversion rules, which may be different from the total length of the input String. I also verfied this by the foll prog. What the API says only happens. So my qstn is does the foll info from Bill's book means the total length of the input string or not? Of it is total length of the string then it is NOT CORRECT. I had checked in his Errata page. It is not listed. I know this post is too long. Please take your own time to verify this. I will be releived. From Java API
[This message has been edited by maha anna (edited April 11, 2000).]
|
William Brogden greenhorn |
posted April 11, 2000 09:05 AM
Good call! The book is in error. Here is the documentation from the source for writeUTF. The first two bytes give the number of bytes in the translated stream.
|
maha anna bartender |
posted April 11, 2000 09:25 AM
Thank you Mr.William Brogden. I didn't expect that your reply will be so quick for my email to you. regds maha anna [This message has been edited by maha anna (edited April 16, 2000).]
|
Kondal Rao greenhorn |
posted April 17, 2000 11:16 AM
Hi Maha, I read your post. I have been reading this Bill Brogden ?Exam Cram? book. This book was written in an excellent way to prepare for the exam (atleast in my opinion). As I am seeing your answers in this forum, you take lot of interest in answering questions. I appreciate your effort in educating Java community. Having said that...here are my comments. In your post you have mentioned about paragraphs 4 and 5. But you have eliminated, paragraph 3, which was given below. When you explain a concept in a book, you do not qualify the words completely in all of their occurences like a legal document. This defeats the purpose of explaining the concept and makes it hard. Similarly, we cannot take any individual sentence from a book and say that it is wring, forgetting the context of the sentence. When you read paragraphs 3,4,5 in order, you do not get the understanding that your are actually using the value returned by the length() method in String object for writing to the outputfile as the string length. At least I did not get that understanding. ?A single character may end up encoded in one, two, or three bytes. Because there is no direct equivalence between the number of characters encoded with UTF-8 in a file and number of bytes, the reading and writing methods use a special format.? So I will not necessarily, call this as an error in the book. Regards,
|
maha anna bartender |
posted April 17, 2000 11:52 AM
Kondal Rao, Thanks for your response. As you mentioned I took a lot of care before posting this message. I read that chapter over and over again whether what I think of the author thinks is corect or not . . I never just take a meaning from a single line or in fact single paragraph. I read the paragraph in the context with all previous and post paragraphs. What I thought the author thought was. So the book is (was may be he had put in his errata)in fact in error. Also note that I wrote this post , NOT with the thinking of what I think is correct, but what the author really thinks he is correct, and if my understanding of what he thinks is correct, then the author is WRONG. which happened to be true. Also note that I never pick-up on anybody just because I want to say something.Also I just did't purposly mention only those paragraphs and didn't leave the previous paragraph also. In fact I did really post the previous paragraph initailly , and after seeing the looooooooong post I edited it. regds [This message has been edited by maha anna (edited April 17, 2000).]
|
Kondal Rao greenhorn |
posted April 17, 2000 01:00 PM
Maha, After reading your recent post, I have gone through the ?Streams and Characters? section of chapter 14. After reading this, I can never come to a conclusion that when the String ?Kondal Rao? will be written to the output file, the first two bytes (the UTF-8 encoded string length) will be 10. Instead I also came to the same conclusion as you that the following will be written to a file using UTF-8 encoding: [length in bytes after encoding in UTF-8] [encoded_K][encoded_o][encoded_n]......[encoded_o]. Anyway, let us not argue that the Rose is Red. The important issue here is, Are we clear in our concepts? Which is ?Yes? in this case, so let us move on. Regards,
|
maha anna bartender |
posted April 17, 2000 01:51 PM
Kondal Rao, It is here. From the author's book. Note the red color font. void writeUTF(String s) This method specified in the DataOutput interface writes the 'LENGTH OF THE STRING' as a 2 byte unsigned integer, then the bytes encoding the chars Anyway I am happy most of the readers didn't notice this and at the same time I wonder if they understood correctly. Ok I won't continue to reply for your post again.
|
| | |