VOOZH about

URL: https://www.geeksforgeeks.org/java/method-class-getname-method-in-java/

⇱ Method Class | getName() Method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Method Class | getName() Method in Java

Last Updated : 9 Apr, 2026

The getName() method of the Thread class is used to retrieve the name of a thread. It helps in identifying threads during execution, especially useful for debugging and logging in multithreaded applications.

  • Returns the name of the current thread
  • Commonly used for debugging and logging
  • Default thread names are like Thread-0, Thread-1, etc.

Output
Thread name: Thread-0

Explanation: The getName() method fetches and prints the name of the thread. If no custom name is set, it displays the default thread name.

Syntax

public final String getName()

Example: Program to check whether class contains a certain specific method.


Output
Class Object Contains Method whose name is method1

Explanation: Above program uses Java Reflection (Class and Method) to retrieve all methods of a class at runtime. It then checks whether a method with the name "method1" exists and prints a message if found.

Comment