Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 instead of thisArrayList. An integer is wrapper classof int primitive type. We use a Java wrapper class because forgenerics we need objects, not the primitives."Generics' is coveredin Chapter 17, which we will not be able to cover thissemester.

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Programming questions

Question

2. Ask, What would happen if?

Answered: 1 week ago

Question

The major factors to consider when choosing a security to trade?

Answered: 1 week ago

Question

The basics of intermarket analysis?

Answered: 1 week ago

Question

Therelationship between hard asset and soft asset markets?

Answered: 1 week ago