why the primitive data type have classes?

Answers were Sorted based on User's Feedback



why the primitive data type have classes?..

Answer / ranganathkini

All of Java's primitive data types have an associated
Wrapper class. These wrapper classes provide useful
functions such as conversion or comparisons most of which
are used by Java implicitly.

Also a wrapper serves as a container for primitive values in
conditions where a reference type is expected.

Is This Answer Correct ?    7 Yes 0 No

why the primitive data type have classes?..

Answer / manikandan [ gtec,vellore ]

there are different type of data types such as int,char
etc.for example suppose if we using arrays it can store a
similar data types but we need to store a char and int in a
same array what can we do for this situation. the wrapper
class helps in this situation by storing a objects in to a
arrays.

example

ArrayList v=new ArrayList();
v.add(new Integer(1));
v.add(new Character('a'));//

the int and char are different type but we stores it by an
object.

Is This Answer Correct ?    2 Yes 2 No

why the primitive data type have classes?..

Answer / zoozoo

because primitive datatypes cannot directly be used through network, like we cannot send them to one n/w to another. so by using wrapper classes to wrap them into objects, which can be sent through n/w.

Is This Answer Correct ?    0 Yes 0 No

why the primitive data type have classes?..

Answer / aditya mohata

These classes are Wrapper classes.We hav them as we cant
pass an primitive directly through an method to different
class.So we need wrapper classes to convert them to their
already defined classes.Send them n again unpack them.

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More Core Java Interview Questions

What is the purpose of lambda expressions?

0 Answers  


Write a regular expression to validate a password. A password must start with an alphabet and followed by alphanumeric characters; its length must be in between 8 to 20.

0 Answers  


What are non-access modifiers?

2 Answers   Cognizant,


What is local variable and instance variable?

0 Answers  


We can write any Java Logics in our JSP. Then why we are using servlets(Controller Layer) to interact with the DAO ?

6 Answers   TCS,






what is object deep copy and shallow copy and why it is required?

2 Answers  


what is diff bet iterator and enumeration?

4 Answers  


Explain serialization and deserialization in java?

0 Answers  


What is difference between adapter class and listener?

0 Answers  


My interview asked what is dynamic variable in java and where we use them.

2 Answers   IBM,


Is it possible to do method overloading and overriding at a time

3 Answers   L&T,


What are different types of constants?

0 Answers  


Categories