Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Java and OOPS

 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Is java a fully object oriented language ?
Hari
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 765
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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" ).
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://c2.com/cgi/wiki?IsJavaObjectOriented
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yi,
sorry, I don't get your point...
 
yi zhu
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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...
 
To avoid criticism do nothing, say nothing, be nothing. -Elbert Hubbard. Please critique this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic