Two Laptop Bag*
The moose likes Beginning Java and the fly likes java -A pure OOPS? 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 "java -A pure OOPS?" Watch "java -A pure OOPS?" New topic
Author

java -A pure OOPS?

Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8898

Hi,
Is Java a pure object oriented programming language like Small talk?


Groovy
Rajesh Augastine
Greenhorn

Joined: May 07, 2002
Posts: 4
Hi Pradeep,
Java is a pure Object Oriented Language as far as I know. It does not implement some of the OOPS concepts like Multiple Inheritance and Metaclasses. But there is no doubt that JAVA is a PURE OBJECT ORIENTED LANGUAGE.
Regards,
Rajesh M A
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8898

I think Java is not a pure object oriented language becoz primitive types like int,char etc are not objects.More over Java does not suport the pure OOP'S feature "All operations performed by sending messages to objects" for e.g. a+b. I would rather call it as a Hybrid object oriented language
[ June 10, 2002: Message edited by: Pradeep Bhat ]
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Additionally, in a pure OO language like smalltalk or ruby, all control structures are imlemented as messages to objects, too.
For example, the "if" control structure is implemented through polymorphism on the Boolean class. Boolean defines the abstract methods "IfTrue: aBlock" and "IfTrue: aBlock Else: anotherBlock" has the two subclasses, True and False, which implement them accordingly. And yes, even blocks are objects in a pure OOL and can be passed as parameters.
So, Java is far from being pure OO.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Is the concept of static forbidden in an object oriented language (such as Smalltalk)?


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8898

http://scgwiki.iam.unibe.ch:8080/SmalltalkWiki/37
Originally posted by Dirk Schreckmann:
Is the concept of static forbidden in an object oriented language (such as Smalltalk)?
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
So it looks like the difference is that in Java Static methods are resolved at compile time and do not participate in polymorphism, but in a pure OO language they would be late binding and overriding happens instead of hiding.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1740
    
    2
That's partly how Smalltalk gets by without constructors. You create new instances with the "new" method, which is a class method (belongs to class, not to an instance) defined in Object (parent of all other classes, like in Java). Kinda like using a factory instead of a constructor, but all subclasses of Object inherit it.
For example, you'd create an instance of MyClass (a subclass of Object) like this:
aVariable := MyClass new.
(Then you'd typically set the desired state of the instance by a call to the instance method init.)
aVariable init.
(Note: my knowledge of Smalltalk is sketchy at best. I've only read tutorials and written a few dozen lines of code. So be gentle if I'd made some mistakes!)
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1740
    
    2
Originally posted by Ilja Preuss:
Additionally, in a pure OO language like smalltalk or ruby, all control structures are imlemented as messages to objects, too.

Is returning from a method a control structure? Isn't the return gizmo in Smalltalk (^) one of the few language constructs not implemented as an object?
Boolean defines the abstract methods "IfTrue: aBlock" and "IfTrue: aBlock Else: anotherBlock" has the two subclasses, True and False, which implement them accordingly.
I think there are four such methods:
ifTrue:
ifTrue: ifFalse:
ifFalse:
ifFalse: ifTrue:
Boolean defines the abstract methods...
Another Smalltalk coolness. There's no "abstract" keyword. You make a method abstract by making the method body
^ subclassResponsibility
Which means return the result of a call to the method "subclassResposibility" (think of "subclass" here as a verb) (defined in Object, I think), which does the Smalltalk equivalent of throwing an exception if it ever gets called. Subclasses, of course, override the "abstract" method to do something more useful.
Jawahar Rajan
Ranch Hand

Joined: Feb 28, 2002
Posts: 38
IMHO:
Though Java does have primitive types such a int, char etc. it does provide wrappers like INTEGER which will behave like an object and can be instantiated and used as an object.
So does this help java to be closer to an OO language.
Further allowing multiple inheritence can lead to a lot of sticky situtations like in C++.

Please correct me if I am wrong.
Thx
Jawahar
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1740
    
    2
Originally posted by Jawahar Rajan:

Though Java does have primitive types such a int, char etc. it does provide wrappers like INTEGER which will behave like an object and can be instantiated and used as an object.
So does this help java to be closer to an OO language.

Primitives the obvious example, but primitives are not the only nonobjects in Java, say in comparison to Smalltalk.
For example, in Smalltalk an expression such as
( a < b )
is an object (an instance of True or False, which are subclasses of Boolean).
And in Smalltalk an arbitrary block of code enclosed in square brackets ([]) is an object that can be passed as a method parameter. An arbitrary block of code in Java (enclosed in curly brackets) is, well, an arbitrary block of code.
[ June 11, 2002: Message edited by: Michael Matola ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java -A pure OOPS?
 
Similar Threads
jdbc drivers and memory leaks
Why C++ is not purely OOPS
Refactoring to Patterns - book questions
Pro Ajax and Java Frameworks book : sample language
Need pure java sound api