To get a current stack trace in JAVA useThread.currentThread().getStackTrace()
Example:
for (StackTraceElement ste : Thread.currentThread().getStackTrace())
{
System.out.println(ste);
}
This Returns an array of StackTraceElement, each array represents one stack frame.
To learn more about it click here.