21

I'd like to know if Java is pure object oriented or not. Please explain it with example. I have goggled it, but I couldn't find the exact answer.

12
  • 14
    You'd have to define the term "pure object oriented" in order to make the question answerable. Commented Oct 11, 2012 at 9:36
  • 3
    I would really like to see an example of pure object oriented programming language. Commented Oct 11, 2012 at 9:39
  • 2
    See stackoverflow.com/questions/974583/… ... summary: can't be answered without a good definition of what "pure object oriented" even means. Commented Oct 11, 2012 at 9:42
  • 1
    Whether it is or isn't, when is this ever relevant? Commented Oct 11, 2012 at 9:42
  • 3
    @Thor84no For instance in an exam. :P Commented Oct 11, 2012 at 9:43

4 Answers 4

20

There are lot of arguments around whether Java is purely object oriented or not. Java should be considered as purely object oriented language as it has wrapper classes. So you can use Integer, Float etc. instead of int, float etc. (there are a total of eight primitive types).

But since Java has those eight primitive types, the critics will say Java is not purely object-oriented.

Sign up to request clarification or add additional context in comments.

8 Comments

-1. Can somebuddy correct me please??
What is "pure" object oriented? Can you explain? And even if it has wrappers, it still has types that are not objects which you can use with no problems.
yes i can correct you. yes java has wrappers. but it has primitives as well. dont say.. that now java has wrappers.. so we can express integer,float etc as objects so java is now pure oo. thing is , yes wrappers are there.. but we can stil have int, float as primitives. so java is not purely object oriented. refer to update to my answer below. java isnt pure oo #fact.. if u feel otherwise , thats another story.
@Mukul Goel - You are seeing in from one side(primitive type) only. Will you not consider a java program pure-OO which uses Wrapper objects(Integer, Float etc) instead of int and float???
Well, you're wrong.
|
15

For example it contains 8 primitive data types. For a language to be "pure oo" everything should exists as objects, but int, float, char, .. etc are not objects in Java.

Here's an example:

int i = 42;
System.err.println(i.toString());

6 Comments

@MIkul Goel but java have wrapper classes for these data types primitives which convert thise into objects .....
Yes but also supports primitives while pure OO language doesn't
Yes, some would say we have wrappers. BUT we can use the primitive datatypes without the wrappers(i.e. not as objects).. OO says..everything should be treated as objects.. SO .. NO pure OO.. :-)
And what is the difference between a primitive type and a type without the function member toString or any other function member? For example, in C++, a object is "a region of storage". So, under this definition, an interger is an object. What is the (unambiguous) definition of object?
@MukulGoel Good point, but I think if a primitive type is an instance of a class or not, is transparent for you. So, I don't see any difference from a programmer's point of view. I come from the C++ world, and an instance of a class with implicitly default constructor, implicitly copy and move constructors/assignment operators (a POD class), and POD subobjects, has no differences with primitive types from a point of view of performance, except for the fact this class is a compoud type (it requieres more storage and time to reserve that storage).
|
9

Java is a OOP language and it is not a pure Object Based Programming Language. Many languages are Object Oriented. There are seven qualities to be satisfied for a programming language to be pure Object Oriented. They are:

  • Encapsulation/Data Hiding
  • Inheritance
  • Polymorphism
  • Abstraction
  • All predefined types are objects
  • All operations are performed by sending messages to objects
  • All user defined types are objects.

Java is not because it supports Primitive datatype such as int, byte, long... etc, to be used, which are not objects. Contrast with a pure OOP language like Smalltalk, where there are no primitive types, and boolean, int and methods are all objects.

This answer is taken from http://wiki.answers.com/Q/Why_is_Java_not_a_pure_OOP_Language

2 Comments

That's not a trustable reference and does not cite its references either. Those 7 qualities, who says so?
actually its not at all true ans.
6

no it has primitive data types, thus i would say its not completely object oriented. i think Smalltalk can be considered pure object oriented than java.

Straight from wiki Smalltalk is a "pure" object-oriented programming language, meaning that, unlike Java and C++, there is no difference between values which are objects and values which are primitive types. In Smalltalk, primitive values such as integers, booleans and characters are also objects

7 Comments

Sorry, but more/less/pure object oriented makes no sense.
yes, it does not. i meant small talk is pure object oriented than java\
Still makes no sense. How do you measure object-orientedness?
@m0skit0 did you check my quoted text from wiki ?? .. i am no OOP guru, nor i know smalltalk. :P
That's why in Wikipedia they put "pure" (between quotes)... because you can't measure such thing, and as such, you cannot say if a language is more/less pure object oriented than another one. And anyway, what does "pure object oriented" mean?
|