Unit-4 Java
Unit-4 Java
2) Running
A thread is in a Running state when it is under execution.
3) Suspended
A thread is in the Suspended state when it is temporarily
inactive or under execution.
►
4) Blocked
A thread is in the Blocked state when it is waiting for
resources.
5) Terminated
A thread comes in this state when at any given time, it
halts its execution immediately
Creating Thread
Priority of a Thread
► Each thread has a priority. Priorities are
represented by a number between 1 and
10.
1.import package.*;
2.import
package.classname; 3.fully
qualified name.
1) Using packagename.*
//save by A.java
package pack;
public class A{
public void msg(){System.out.println("Hello
");}
}
package mypack;
import pack.*;
class B{
public static void main(String
args[]){ A obj = new A();
obj.msg();
}
}
2) Using packagename.classname
►If
you import package.classname then only
declared class of this package will be
accessible.
Example
//save by A.java
package pack;
public class A{
public void msg(){System.out.println("Hello
");}
}
package mypack;
import pack.A;
class B{
public static void main(String
args[]){ A obj = new A();
obj.msg();
}
}
3) Using fully qualified name
//save by A.java
package pack;
public class A{
public void msg(){System.out.println("Hello
");}
}
package mypack;
class B{
public static void main(String
args[]){ pack.A obj = new A();
obj.msg();
}
}
Subpackage in java
► Package inside the package is called the
subpackage.
► javac
mypack\testpack\MySubPackageProgram.java ► java
mypack.testpack.MySubPackageProgram