-1

I am new to programming and I just started working with Applets on Java. I saw the command getState and understand what it's doing to the specific code but I don't know what it actually does. What is the function of getState() command on Java? What do we use it for?

elseeer
  • 1
  • 1

1 Answers1

0

Here's a quick example of the usage of getState() I found after searching:

package com.tutorialspoint;

import java.lang.*;

public class ThreadDemo implements Runnable {

    public void run() {

        // returns the state of this thread
        Thread.State state = Thread.currentThread().getState();
        System.out.println(Thread.currentThread().getName());
        System.out.println("state = " + state);
    }

    public static void main(String args[]) {
        Thread t = new Thread(new ThreadDemo());

        // this will call run() function
        t.start();   
    }
} 

Compiling and running gives us

Thread-0
state = RUNNABLE
YosiFZ
  • 7,792
  • 21
  • 114
  • 221
C. Peck
  • 3,641
  • 3
  • 19
  • 36