- 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
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);
- Related Articles
- Is array a primitive data type in Java?
- How to Get a slice of a primitive array in Java?
- Convert double primitive type to a Double object in Java
- Is String a primitive data type or an object in Java?
- Passing primitive values while instantiating a parameterized type (generic) in Java?
- Is an array a primitive type or an object in Java?
- Convert short primitive type to Short object in Java
- Convert byte primitive type to Byte object in Java
- Get the declared method by name and parameter type in Java
- Java Program to convert a Primitive Type Value to a String
- Prove that the interface for a primitive type is an empty array in Java
- What are the default values of instance variables whether primitive or reference type in Java?
- Get the Name of a Member Object in Java
- Get the unqualified name of a class in Java
- Java Program to convert a string into a numeric primitive type using Integer.valueOf()

Advertisements