• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Encoding

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone elaborate on this?please
 
Deepa sivasankar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone shed some light on this encoding part?. Please...
thanks for ur help
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Deepa sivasankar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks ajith, again.
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Maha for a great explanation. I appreciate it.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic