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?
Comparing Objects Vs Comparing Primitive data Types Topic: Discuss how do we compare Strings for equality?...
Comparing Objects Vs Comparing Primitive data Types Topic: Discuss how do we compare Strings for equality? Provide coding examples. How String comparison is different than the primitive data type comparison? Please cite any resources you used.
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?
Write a c statement to declare variables of primitive data types, and assign values to the...
Write a c statement to declare variables of primitive data types, and assign values to the variables. Use common control structure in c, such as if, switch, break, for, while statements. Write a c program that takes command line parameters, and perform some computation based on the command line input. Write c statements to generate random number within a certain range. Write a c statement to declare array variables of primitive data types, and assign values to the elements of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT