robturtle
8/3/2017 - 12:01 AM

Object Model

Object Model

The concrete object model

  • Objects are just one kind of data structures;
  • Objects are containers. They have slots to hold primitive types and/or other objects.
  • Things an object holds are called "properties"/"attributes".
    • Values are called "attributes"
    • Procedures are called "methods"
  • Object hierarchical property retrieval.

Primitives V.S. Objects

int:

address      value
0xabcd1234 | 0x00000001 | # 1

int[] in C V.S. [1,2,3] in Python

0xabcd1234  | 0x00000001 | # [1,2,3]
            | 0x00000002 |
            | 0x00000003 |
            | 0x00000004 | # 4
            | 0xabcd1234 |

Object data structrue:

object 1
| 0x10100001 | # type
| 0xc3ccab10 | # some other meta data
| 0xabcd1230 | # value or address to data

object 2
| 0x10100001 | # type
| 0xc3ccab10 | # some other meta data
| 0xabcd4440 | # value or address to data

Object model in Java:

reference 1
| 0x10101000 | # type
| 0x1203cccc | # meta
| 0xabcd1234 | # address to data

...
in memory pool
0xabcd1234 | 0x00000001 |

int[] in Java:

reference 1
| 0x10101000 | # type
| 0x1203cccc | # meta
| 0xabcd1234 | # address to data

...
in memory pool
0xabcd1234  | 0x00000003 | # meta
            | 0x00000002 | # length
            | 0x00000003 |
            | 0x00000004 | # 4

class Point { static int x; int y } Point p = new Point(1, 2);

reference of Point.class
| 0x10101000 | # type
| 0x1203cccc | # meta
| 0xabcd0000 | # address to data

reference of p
| 0x10101000 | # type
| 0x1203cccc | # meta
| 0xabcd1234 | # address to data

...
in memory pool
0xabcd0000  | 0x00000001 | # x
...
0xabcd1234  | 0x10101000 | # meta
            | 0x00000003 | # y

Object[] in Java

reference 1
| 0x10101000 | # type
| 0x1203cccc | # meta
| 0xabcd1234 | # address to data

...
in memory pool
0xabcd1234  | 0x00000003 | # meta
            | 0x00000002 | # length
            | 0x10101000 | # type
            | 0x1203ccc0 | # meta
            | 0xabcd1234 | # address to data
            | 0x10101000 | # type
            | 0x1203ccc0 | # meta
            | 0xabcd1234 | # address to data

List l = new ArrayList<>(); implementation: use Object[] to store data

how many primitive types are there in Java?

  • 4 integral types
    • byte
    • short
    • int
    • long
  • 2 floating point types
    • float
    • double
  • char
  • boolean

UTF-8: backward compatible to ASCII; memory compact UTF-16: easy to randomly locate

Java syntax

  • class instantiation
    • class
    • new
    • this: reference to enclosing instance itself
    • static: no implicit this argument
      • variable
      • method
      • inner class
  • class hierarchy
    • extends
      • override
      • overload
    • final
      • address of reference can not be changed once initialized
      • value of primitives can not be changed once initialized
      • class cannot be extended
    • super: reference to superclass
      • you only have to invoke a super constructor if there isn't a default constructor in the parent class
      • call super version functions
  • interfaces
    • interface
    • implements
      • public InterfaceA extends InterfaceB
    • abstract
  • access control
    • package/private/protected/public
  • module system
    • import
  • multi-thread
    • volatile