3.9. Arrays

Java Virtual Machine arrays are also objects. Arrays are created and manipulated using a distinct set of instructions. The newarray instruction is used to create an array of a numeric type. The code:

void createBuffer() {    int buffer[];    int bufsz = 100;    int value = 12;    buffer = new int[bufsz];    buffer[10] = value;    value = buffer[11];}

might be compiled to:

Method void createBuffer()0   bipush 100     // Push int constant 100 (bufsz)2   istore_2       // Store bufsz in local variable 23   bipush 12      // Push int constant 12 (value)5   istore_3       // Store value in local variable 36   iload_2        // Push bufsz...7   newarray int   // ...and create new int array of that length9   astore_1       // Store new array ...

Get The Java® Virtual Machine Specification, Java SE 7 Edition, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.