Found 9150 Articles for Object Oriented Programming

Java Signature getProvider() method

Samual Sam
Updated on 30-Jul-2019 22:30:25

194 Views

The provider for the signature object can be obtained using the method getProvider() in the class java.security.Signature. This method requires no parameters and it returns the provider for the signature object.A program that demonstrates this is given as follows −Example Live Demoimport java.security.*; import java.util.*; public class Demo {    public static void main(String[] argv) {       try {          Signature signature = Signature.getInstance("SHA256withRSA");          Provider provider = signature.getProvider();          System.out.println("The Provider is: " + provider);       } catch (NoSuchAlgorithmException e) { ... Read More

Java Signature getAlgorithm() method

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

219 Views

The name of the algorithm for the signature object can be obtained using the method getAlgorithm() in the class java.security.Signature. This method requires no parameters and it returns the name of the algorithm for the signature object.A program that demonstrates this is given as follows −Example Live Demoimport java.security.*; import java.util.*; public class Demo {    public static void main(String[] argv) {       try {          Signature signature = Signature.getInstance("SHA256withRSA");          String algorithm = signature.getAlgorithm();          System.out.println("The Algorithm is: " + algorithm);       } catch (NoSuchAlgorithmException e) { ... Read More

CharBuffer allocate() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

145 Views

A new CharBuffer can be allocated using the method allocate() in the class java.nio.CharBuffer. This method requires a single parameter i.e. the capacity of the buffer. It returns the new CharBuffer that is allocated. If the capacity provided is negative, then the IllegalArgumentException 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 {          CharBuffer buffer = CharBuffer.allocate(n);          buffer.put('A');          buffer.put('P');   ... Read More

CharBuffer duplicate() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

121 Views

A duplicate buffer of a buffer can be created using the method duplicate() in the class java.nio.CharBuffer. 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 {          CharBuffer buffer1 = CharBuffer.allocate(5);          buffer1.put('A');          buffer1.put('P');          buffer1.put('P');          buffer1.put('L'); ... Read More

CharBuffer compact() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

119 Views

The buffer can be compacted using the compact() method in the class java.nio.CharBuffer. This method does not require a parameter and it returns the new compacted CharBuffer 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 {          CharBuffer buffer = CharBuffer.allocate(n);          buffer.put('A');          buffer.put('B');   ... Read More

CharBuffer slice() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

145 Views

A new CharBuffer with the content as a shared subsequence of the original CharBuffer can be created using the method slice() in the class java.nio.CharBuffer. This method returns the new CharBuffer that is read-only if the original buffer is read-only and direct if the original buffer is direct.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 {          CharBuffer buffer1 = CharBuffer.allocate(n);          buffer1.put('A');       ... Read More

CharBuffer wrap() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

288 Views

A character array can be wrapped into a buffer using the method wrap() in the class java.nio.CharBuffer. This method requires a single parameter i.e. the char array to be wrapped into a buffer and it returns the new buffer created. If the returned buffer is modified, then the contents of the array are also similarly modified 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) { try { ... Read More

CharBuffer compareTo() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

129 Views

A buffer can be compared with another buffer using the method compareTo() in the class java.nio.CharBuffer. This method returns a negative integer if the buffer is less than the given buffer, zero if the buffer is equal to the given buffer and a positive integer if the buffer is greater than the given 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 {       CharBuffer buffer1 = CharBuffer.allocate(n);       buffer1.put('A');       buffer1.put('P'); ... Read More

CharBuffer get() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

138 Views

The value at the current position of the buffer is read and then incremented using the method get() in the class java.nio.CharBuffer. 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 {          CharBuffer buffer = CharBuffer.allocate(n);          buffer.put('A');          buffer.put('P');       ... Read More

CharBuffer arrayOffset() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

105 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.CharBuffer. 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 {          CharBuffer buffer = CharBuffer.allocate(5);          buffer.put('A');          buffer.put('P');          buffer.put('P');         ... Read More

Advertisements