Question
Introductionto Wrapper classes, this is a tool or concept provided in theJava Programming Language that gives us a way to utilize nativedatatypes as Objects with
Introductionto "Wrapper" classes, this is a tool or concept provided in theJava Programming Language that gives us a way to utilize nativedatatypes as Objects with attributes and methods.
A Wrapper class inJava is the type of class which contains or the primitive datatypes. When a wrapper class is created a new field is created andin that field, we store the primitive data types. It also providesthe mechanism to covert primitive into object and object intoprimitive.
Working withcollections, we use generally genericArrayList
Advantages of Java Wrapper Class
- They are used to convert the primitive data types into objects(Objects are needed when we need to pass an argument in the givenmethod).
- The package java.util contains classes which only handlesobjects, so it helps in this case too.
- Data Structures store only objects and primitive datatypes.
- In multithreading, we need an object to supportsynchronization.
Primitive Data Type | Wrapper Class |
byte | Byte |
long | Long |
float | Float |
int | Int |
1. Create a WordCounter application, submit WordCounter.java.
Word Counter takesinput of a text file name (have a sample file in the same directoryas your Word Counter application to we don't have to fully path thefile). The output of our Word Counter application is to echo thefile name and the number of words contained within the file.
Consult Code Listing9-9 and 9-10 for examples of analyzing data in a file. Notice theCode listings use Exceptions, we will learn MORE aboutExceptions and Exception Handling in Chapter 11, so stay tuned!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started