What are the key differences between OO in Smalltalk and Java?

前端 未结 7 1750
臣服心动
臣服心动 2021-01-30 13:31

What are the key differences between OO in Smalltalk and Java?

Please note that I am a Java programmer trying to expand his horizons by exploring Smalltalk. Currently I

7条回答
  •  时光取名叫无心
    2021-01-30 14:00

    1. Object Model. In Smalltalk every thing, is an object. Java has primitive types like int and float whose representation and behavior are different from complex objects.
    2. Behavior invocation. Behavior of a Smalltalk object is invoked by sending it a message. Java has methods, which are basically function calls, with the destination object being a special first argument called this.
    3. Encapsulation. Smalltalk has strict encapsulation. An object's fields can be exposed only through messages. In contrast, Java allows public fields.
    4. Dynamism. Smalltalk is extremely dynamic. All types are identified at runtime. A class can be introspected and modified at runtime (dynamic meta-programming!). New classes can be created and instantiated at runtime. Java has static type checking along with runtime polymorphism. There is introspection and reflection, but classes and objects cannot be modified from within a running program.
    5. Syntax. Smalltalk do not have a syntax. Instead it has a simple, consistent format for sending messages. Java, like other languages of the C family, has a complex syntax.
    6. Environment. Most Smalltalk implementations provide a complete, standalone, live computing environment with image based persistence. Some of these environments can even be booted on bare metal. The JVM in turn is usually dependent on an underlying operating system for threading, networking etc. Source code must be entered into text files, compiled and explicitly loaded into the JVM for execution.

提交回复
热议问题