aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Encoding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Encoding" Watch "Encoding" New topic
Author

Encoding

Deepa sivasankar
Ranch Hand

Joined: Jul 22, 2003
Posts: 35
Maha anna,
Can you please explain this objective ?
Distinguish between conditions under which platform default encoding conversion should be used and conditions under which a specific conversion should be used.
Can you tell me when you use the sockets what kind of encoding should be used?.
My answer is that we should use ascii 8 bit stream datatype and not character 16 bit unicoding.
I would appreciate your help.
Thanks
Deepa
Deepa sivasankar
Ranch Hand

Joined: Jul 22, 2003
Posts: 35
Can someone elaborate on this?please
Deepa sivasankar
Ranch Hand

Joined: Jul 22, 2003
Posts: 35
Can someone shed some light on this encoding part?. Please...
thanks for ur help
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Deepa,
Answer to your first question is covered under an old discussion( actually initiated by you ). Here is the link http://www.javaranch.com/ubb/Forum24/HTML/001685.html
About Sockets, I am not sure if it is something you need to worry for the SCJP. It is not a part of the objectives. As far as I understand, since sockets are used to communicate between two machines, what flows across the wire are raw bytes. You can send anything, as long as you are able to reconstruct the information at the receiving end. So, encoding has no relevance here. May be( I am not sure again, ) Socket-based streams can be chained to readers/writers and only then you can specify encoding schemes.
Hope this helps.
Ajith

Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Deepa sivasankar
Ranch Hand

Joined: Jul 22, 2003
Posts: 35
Thanks ajith, again.
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Deepa,
Sorry for the delayed reply.
Distinguish between conditions under which platform default encoding conversion should be used and conditions under which a specific conversion should be used.
When we read/write text into a file, the file io classes use the encoding method either specified in the arg of the IO classes , or the default encoding scheme. For 'streams' /raw bytes encoding is not needed. Maximum we gather the bytes as byte/char/short/int/long/float/double. For this we use the high level streams DataInputStream/DataOutputStrerm which has the readByte/readInt... all primitive reading methods.
But to read a text file which may use any encoding scheme, for Japaneese char may be one scheme/For Chineese chars may be another scheme . So when we write a Japaneese chars/text file using Japaneese encoding scheme, when you write and read from the same machine/computer you need not explicitly specify the 2nd argument 'String encoding' of new InputStreamReader(InputStream, String enc) . We can omit the 2nd arg.
But what if you transfer the file across to machines using sockets.You just send the text file over the Internet. At the same time you int the InputStreamReader and OutputStreamWriter classes of your appln you explicitly say the 'enc' scheme. Otherwise if you run your application, it is going to use the default encoding scheme of the other machine. This creates confusion especially if you already preparea a text file here and send this textfile over the net and try to read this file using another encoding scheme. It may produce jnk.
So these are the 2 conditions where the encoding scheme is needed snd NOT needed. In other words , if read/write of text file happens in the SAME machine need not specify explicit encoding to the Reader and Write classes. If you read/write in ONE machine and write/read int another it is BETTER to explicitly specify the encoding scheme to InputStreamReader/Writer classes. I think for the 2nd qstn Ajith answered.
regds
maha anna
Deepa sivasankar
Ranch Hand

Joined: Jul 22, 2003
Posts: 35
Thanks Maha for a great explanation. I appreciate it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Encoding