Hi everyone I am coming from a C background and I am finding it hard to understand wrapper classes and unwrapping them and their use. Can anyone tell me how they work in english that is easy to understand. And what is an object is it a variable, a data type, a value stored in a variable? I read that everything is an object in java. And is a class a function as in c or is method a function as in c? Can someone please help me understand these :P Thanks in advance guys!!!

Here are some simplified answers to start with - you may want some follow-up questions.

A class is a data type - think of it as a struct plus some related methods. Eg a Person class has individual variables for for name etc, date of birth etc and methods to update or use those variables. Eg a Button object has all the data needed to define a GUI button, and methods to display the button, perform a callback when the button is clicked, etc.

An object is a instance of a class - eg {"John Doe", 12/12/1994} coiuld be a Person object - an instance of the class Person.

A method is like a function - you pass it some values as parameters, it processes them and (optionally) returns a value. In Java-speak a "function" is a method that doen't have any state info - ie the returned value depends only on the passed parameters.

Not everything in Java is an object. For reasons of efficiency there are also "primitive types" like int, boolean, char, float that are like their C equivalents.

Ordinary Java variables come in two types: primitive types just hold an int, float etc, and "reference" types hold a pointer to an object. It's a convention that primitive types have names that begin with a lower case letter, and classes have names that begin with an upper case.

Finally wrapper classes take a primitive vaue (int, char etc) and "wrap" it in a class because that attaches a lot of useful methods to the value. Eg a primitive int is just an integer value, but an Integer object has an integer value, and methods like parseInt(String s) - parses the String as an integer value, toHexString(), etc

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.