Tuesday, September 24, 2013

class vs primitive data type in Java

Java has 8 primitive data types, they are byte, short, int, long, float, double, boolean, and char, and also has class of each of them.

A class is a wrapper of a primitive variable, for example, the Integer class document states "The Integer class wraps a value of the primitive type int in an object. An object of type Integer contains a single field whose type is int."

But there is still difference in usage, the class type variable can be assigned with value null and stored in the container while a primitive variable cannot. But primitive type is found to have advantage in performance, here is the discussion, Why do people still use primitive types in Java?

No comments:

Post a Comment