aspose file tools*
The moose likes Beginning Java and the fly likes OOPS Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "OOPS Question" Watch "OOPS Question" New topic
Author

OOPS Question

Nilesh Raje
Ranch Hand

Joined: Aug 02, 2005
Posts: 153
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

Joined: Dec 16, 2008
Posts: 1032
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.


All code in my posts, unless a source is explicitly mentioned, is my own.
Nilesh Raje
Ranch Hand

Joined: Aug 02, 2005
Posts: 153
So you mean Java is not purely Object Oriented is it ?
Ruben Soto
Ranch Hand

Joined: Dec 16, 2008
Posts: 1032
Define purely object oriented.
anu kuntala
Greenhorn

Joined: Sep 25, 2008
Posts: 17
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

Joined: Dec 16, 2008
Posts: 1032
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

Joined: Aug 16, 2005
Posts: 13884
    
  10

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Nilesh Raje
Ranch Hand

Joined: Aug 02, 2005
Posts: 153
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
Sheriff

Joined: Sep 28, 2004
Posts: 18141
    
  39

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10929
    
  12

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Pankaj Rathod
Greenhorn

Joined: Feb 02, 2009
Posts: 7
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 ).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: OOPS Question
 
Similar Threads
OO Basics
I once heard the great Paul Wheaton say...
object oriented
A puzzle asked for HR interview
Is Java derived from C++