aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Missing constructor that accepts a String in class Character 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 "Missing constructor that accepts a String in class Character" Watch "Missing constructor that accepts a String in class Character" New topic
Author

Missing constructor that accepts a String in class Character

Andy James
Ranch Hand

Joined: Aug 22, 2005
Posts: 90
All the other wrapper classes (Byte, Short, Integer, Long, Double, Float, Boolean) define a constructor that accepts a String argument. Was there a specific reason why it wasn't defined for the class Character?

Thanks.

cheers
Andy
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Why do we need a String argument parameter to Character class Constructor? Instead of putting a double(") quotas in the Constructor, you can put a single(') quotas! This may be the reason!


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Was there a specific reason why it wasn't defined for the class Character?


If I pass in a String, which is a CharSequence of characters, as the input, which one of these characters should the resulting Character Object represent ? Should an exception be thrown when the String length is greater than 1 character ? Would that be the expected behavior ?


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Andy James
Ranch Hand

Joined: Aug 22, 2005
Posts: 90
Abimaran,
Thanks for the reply.

Deepak,
You ask a good set of questions in answer to a single question:
which one of these characters should the resulting Character Object represent ? Should an exception be thrown when the String length is greater than 1 character ? Would that be the expected behavior ?


I apologize if my thought seem to be rude. It seemed that you were irritated while answering this question, as if it seemed quite obvious to you. Examine the source code of the Java API (or for that matter any API) and you will be able to find loads of examples, where code is redundant or seems to be offering functionality that could have been avoided easily.
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

I apologize if my thought seem to be rude. It seemed that you were irritated while answering this question, as if it seemed quite obvious to you.


haha ! Not at all. Your question was interesting. The way I would have handled it is to not provide a constructor since the expected behavior might be confusing. But thats just me.

The reason I raised those questions was to put seeds of thought into your mind. Your answers, if they can be justified technically, might well prove me wrong. So the questions are mutually beneficial to you, me and the community at large.

Please feel free to ask as many questions in JR as you see fit. We have a 'Be nice' policy that everyone will follow when they answer your questions.
 
wood burning stoves
 
subject: Missing constructor that accepts a String in class Character