aspose file tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes Java and OOPS Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Reply Bookmark "Java and OOPS" Watch "Java and OOPS" New topic
Author

Java and OOPS

Hari babu
Ranch Hand

Joined: Jun 25, 2001
Posts: 208
Hi all,
Is java a fully object oriented language ?
Hari
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Is it fully object-oriented?
Well, Java seems to fully support the notion of an object, but primitive data types and Java's implementation of its static context would both seem to be non-object-oriented features.
[ September 23, 2002: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Vikrama Sanjeeva
Ranch Hand

Joined: Sep 02, 2001
Posts: 756
Hi,
Yes Java is Fully Object Oriented!.This mean that non of the Java program can run without the creation of object.Therefore in every Java program object creation is neccessary.
Bye,
Viki.


Count the flowers of your garden, NOT the leafs which falls away!
Prepare IBM Exam 340 by joining http://groups.yahoo.com/group/IBM340Exam/
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
I would disagree. Smalltalk is fully object-oriented. Java is mostly object-oriented but it does have primitives which can not be treated as objects, hence the need for object wrappers.
C# is somewhere in the middle since it has primitives but they are automatically boxed and unboxed as necessary.
Zafar Ali
Ranch Hand

Joined: May 11, 2002
Posts: 64
I think Java is not fully Object Orientd Programming. Because primtive values in Java are not Objects, in OO paradigms we consider every thing as an Object.
Correction's are well come.


Zafar <br />***Your behaviour should affect.***
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Vikrama Sanjeeva:
Yes Java is Fully Object Oriented!.This mean that non of the Java program can run without the creation of object.Therefore in every Java program object creation is neccessary.

I disagree strongly. Just the creation of an object doesn't make a language fully OO (Otherwise pre-.NET VB would have been "fully 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
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
http://c2.com/cgi/wiki?IsJavaObjectOriented
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
One way to determine if a language is OO or not might be to look at how easy it is to write procedural code in that language. It's easy in Java. Hard in SmallTalk.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Another way might be to write a program by using nothing but objects and sending messages to them. It's all you can do in Smalltalk afaik - it's nearly impossible in Java for any but the simplest system.
[ September 24, 2002: Message edited by: Ilja Preuss ]
yi zhu
Ranch Hand

Joined: Sep 10, 2002
Posts: 41
I don't think primitive prevents Java from being a fully OO. OO means interface and polymorphism. An object without behavior is not an true object!
When we type the following line of code
for(int i=0; i<10; i++)
we are not using any behavior of int. So here primitive is more than enough!
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by yi zhu:
I don't think primitive prevents Java from being a fully OO. OO means interface and polymorphism. An object without behavior is not an true object!
When we type the following line of code
for(int i=0; i<10; i++)
we are not using any behavior of int. So here primitive is more than enough!

Well, both "<" and "++" are actually behaviour of an int - and are implemented as methods in Smalltalk. Hell, even loops are implemented as methods.
So, in a fully OO Java, you would write the above as something along the lines of

Notice that Smalltalk has a much more elegant (and less verbose) syntax here:

[ December 30, 2002: Message edited by: Ilja Preuss ]
yi zhu
Ranch Hand

Joined: Sep 10, 2002
Posts: 41
Well, both "<" and "++" are actually behaviour of an int - and are implemented as methods in Smalltalk. Hell, even loops are implemented as methods.
Oops..., in this world, we got to accept some basic facts, and Arithmetic of int is just one of them. I don't think your code is more readable. What's the point of the encapsulation of arithmetic of int? If you want to change implementation one day, your class will have nothing to do with int. I would call this extreme OO.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by yi zhu:
Oops..., in this world, we got to accept some basic facts, and Arithmetic of int is just one of them.

So? You could probably make the same point for most methods on java.lang.String...


I don't think your code is more readable.

And I didn't say so. But it's certainly more OO, isn't it?
As an aside, I *do* think that the Smalltalk way is much more elegant in many regards. Just compare

to

What's the point of the encapsulation of arithmetic of int? If you want to change implementation one day, your class will have nothing to do with int.

What is the point of implementing things which won't change in a non-OO way?
I would call this extreme OO.

And I would call it *full* OO. Which simply is my point: Java is not fully OO.
[ January 02, 2003: Message edited by: Ilja Preuss ]
Michael Zalewski
Ranch Hand

Joined: Apr 23, 2002
Posts: 168
Originally posted by yi zhu:
...I don't think your code is more readable. What's the point of the encapsulation of arithmetic of int? If you want to change implementation one day, your class will have nothing to do with int. I would call this extreme OO.

Well... I can think of multiple reasons to change the implementation. What if the low level implementation of int changes? 1's complement instead of 2's complement. LittleEndian instead of BigEndian. What if I want to extend the int type to, for example, include values like 'null', or 'NaN' (Not A Number). What if I want to specialize it so I have an int object which is restricted to unsigned or natural numbers? Can't do any of this in Java because you can't subclass int.
And what if you want to use reflection to get at the method to add two ints. Can't do it in Java (yet -- I think with 1.5 you could use Integer.add and boxing. Except that the Integer class is final so you can't make such a method as Integer.add).
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Another nice feature of Smalltalk is that you can add methods to existing classes for specific applications.
For example, it is accepted practice in Smalltalk to add conversion methods to number classes, so instead of writing

in Java; in Smalltalk you would enhance Number by a km method, being able to write


[ January 07, 2003: Message edited by: Ilja Preuss ]
yi zhu
Ranch Hand

Joined: Sep 10, 2002
Posts: 41
Well... You are really hard "full" OO GUYS!!!
To make you more comfortable with 1+1, just think it as a static method... and this expression does not tell you the low level implementation behind it. Don't you think it's more than your 1.add(2)?
"full".isEquivalentTo("extreme")==true.
Sorry, true is primitive too.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
yi,
sorry, I don't get your point...
yi zhu
Ranch Hand

Joined: Sep 10, 2002
Posts: 41
Ilja,
You said that both "<" and "++" are actually behaviour of an int - and are implemented as methods in Smalltalk.
But you can also consider i+j or i<j as static methods too. (equivalent to something likeINT.sum(i, j) and INT.compare(i, j). And without primitive, how can you build an object?
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6919
And without primitive, how can you build an object?
Consider a "bare metal" system where the only "primitive" operations are machine code to operate on meaningless groups of memory locations. If you are building a new language from scratch, this is where you start. In this sort of context, there is no such thing as integer, character, boolean, addition, multiplication, etc. It's up to the language design to specify how everything works.
Designers of languages which evolved from such simplebeginnings (Forth, Smalltalk, Fortran, Basic, many others which have been largely forgotten) have had to decide for themselves how to implement these common ideas.
In Forth (for example) everything is essentially either a "word" (an executable sequence of references to other "words"), an untyped block of memory in the heap, or a block of memory on a stack. Numbers are just words which push an appropriate block of memory onto a stack.
In Smalltalk, everything is an object. An object is a block of memory containing a table of memory addresses referring to other objects (member variables), the memory address of a "class" object to delegate unknown operations to, and a table of memory addresses of "code" for the methods. Similar to Forth, this "code" is actually just a sequence of object references and message names.
Some versions of Forth and Smalltalk have "optimized" their interpreters by manually pre-compiling some words or methods to low-level machine code, but in principle, both languages only need the fundamental operations (Forth: look up a word in a dictionary, push/pop a block of memory onto a stack, run through a list of words, looking up and executing each one etc.; Smalltalk: load the object at a memory location, ask an object if it understands a message, create a new instance of a class etc.) need to be coded beforehand. Everything else - integers, strings, arrays, network sockets, screen widgets and so on are written in the anguage itself.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by yi zhu:
Ilja,
You said that both "<" and "++" are actually behaviour of an int - and are implemented as methods in Smalltalk.
But you can also consider i+j or i<j as static methods too. (equivalent to something likeINT.sum(i, j) and INT.compare(i, j).

Yes, certainly. You can also consider it as set operations (as mathematicans do, iirc), and probably in a myriad of other ways. However, those ways are not object oriented.
And without primitive, how can you build an object?

I am not sure - I don't know how the Number classes are implemented. I am sure though, that in Smalltalk numerical literals *are* objects.
yi zhu
Ranch Hand

Joined: Sep 10, 2002
Posts: 41
Hi all,
I guess I understand better your position now. (Thanks to all your explanation)
But could you show me a useful OO feature that is available in Smalltalk but not in Java due to primitive? :roll:
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by yi zhu:
I guess I understand better your position now. (Thanks to all your explanation)



But could you show me a useful OO feature that is available in Smalltalk but not in Java due to primitive? :roll:

Well, I think it comes down to
a) convenience - it's rather complicated to put primitives into collections in Java, for example; and
b) elegance - for me, it's simply more satisfying to have "everything an object" instead of having to handle an unnecessary amount of different concepts.
Don't get me wrong - I really like Java. It not being fully OO is just a minor point of annoyance...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java and OOPS
 
Similar Threads
zipping as self extracting exe
class
WA #2 ..... word association
J2EE
c++ or Java--your suggestions please