Java for android • Java for android ตางกบ java ทวๆไปตรงท – Virtual machine • บน windows , mac. OS, Unix, linux จะใช java virtual machine (J 2 SE) ลกษณะ Stack based virtual machine ในการทำงาน • บน Andriod จะใช Dalvik หรอ ART(สามาเลอกไดใน Kitkat แตเปนมาตรฐานใน lolipop ขนไป ) ในการเปน virtual machine ลกษณะ Register based virtual machine ในการทำงาน
Virtual machine • Virtual machine นอกจากจะเปน System virtual machine ททำการ run บน Native operating system เชน windows, linux, mac. OS และอนๆ อยางเชน Virtual box, Vmware, QEMU, Windows virutal PC เปนตน • ยงม VM อกประเภททเปน process ทำ หนาทชวยให
Non-system virtual machine • Non-system virtual machine เปน process ทจะมการทำหนาทดงตอไปน 1. Compilation of source language into VM specific bytecode 2. Data structures to contains instructions and operands (the data the instructions process) 3. A call stack for function call operations 4. An ‘Instruction Pointer’ (IP) pointing to the next instruction to execute 5. A virtual ‘CPU’ – the instruction dispatcher that • Fetches the next instruction (addressed by the instruction pointer) • Decodes the operands
J 2 SE vs Dalvik • J 2 SE จะสราง java byte code อยใน DEX file แลวสงไปให JAVA virtual machine ทำงานเลย • ตางกบ Dalvik ทจะทำการ Complie DEX file