Object Oriented Programming Articles

Page 510 of 588

DoubleBuffer arrayOffset() method in Java

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 115 Views

The offset of the first element of the buffer inside the buffer array is obtained using the method arrayOffset() in the class java.nio.DoubleBuffer. If the buffer backed by the array is read-only, then the ReadOnlyBufferException is thrown.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          DoubleBuffer buffer = DoubleBuffer.allocate(5);          buffer.put(4.5D);          buffer.put(1.2D);          buffer.put(3.9D);         ...

Read More

Fix for java.math.BigInteger cannot be cast to java.lang.Integer?

Samual Sam
Samual Sam
Updated on 30-Jul-2019 6K+ Views

You can typecast with the help of method intValue(). The syntax is as follows −Integer yourVariableName=((BigInteger) yourBigIntegerValue).intValue();Here is the Java code to convert java.math.BigInteger cast to java.lang.Integer. The code is as follows −Example Live Demoimport java.math.BigInteger; public class BigIntegerToInteger {    public static void main(String []args) {       BigInteger bigValue [] = new BigInteger[5];       bigValue[0] = new BigInteger("6464764");       bigValue[1] = new BigInteger("212112221122");       bigValue[2] = new BigInteger("76475");       bigValue[3] = new BigInteger("94874747");       bigValue[4] = new BigInteger("2635474");       for(int i = 0; i< bigValue.length; i++) ...

Read More

ShortBuffer order() Method in Java

Samual Sam
Samual Sam
Updated on 30-Jul-2019 130 Views

The byte order of the buffer can be obtained using the method order() in the class java.nio.ShortBuffer. This method requires no parameters and it returns the byte order of the buffer.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          ShortBuffer buffer = ShortBuffer.allocate(n);          buffer.put((short)12);          buffer.put((short)91);          buffer.put((short)25);          buffer.put((short)18);          buffer.put((short)30); ...

Read More

ByteBuffer asShortBuffer() method in Java

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 222 Views

A view of the ByteBuffer can be created as a ShortBuffer using the asShortBuffer() method in the class java.nio.ByteBuffer. This method requires no parameters and it returns a short buffer as required. This buffer reflects the changes made to the original buffer and vice versa.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 50;       try {          ByteBuffer bufferB = ByteBuffer.allocate(n);          ShortBuffer bufferS = bufferB.asShortBuffer();       ...

Read More

ByteBuffer compact() method in Java

Samual Sam
Samual Sam
Updated on 30-Jul-2019 316 Views

The buffer can be compacted using the compact() method in the class java.nio.ByteBuffer. This method does not require a parameter and it returns the new compacted ByteBuffer with the same content as the original buffer. If the buffer is read-only, then the ReadOnlyBufferException is thrown.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo { public static void main(String[] args) { int n = 5; try { ByteBuffer buffer ...

Read More

ByteBuffer duplicate() method in Java

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 470 Views

A duplicate buffer of a buffer can be created using the method duplicate() in the class java.nio.ByteBuffer. This duplicate buffer is identical to the original buffer. The method duplicate() returns the duplicate buffer that was created.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          ByteBuffer buffer1 = ByteBuffer.allocate(5);          buffer1.put((byte)1);          buffer1.put((byte)2);          buffer1.put((byte)3);          buffer1.put((byte)4); ...

Read More

ByteBuffer get() method in Java

Samual Sam
Samual Sam
Updated on 30-Jul-2019 532 Views

The value at the current position of the buffer is read and then incremented using the method get() in the class java.nio.ByteBuffer. This method returns the value that is at the current buffer position. Also, the BufferUnderflowException is thrown if underflow situation occurs.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo { public static void main(String[] args) { int n = 5; try { ByteBuffer buffer = ByteBuffer.allocate(n); ...

Read More

ByteBuffer asLongBuffer() method in Java

Samual Sam
Samual Sam
Updated on 30-Jul-2019 135 Views

A view of the ByteBuffer can be created as a LongBuffer using the asLongBuffer() method in the class java.nio.ByteBuffer. This method requires no parameters and it returns a long buffer as required. This buffer reflects the changes made to the original buffer and vice versa.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 50;       try {          ByteBuffer bufferB = ByteBuffer.allocate(n);          LongBuffer bufferL = bufferB.asLongBuffer();       ...

Read More

ByteBuffer asReadOnlyBuffer() method in Java

Samual Sam
Samual Sam
Updated on 30-Jul-2019 558 Views

A read-only byte buffer can be created using the contents of a buffer with the method asReadOnlyBuffer() in the class java.nio.ByteBuffer. The new buffer cannot have any modifications as it is a read-only buffer. However, the capacity, positions, limits etc. of the new buffer are the same as the previous buffer.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {     int n = 5;     try {       ByteBuffer buffer = ByteBuffer.allocate(5);   ...

Read More

ByteBuffer asDoubleBuffer() method in Java

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 169 Views

A view of the ByteBuffer can be created as a DoubleBuffer using the asDoubleBuffer() method in the class java.nio.ByteBuffer. This method requires no parameters and it returns a double buffer as required. This buffer reflects the changes made to the original buffer and vice versa.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 50;       try {          ByteBuffer bufferB = ByteBuffer.allocate(n);          DoubleBuffer bufferD = bufferB.asDoubleBuffer();       ...

Read More
Showing 5091–5100 of 5,878 articles
« Prev 1 508 509 510 511 512 588 Next »
Advertisements