Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OOPS Question

 
Nilesh Raje
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I need your inputs to this question.

An interviewer asked my friend this question and he was baffled. Please suggest me what would be the right answer.

Q) Is Java Purely Object Oriented?
A) He said it is and then he asked this

Q) So what you think about primitives have to do. As they are not Objects? You cant do .hashcode() on a primitive .So still you think its Java is Object Oriented Language?

What would be the best answer to this question??



 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Technically Python is more purely OO than Java, for example. In Python everything is an object, including "primitives." That's probably what the interviewer meant by purely object oriented.
 
Nilesh Raje
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you mean Java is not purely Object Oriented is it ?
 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Define purely object oriented.
 
anu kuntala
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java The primitive types (boolean, byte, char, short, int, long, float, and double), and the keyword void are also Objects of type "Class" class. Please refer Java API for more information about java.lang.Class.
So In my opinion Java is pure Object Oriented Language.
 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anu kuntala wrote:In Java The primitive types (boolean, byte, char, short, int, long, float, and double), and the keyword void are also Objects of type "Class" class. Please refer Java API for more information about java.lang.Class.
So In my opinion Java is pure Object Oriented Language.

Why can't you use generics with primitives then? And what methods can you call on an int variable?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15288
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These questions are not directly related to the SCJP exam. I will move this topic to a more appropriate forum.

Whether Java is "purely object oriented" depends on what your exact definition of "purely object oriented" is. There is no fixed definition which is agreed upon by everybody, so there's no exact answer to that question. This question has been asked and discussed before on JavaRanch, so if you do a search in the forums you'll find the previous discussions about this question.

The fact that in Java not everything is an object (Java has primitive types) is one of the arguments that people use to show that Java is not a purely object oriented language.
 
Nilesh Raje
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well thats a interesting contribution everyone is making here.

I did check the API docs for java.lang.class and found this
"The primitive Java types (boolean, byte, char, short, int, long, float, and double), and the keyword void are also represented as Class objects."

I believe this makes sense and should be a good answer to the interviewer. Atleast that can satisfy his answer by 85% .

 
Henry Wong
author
Marshal
Pie
Posts: 21126
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java The primitive types (boolean, byte, char, short, int, long, float, and double), and the keyword void are also Objects of type "Class" class. Please refer Java API for more information about java.lang.Class.
So In my opinion Java is pure Object Oriented Language.


This is just saying that there are Class objects which are used to represent the primative types. This doesn't mean that the primative types are objects.

Of course, this makes sense. If there isn't Class objects that can represent the primative types, then the reflection libraries would be broken, as it can only access constructors and methods that take as parameters and return objects.



As for whether Java is a pure OOP language -- I've decided not to engage in that argument.

Henry
 
fred rosenberger
lowercase baba
Bartender
Posts: 12127
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ruben Soto wrote:In Python everything is an object, including "primitives."

I am not a Python expert, but I believe Python has operators (+, **, and ==, for example) which are NOT objects, so it is by some definitions NOT 'purely OO'. Some folks believe that to be 'purely OO', operators shouldn't exist - everything should be done via method calls on objects.
 
Pankaj Rathod
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question is actually asked in an interwiew. The interviewers does not seek 100% definate/correct answer to such questions.

From that point of view, I think, one can answer the question of Java being an purely OO in affirmative and argue that in java there are Wrapper classes (Objects) for every primitive type and one can use Interger Object in place of int primitive wherever needed.

In any case, whether you say yes or no, the interviewer will challenge your position on such issues. So just pick up one line of theory which you are comfortable in and defend your position in all possible ways.

Thats the way in an interview (not life ).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic