Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java -A pure OOPS?

 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Is Java a pure object oriented programming language like Small talk?
 
Rajesh Augastine
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the concept of static forbidden in an object oriented language (such as Smalltalk)?
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Michael Matola
whippersnapper
Ranch Hand
Posts: 1821
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1821
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1821
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic