From the course: Java Threads
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
The main thread - Java Tutorial
From the course: Java Threads
The main thread
- [Instructor] If you think you've never worked with Java threads before, think again. Every Java programmer has done so indirectly by executing the main method of your Java class. The main method is executed by a special thread created by the Java virtual machine, or JVM, to run your Java program. This thread is known as the main thread. Here, you see a Java class with the main method in it. I'm adding this print statement in the main method. I'm using the individual shortcut, sout. Now I need to print out the name of the thread that runs the main method. To do that, I'm using the thread class. As you can see, the thread class is in the java.lang package. So we don't need to import it. The thread class encapsulates the attributes and behavior of a Java thread. The thread class has a static method named currentThread. This method call returns a reference to the currently executing thread object. That is the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.