
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get the Name of a Primitive Type in Java
The getName() method is used to get the names of the entities such as primitive type, interface, class, array class, void etc. that represented by the class objects. These names are returned in the form of a string.
A program that gets the name of a primitive type using getName() method is given as follows -
Example
public class Demo { public static void main(String[] argv) throws Exception { String name1 = float.class.getName(); System.out.println(name1); String name2 = int.class.getName(); System.out.println(name2); String name3 = char.class.getName(); System.out.println(name3); } }
Output
float int char
Now let us understand the above program.
The getName() method is used to get the names of the primitive data types float, int and char. Then these names are stored in name1, name2 and name3 respectivel and displayed. A code snippet which demonstrates this is as follows −
String name1 = float.class.getName(); System.out.println(name1); String name2 = int.class.getName(); System.out.println(name2); String name3 = char.class.getName(); System.out.println(name3);
Advertisements