- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Provider toString() method in Java
The name and the version number of the provider in string form can be obtained using the method toString() in the class java.security.Provider. This method requires no parameters and it returns the name as well as the version number of the provider in string form.
A program that demonstrates this is given as follows −
Example
import java.security.*; import java.util.*; public class Demo { public static void main(String[] argv) { try { KeyPairGenerator kpGenerator = KeyPairGenerator.getInstance("DSA"); Provider p = kpGenerator.getProvider(); System.out.println("The name and version number of the provider is: " + p.toString()); } catch (NoSuchAlgorithmException e) { System.out.println("Error!!! NoSuchAlgorithmException"); } } }
Output
The name and version number of the provider is: SUN version 1.8
Now let us understand the above program.
The toString() method is used to obtain the name and the version number of the provider in string form. Then this is displayed. If the algorithm name is wrong, then the exception NoSuchAlgorithmException is thrown. A code snippet that demonstrates is given as follows −
try { KeyPairGenerator kpGenerator = KeyPairGenerator.getInstance("DSA"); Provider p = kpGenerator.getProvider(); System.out.println("The name and version number of the provider is: " + p.toString()); } catch (NoSuchAlgorithmException e) { System.out.println("Error!!! NoSuchAlgorithmException"); }
- Related Articles
- Java toString() method.
- ShortBuffer toString() method in Java
- Duration toString() method in Java
- MonthDay toString() Method in Java
- Instant toString() method in Java
- LocalDate toString() method in Java
- LocalDateTime toString() method in Java
- LocalTime toString() method in Java
- Provider elements() method in Java
- Provider entrySet() method in Java
- Provider get() method in Java
- Provider getInfo() method in Java
- Provider getName() method in Java
- Provider getVersion() method in Java
- Provider getProperty() method in Java

Advertisements