
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
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());
Advertisements