my dog learned polymorphism
The moose likes Java in General and the fly likes java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "java" Watch "java" New topic


alok neha

Joined: May 24, 2004
Posts: 1
what is difference between wrapper classes and static classes though we need not to create a class object for creating an instance of the class.
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
These are completely different.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
A wrapper usually makes life easier for clients (developers who code classes that use some other class) by hiding some tricky details. Frinstance I've been working on a wrapper that has simple methods like lookUpCode(x). Inside it uses a factory to get a proxy for a remote object, handles some exceptions, translates some argument types, etc. Without the wrapper, we'd make everyone who wants to call a method learn all those tricky bits.

I think by static class you mean a class with all static methods. Some OO folk call these "utility" classes. Since good objects are a combination of data and behavior and these seem to have behavior only, they are sometimes considered poor objects. I don't mind em because they are easy to call.

Wrappers could be static which leverages "easier to call" twice, but not all of them are. Static classes could be wrappers or plain stand-alone objects.

Hope that helps. Hope you enjoy learning more of these OO idioms and patterns. I think it's all a real blast and there's more than enough to keep your brain busy for a long while.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
Well there are 2 types of uses for wrapper classes.

First type:
Classes that wrap primitives. These are classes that are taking an int and making it an Integer. Or taking a float a Float. This may give you certain abilities like converting a String to an int or an int to a String as well as other functions.

Second type:
Wrapper classes are also used to simplify. Imagine you have some very complex classes that do many things. Say... HTTPUnit. HTTPUnit has some very powerful things you can do with it. However the issue might be that it may be too complex for your needs. You may be able to create a wrapper class to simplify the code to pull out only what you need and hide other complexities. This is exactly what JWebUnit has done. JWebUnit is basically a bunch of wrapper classes for HTTPUnit. It really doesn�t add functionality. It just simplifies it.

There really is no such thing as a static class. There are static methods in a class and there might be static variables attached to the class, but no such thing as a static class. When you hear static think ONE. There is only ONE instance of the static item. That static item will always be attached to the class. If its a static method, then that method is the only one in existance. If its a static variable, then that variable is the only instance.

Try checking out singletons.

Hope that helps.
[ May 26, 2004: Message edited by: Dale DeMott ]

By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
I agree. Here's the link:
subject: java
It's not a secret anymore!