Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//Contents in a non-direct ByteBuffer are stored in the normal memory. 
//Contents in a direct ByteBuffer are stored in some I/O device.

import java.nio.ByteBuffer;

public class Main {
    public static void main(String[] argv) throws Exception {

        ByteBuffer bbuf = ByteBuffer.wrap(new byte[10]);
        boolean isDirect = bbuf.isDirect(); // false

        bbuf = ByteBuffer.allocate(10);
        isDirect = bbuf.isDirect(); // false

        bbuf = ByteBuffer.allocateDirect(10);
        isDirect = bbuf.isDirect(); // true

    }
}