-1

I just want to know weather java is purely object oriented programming or not, cause we have int, float e.t.c primitive datatypes in java, some people say java is not purely object oriented program, but i know primitive data types also objects of "Class" class. Now here comes my actual question, if primitive data types are also objects of "Class" class then we can not store and retrieve them by using any collection class? when we try to store any primitive type in any collection class why auto boxing taking place? that means as collection Documentation says if we able to store only object not primitive data types in the collection classes then, data types are no more treated as object..!! ??

Andrei
  • 42,814
  • 35
  • 154
  • 218
  • See: [Is Java 100% object oriented](http://stackoverflow.com/questions/974583/is-java-100-object-oriented) –  Jan 23 '14 at 16:28
  • 1
    Primitives aren't objects of class `Class`. – Ismail Badawi Jan 23 '14 at 16:28
  • @IsmailBadawi I think they meant that you can do `int.class` to get the corresponding `Class` object. – Sotirios Delimanolis Jan 23 '14 at 16:44
  • Different people will have different ideas of what constitutes "purity", and discussing this doesn't really have much practical value. Thus I believe this is opinion-based and doesn't belong on SO. (See [here](http://www.linkedin.com/groups/Is-Java-pure-object-oriented-70526.S.5825347971360763906?trk=groups_search_item_list-0-b-ttl) for a recent discussion on another forum.) – ajb Jan 23 '14 at 16:51

3 Answers3

1

These primitive types have wrapper classes.

int - java.lang.Integer
float - java.lang.Float

This way, you can actually have List<Integer>, etc.

Marlo C
  • 587
  • 3
  • 14
  • 26
1

I define purity to be the degree of a programming language deviating from purely object-oriented programming, which consists only of objects and message passing. In other words,

  • Everything is an object.
  • All you can do is send a message.

Java is far from pure OO language compared to something like Smalltalk and Self but probably closer compared to C++, so it's a step forward. In Smalltalk for example, creation of an object is done through message passing:

| window |
 window := Window new.
 window label: 'Hello'.
 window open

In modern programming, I think the closer concept to pure OO is Erlang or Akka's actor model. I wrote blog post a while back: what is object-oriented programming?

Eugene Yokota
  • 94,654
  • 45
  • 215
  • 319
0

Recommend you to have a look at this post: What's the difference between primitive and reference types?. To answer you original question, Java is not "pure" OO in terms of having primitive types besides the reference types. However, with autoboxing, this is almost transparent for the user of the language.

Community
  • 1
  • 1
Janos
  • 1,987
  • 3
  • 17
  • 24