4

I am new to Android but experienced in Java. In Java when we do this:

MyClass myObj = new MyClass();

It clearly does the following:

  1. Inserts the memory pointer myObj upto the stack
  2. Allocates a new space for object of type MyClass in the heap
  3. Appoints this new space's reference to myObj

But I am a little bit confused about the following questions:

  1. But in Android, does this work in the same way?
  2. Does Android have full stack and heap memories?
  3. Does Android have Java Virtual Machine (JVM) for my Java app (Android app) to work on?

Thanks a lot!

GingerHead
  • 8,130
  • 15
  • 59
  • 93
  • 1
    wonder what all this Oracle vs Google fuss is about? – Scary Wombat May 23 '14 at 00:59
  • 2
    (First Question Review) The question is well written. Personally I wondered a bit why you think Android/Dalvik would be any different. If you add that, then you might get more targeted answers. – eckes May 23 '14 at 01:16
  • 2
    See also http://stackoverflow.com/questions/4588076/is-dalviks-memory-model-the-same-as-javas – eckes May 23 '14 at 01:17

1 Answers1

3

Android re-implemented the Java Virtual Machine with their own Dalvik Virtual Machine. Unlike the JVM which is stack-based, Dalvik is register based. You can see a comparison between the two here:

http://en.wikipedia.org/wiki/Dalvik_(software)#Performance

Yes Dalvik VM has a heap just like the JVM - just not a stack. It is 100% compatible with any Java 1.6 source code (1.7 support is slowly coming, and preliminary support is available in Android Studio). So in your 3 steps:

  1. Inserts the reference to myObj in a register
  2. Allocates a new space for object of type MyClass in the heap
  3. Appoints this new space's reference to myObj
Martin Konecny
  • 57,827
  • 19
  • 139
  • 159
  • 2
    Here's another reference if you're still looking for more: http://stackoverflow.com/questions/3446540/what-is-the-difference-between-dvm-and-jvm – Martin Konecny May 23 '14 at 02:35