Found 9326 Articles for Object Oriented Programming

SecureRandom getAlgorithm() method in Java

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

95 Views

The name of the algorithm for the SecureRandom object can be obtained using the method getAlgorithm() in the class java.security.SecureRandom. This method requires no parameters and it returns the name of the algorithm for the SecureRandom 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 {          SecureRandom sRandom = SecureRandom.getInstance("SHA1PRNG");          String algorithmName = sRandom.getAlgorithm();          System.out.println("The Algorithm is: " + algorithmName);       } catch (NoSuchAlgorithmException e) { ... Read More

SecureRandom generateSeed() method in Java

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

105 Views

The number of seed bytes can be obtained using the method generateSeed() in class java.security.SecureRandom. This method requires a single parameter i.e. the number of seed bytes and it returns the seed bytes that are generated.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 {          SecureRandom sRandom = SecureRandom.getInstance("SHA1PRNG");          byte[] arrB = sRandom.generateSeed(5);          System.out.println("The seed bytes generated are: " + Arrays.toString(arrB));       } catch (NoSuchAlgorithmException e) ... Read More

SecureRandom getInstance() method in Java

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

232 Views

A SecureRandom object can be obtained using the getInstance() method in class java.security.SecureRandom. This SecureRandom object is useful in implementing the Random Number Generator (RNG) algorithm that is specified.The getInstance() method requires a single parameter i.e. the Random Number Generator (RNG) algorithm and it returns the SecureRandom 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 {          SecureRandom sRandom = SecureRandom.getInstance("SHA1PRNG");          String s = "Apple";          byte[] arrB = ... Read More

Java Signature getInstance() method

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

1K+ Views

A signature object that can implement the required signature algorithm can be obtained using the method getInstance() in the class java.security.Signature. This method requires a single parameter i.e. the standard algorithm name and it returns 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 str = signature.toString();          System.out.println(str);       } catch (NoSuchAlgorithmException e) { ... Read More

Java Signature toString() method

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

270 Views

The string representation for the signature object can be obtained using the method getString() in the class java.security.Signature. This includes information such as the object state, algorithm name etc. The method getString() 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"); ... Read More

Java Signature getProvider() method

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

126 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

148 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

96 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

73 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

67 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

Advertisements