File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Wrapper class constructors 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 "Wrapper class constructors" Watch "Wrapper class constructors" New topic
Author

Wrapper class constructors

Neha Monga
Ranch Hand

Joined: Mar 13, 2007
Posts: 34
Hi All!

Compiler complains for the following code -->

public class XXX {
public static void main(String args[]) {
byte a = 10;
Byte x = new Byte(a);
Byte y = new Byte(11);//compiler complains
System.out.println(x.compareTo(y));
}
}


Why the compiler does not complain for the following code -->

public class ZZZ {
public static void main(String args[]) {
Float f = new Float(32D);//compiler does not complain
System.out.println(f);
}
}

pls clarify..Thanks
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Have you by any chance looked at the API for these classes?


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Abdul Mohsin
Ranch Hand

Joined: Apr 26, 2007
Posts: 111

just go through the java doc.
In your first code 11 is "int" that is default type for integer type and there is constructor defined which take "int" and "int" is not automatically converted into byte .
if you change your code to
Byte y = new Byte((byte)11);// compiles fine

second code is perfectly fine
there is a constructor defined
Float(double value) in API just go through it.

Regards,

Abdul Mohsin


Regards, Abdul Mohsin
krishna bulusu
Ranch Hand

Joined: Aug 28, 2006
Posts: 185
check with the javaDoc,
there is no costructor for new Byte(int value)
but, there is a constructor for new Float(double value).


Thanks&Regards, Krishna.
SCJP1.4, SCWCD1.4, SCBCD 5.0
Neha Monga
Ranch Hand

Joined: Mar 13, 2007
Posts: 34
okay...i found my answer in API...

thanks
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
"krishna" while we appreciate your responses to the questions on this forum, you are getting near the post count limit where we close your access to JavaRanch for disregarding our JavaRanch Naming Policy. So please change your display name immediately (in brief: <first name><space><family name> ;) .

Thanks
-Barry

(close)
[ May 23, 2007: Message edited by: Barry Gaunt ]
krishna bulusu
Ranch Hand

Joined: Aug 28, 2006
Posts: 185
I have changed my dispaly name.
Is there any post count limit here? I really don't know that
if yes, can you tell me or give the link where can i get that information.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Originally posted by krishna:
I have changed my dispaly name.
Is there any post count limit here? I really don't know that
if yes, can you tell me or give the link where can i get that information.


You do not need to know about the post count exact limit when we lock your account when it has an invalid display name. You have just to worry about getting your display name changed.

Your display name seems to still be "krishna", what did you change it too?
[ May 23, 2007: Message edited by: Barry Gaunt ]
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Hi Barry

Is there any limits on the number of posts ? If so on what frequency its taken into account?

If it really matters, can you please redirect us to the page where we will be educated on it!

Thank you.


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Hi

[RM]:Is there any limits on the number of posts ? If so on what frequency its taken into account?

I think, no I'm sure Barry was referring to the fact that incase you do have a display name that does not meets the Javaranch standards then your account could be deleted.

[EDIT] Had forgot to add the does not words in my orignal post.
[ May 24, 2007: Message edited by: Anupam Sinha ]
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Originally posted by Anupam Sinha:
Hi

[RM]:Is there any limits on the number of posts ? If so on what frequency its taken into account?

I think, no I'm sure Barry was referring to the fact that incase you do have a display name that does not meets the Javaranch standards then your account could be deleted.


Exactly.
[ May 29, 2007: Message edited by: Barry Gaunt ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Wrapper class constructors