java.nio.ByteOrder Class in Java Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 1 Likes Like Report ByteOrder is a class from java.nio package. In general Byte Order mean the enumeration of ByteOrder. In java there are primitive data types like int, char, float, double are there which will store there data in the main memory in some number of bytes.For example, a character or a short integer occupies 2 bytes, a 32-bit integer or a floating-point value occupies 4 bytes, and a long integer or a double-precision floating-point value occupies 8 bytes.And each value of one of these multi-byte types is stored in a sequence of contiguous memory locations.Here, consider a long integer which occupies 8 bytes, and these eight bytes could be stored in memory (from low address to high address) as 13,17,21,25,29,34,38,42; this arrangement is known as big-endian order (the most-significant byte, the “big” end, is stored at the lowest address).Alternatively, these bytes could be stored as 42,38,34,29,25,21,17,13; this arrangement is known as little-endian order (the least-significant byte, the “little” end, is stored at the lowest address to the highest address). Note: ByteOrder Class extends Object Class which is the root of the class hierarchy. There are two fields of ByteOrder class FieldDescriptionBIG_ENDIANThis is a field that will be denoting big-endian byte order.LITTLE_ENDIANThis is a field that will be Constant denoting little-endian byte order. Syntax: Class declaration public final class ByteOrder extends Object {} Methods of this class are as follows: MethodsDescriptionnativeOrder() This method is defined to increase the performance of JVM by allocating direct buffer in the same order to the JVM. This method returns the native byte order of the hardware upon which this Java virtual machine is running. toString()This method returns the string which is defined in a specified way. Implementation: Example Java // Java Program to demonstrate ByteOrder Class // Importing input output and utility classes import java.io.*; // Importing required classes from java.nio package // for network linking import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.IntBuffer; // Main class public class GFG { // Main driver method public static void main(String[] args) throws Exception { // Here object is created and allocated and // it with 8 bytes of memory ByteBuffer buf = ByteBuffer.allocate(8); // This line of code prints the os order System.out.println("OS Order :- " + ByteOrder.nativeOrder()); // This line of code prints the ByteBuffer order // Saying that whether it is in BIG_ENDIAN or // LITTLE_ENDIAN System.out.println("ByteBuffer Order :- " + buf.order()); // Here the conversion of int to byte takes place buf.put(new byte[] { 13, 17, 21, 25 }); // Setting the bit set to its complement using // flip() method of Java BitSet class buf.flip(); IntBuffer integerbuffer = buf.asIntBuffer(); System.out.println("{" + integerbuffer.position() + " : " + integerbuffer.get() + "}"); integerbuffer.flip(); buf.order(ByteOrder.LITTLE_ENDIAN); integerbuffer = buf.asIntBuffer(); System.out.println("{" + integerbuffer.position() + " : " + integerbuffer.get() + "}"); } } OutputOS Order :- LITTLE_ENDIAN ByteBuffer Order :- BIG_ENDIAN {0 : 219223321} {0 : 420811021} Note: The order of a newly-created byte buffer is always BIG_ENDIAN.One can have different OS Order for different machines. Create Quiz Comment P pranaythanneru Follow 1 Improve P pranaythanneru Follow 1 Improve Article Tags : Java Java-NIO package Java-Classes Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References7 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers1 min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like