Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public class Main {
    public static void main(String[] args) {
        ByteBuffer bb = ByteBuffer.allocate(2);
        System.out.println("Default  Byte  Order: " + bb.order());
        bb.putShort((short) 300);
        bb.flip();
        showByteOrder(bb);

        bb.clear();
        bb.order(ByteOrder.LITTLE_ENDIAN);
        bb.putShort((short) 300);
        bb.flip();
        showByteOrder(bb);
    }

    public static void showByteOrder(ByteBuffer bb) {
        System.out.println("Byte  Order: " + bb.order());
        while (bb.hasRemaining()) {
            System.out.print(bb.get() + "    ");
        }
        System.out.println();
    }
}