user3676125
user3676125

Reputation: 21

Difference between helper classes and wrapper classes for primitive numeric datatypes in java

I was going through some java video tutorials where the tutor references Double, Integer,Byte etc as helper classes for primitives double,int,byte. But they are supposedly wrapper classes which cause autoboxing and unboxing , so i am not able to figure out the difference between helper classes and wrapper classes.

Upvotes: 0

Views: 3002

Answers (2)

D V Santhosh Kiran
D V Santhosh Kiran

Reputation: 159

As explained by Mr. Verburg (I don't have the exact link): A helper class/method tends to be hidden from the client and is used internally to provide some boiler plate work that has no business domain meaning. For example, let's say you wanted to convert a date into a timestamp in order to save it to your particular datastore. You might have a utility class called DateConvertor with a convertDateToTimestamp method that performs this processing.

And Wrapper classes does the Boxing and Unboxing of primitive variables to Objects; Hence are called Wrapper Classes.

you have well identified that these classes are performing both the tasks. So these are called Helper classes as well as Wrapper classes. Just use the one which is more appropriate to the context.

Upvotes: 2

Eran
Eran

Reputation: 393851

Integer, Long, Character, etc... serve for both purposes.

On one hand, static methods such as Integer.parseInt(String) (which returns an int) can be considered helper methods of the primitive types.

On the other hand, they serve as wrappers for the primitive types, as you mentioned.

Upvotes: 0

Related Questions