• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Another question from Khalid

 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I said in another thread, this question is a harder question but brings up some good points to remember.
4. Which method implementations will write the given string to a file named "file", using UTF8 encoding?

Select all valid answers
A. Implementation A
B. Implementation B
C. Implementation C
D. Implementation D
E. Implementation E

Try it out as a test question first, and then try compiling it to see if you are right. I got this one wrong the first time through Khalids exam.
Bill
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually I too got it wrong. I compiled and tested the answers are A & B. No setEncoding in FileWrite C is wrong, No constructor for FilterWriter(FileWriter,String) D is wrong and OutputStream is abstract.
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Close Sivaram, but A and B is what I first thought it was. You are right about C, D, and E though.
C false - there is not setEncoding() method
D false - there is no constructor for FileWriter that takes (FileWrite, String) as parameters
E false - Output stream is an abstract class so you can't say new OutputStream. There is a constructor of the OutputStreamWriter class that takes (OutputStream, String) as parameters, but it must be a class that is subclassing OutputStream.

So, which one of A and B are not correct and why.
Bill
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I think option B would be the right one as in option A we dont specify the encoding method and hence depending on the default setting it could vary.
MKBala...
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bill,
A is not correct because it can't mention the encoding. only B can specify the encoding in its constructor. hence B is correct.
Correct me if i am wrong
rajani
 
Balamurugan Kandasamy
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Think the above post is not structurally well formed ::
Option B is right.
Option A need not be right as the default encoding may vary depending on system settings.
MKBala...
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your right, B is the only correct answer. The default encoding method is the method that is set on the local machine, so the only way to guarantee the encoding of UTF8 is to assign it with OutputStreamWriter constructor that looks like this:
OutputStreamWriter(OutputStream out, String enc)
First time I did the exam, I thought A was correct also, and when you compile it, it looks correct, but B is the only option that is guaranteed to be correct.
Bill
[This message has been edited by bill bozeman (edited December 20, 2000).]
 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually the question is not precise enough. It could be rephrased as follows:
"Which method implementations will write the given string to a file named "file", using UTF8 encoding, regardless of the default character encoding of the local machine?
 
Good heavens! What have you done! Here, try to fix it with this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic