This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
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
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 ]
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
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
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!)
Joined: Mar 25, 2001
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.
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
Joined: Mar 25, 2001
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 ]