- 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
Display the current method name in Java
The current method name that contains the execution point that is represented by the current stack trace element is provided by the java.lang.StackTraceElement.getMethodName() method.
A program that demonstrates this is given as follows −
Example
public class Demo { public static void main(String args[]) { System.out.println ("The method name is: " + new Exception().getStackTrace()[0].getMethodName()); } }
Output
The method name is: main
Now let us understand the above program.
The method getMethodName() is used to obtain the current method name that contains the execution point that is represented by the current stack trace element. This is printed using System.out.println(). A code snippet which demonstrates this is as follows −
System.out.println ("The method name is: " + new Exception().getStackTrace()[0].getMethodName());
- Related Articles
- Display localized month name with printf method in Java
- Display the length of current file in Java
- How to display the name of the Current Thread in C#?
- Display the Operating System name in Java
- C# Program to display name of Current Thread
- Fetching the name of the current thread in Java
- Display the package name of a class in Java
- Java Program to Display current Date and Time
- Display the current mask in Numpy
- Java Program to display Current Time in another Time Zone
- Display month by name and number in Java
- How to display all stack frames of the current thread in Java 9?
- Display Timestamp before the current date in MySQL
- Display Day Name of Week using Java Calendar
- Subtract seconds from current time using Calendar.add() method in Java

Advertisements