Question

In: Computer Science

Why do you think Java provides both primitive data types and wrapper classes for them? Why...

Why do you think Java provides both primitive data types and wrapper classes for them? Why not just one or the other?

Solutions

Expert Solution

Java provides both primitive data types and wrapper classes.java being object-oriented in nature and expects everything in the form of an objects . so Primitive datatypes are converted into objects by using Wrapper classes.

A Wrapper class is a class whose object wraps or contains a primitive data types.

When we create a wrapper class object , it contains a field and in this field and can store a primitive data types. In other words, we can wrap a primitive value into a wrapper class object.

The following picture shows both primitive data types and wrapper classes.

Need of Wrapper Classes:

  1. They convert primitive data types into objects. Objects are needed if we wish to modify the arguments passed into a method (because primitive types are passed by value).
  2. The classes in java.util package handles only objects and hence wrapper classes help in this case also.
  3. Data structures in the Collection framework, such as ArrayList and Vector, store only objects (reference types) and not primitive types.
  4. An object is needed to support synchronization in multithreading.

Related Solutions

What are wrapper classes and why are they useful for ArrayLists? In your answer, include examples...
What are wrapper classes and why are they useful for ArrayLists? In your answer, include examples of autoboxing and unboxing. Your Discussion should be at least 250 words in length, but not more than 750 words. Once you’ve completed your initial post, be sure to respond to the posts of at least 3 of your classmates.
Probiotics: Do You Need Them? What do you think? Do you think you should add probiotics...
Probiotics: Do You Need Them? What do you think? Do you think you should add probiotics to your diet? Why or why not? Do you think we know enough about probiotics to recommend them to the public? Site your source
do you think we should be testing on animal and using them for research? explain why?
do you think we should be testing on animal and using them for research? explain why?
Answer the following question: Why do you think eating disorders are on the rise for both...
Answer the following question: Why do you think eating disorders are on the rise for both men and women? Search the internet and find a photo that reflects how social media has shaped society's thinking and maybe our own. Please make good choices when choosing your picture! When you find that perfect photo please post the URL and briefly give one or two sentences discuss the photo. Keep in mind the following: What is the ‘reality’ behind these photos? How...
Connective tissue is the most diverse of all tissue types. Why do you think that is?...
Connective tissue is the most diverse of all tissue types. Why do you think that is? Why do you think blood and lymph are classified as a type of connective tissue?
Do you think every program needs all three (algorithms, flowcharts, and pseudocodes) of them? Why or...
Do you think every program needs all three (algorithms, flowcharts, and pseudocodes) of them? Why or why not? Justify your answer with examples. If you plan to create any two of them for a program, which one would you eliminate? Why? You have read about fundamental data types in your book. Are these data types enough to represent all data or do you think additional data types are needed? Why or why not? Explain your answer with examples. Looking at...
Some genes don’t appear to have any mutations associated with them. Why do you think this...
Some genes don’t appear to have any mutations associated with them. Why do you think this is?
Why do you think some business owners classify people that work with them as contractors when...
Why do you think some business owners classify people that work with them as contractors when they should actually be classified as employees? What is the difference and why does the government care?
Someone says that face-to-face classes always do better than online classes, you disagree and think they...
Someone says that face-to-face classes always do better than online classes, you disagree and think they are the same. You gather data and below is some fictitious data. Group 1 percentage Group 2 percentage Median 0.610 Median 0.74553571 Mean 0.646 Mean 0.68526786 St. Deviation 0.225 St. Deviation 0.18357571 n 16 n 18 Hint you'll need to convert the percentages to something else, and ask yourself are they proportion or mean... Provide: Null and Alternative Hypothesis, Test statistic, p-value, (**alpha is...
In JAVA (eclipse).... Extract both files and place them in your program’s folder. You will be...
In JAVA (eclipse).... Extract both files and place them in your program’s folder. You will be using them. In your driver class: • Create an array called “boyNames” and store all names from the BoyNames.txt file • Similarly, create an array called “girlsNames” and store all names from the GirlNames.txt file • Create a text menu that allowing users to: 1. Enter a name and the application must display a message indicating if the name is among the most popular...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT