Tell the difficulties that i am difficult.
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Jelle Klap wrote:The first creates a primitive short with value 7.
The second creates a Short object, using auto-boxing to wrap the literal short value.
Before Java 5 the second appraoch would fail, and you would have to use the Short constructor that takes a primitive short.
As of Java 5 the second auto-boxing approach is equivalent to Short.valueOf(7) (this overload of valueOf was also added in Java 5).
Tell the difficulties that i am difficult.
Jelle Klap wrote:As of Java 5 the second auto-boxing approach is equivalent to Short.valueOf(7)
Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Anayonkar Shivalkar wrote:The difference is 'short' is a primitive data type whereas 'Short' is a class - which wraps primitive 'short'.
I'm not sure, but the only reason to (now) maintain primitive data types is backward compatibility and (perhaps) low memory footprint.
I hope this helps.
Tell the difficulties that i am difficult.
saloni jhanwar wrote:if Short is class then what is short ? method or something else ?
Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Anayonkar Shivalkar wrote:You are welcome.
saloni jhanwar wrote:if Short is class then what is short ? method or something else ?
No. Its just a primitive data type. A primitive data type is predefined by language and is treated as a reserved keyword.
On another note, wrapper class for int is Integer (not Int).
I hope this helps.
Tell the difficulties that i am difficult.
Anayonkar Shivalkar wrote:
Jelle Klap wrote:As of Java 5 the second auto-boxing approach is equivalent to Short.valueOf(7)
Is it so? I thought it is
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Anayonkar Shivalkar wrote:Wrapper classes names are same as primitive data types - just first letter is capital (e.g. Boolean, Float).
Exceptions : Integer for int and Character for char.
Tell the difficulties that i am difficult.
Tell the difficulties that i am difficult.
Jelle Klap wrote:boxing uses the valueOf() / xxxValue() pairs.
You can check this yourself using javap to dissasamble a .class file.
Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)