Primitive Types

What happens when you add a primitive type (e.g. double) value to a collection?

Questions by angeebrascom

Showing Answers 1 - 7 of 7 Answers

Every one says that every concept in Java is purely prepared in Object Oriented Form only in
you need to remember one thing when Java people preparing the Java they try to create an alter
native to C or C++ so that they provided some common functionalities like primitive datatypes. If they introduced primitive datatypes in terms of Object form no one in the show their
interest to learn the Java. First people see some common functionalities and then see the advantage of new language.

So in the same way JavaSoft people introduced primitive datatypes and also they introduced Wrapper
classes. Here primitive types are not object oriented datatypes but Wrapper classes like Integer, Float, Double, String are purely Object Oriented concepts.

Generally if
you see any object in the Java will take the default value as null but primitive datatypes will take default values are different for different types for example int defined value is 0(zero),float default value is 0.0 like that. But wrapper classes default value is null check once again and confirm yourself.

In real time projects we deal with Wrapper classes as datatypes not the primitive types as datatypes.


  Was this answer useful?  Yes

pdureja

  • Apr 6th, 2011
 

Collection can hold Objects but not primitives. Prior to Java5, we need to wrap primitive using wrapper classes and in java 5 autoboxing do it automatically.

Prior to java 5:
xyzCollection.add(new Integer(10))

In java
xyzCollection.add(10) //will do autoboxing 

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions