public class DumpStackDemo { public static void main(String[] args) { Thread currentThread = Thread.currentThread(); currentThread.dumpStack(); } }In this example, we obtain a reference to the current thread object by calling the `currentThread()` method of the `Thread` class. We then call the `dumpStack()` method on it to print the stack trace to the standard error stream. The `dumpStack()` method is part of the `java.lang` package, which is included in the core Java libraries.