28 July 2013

Why are "primitive types" (like int , boolean) not objects in java?

As part of looking for job I needed to do some revision about Java and learn few things which I always would like to learn about Java (like why string is immutable,why primitive types are not object and etc.)

What are reasons Java has primitive types instead of object ?
I expected that it must be something to do with performance or memory consumption .I found article with Creator of Java,  James Gosling where he answer on question.

"Bill Venners: Why are there primitive types in Java? Why wasn't everything just an object?
James Gosling: Totally an efficiency thing. There are all kinds of people who have built systems where ints and that are all objects. There are a variety of ways to do that, and all of them have some pretty serious problems. Some of them are just slow, because they allocate memory for everything. Some of them try to do objects where sometimes they are objects, sometimes they are not (which is what the standard LISP system did), and then things get really weird. It kind of works, but it's strange.Just making it such that there are primitive and objects, and they're just different. You solve a whole lot of problems. " Source: http://www.artima.com/intv/gosling313.html 

Source :

A Conversation with Java's Creator, James Gosling http://www.artima.com/intv/gosling313.html