Class Running Notes 23rd Nov
Class Running Notes 23rd Nov
1.Thread Creation:
2.Ready-to-run:
i
thi
=>The state of thread which is ready to execute by Thread-scheduler is known
as Ready-to-run.
ipa
3.Running:
Ma
=>The state in which the thread under execution is known a "Running State"
Note:
=>Thread Scheduler will shedule the threads from Ready-to-run state to running
sh
state based on algorithms.
ate
(a)Thread-Completion:
=>The state in which the thread executed successfully and generated result
nk
(b)Thread-Blocked-state:
Note:
=>when we use wait() or sleep() methods then the thread in under blocked state.
=>wait() method will block the thread execution until it receives msg in the
Thread-Dead-Lock :
i
thi
=>The permanent blockage of thread is known as Thread-Dead-lock.
ipa
Note:
=>If any event raised under blocked state is permanent then the thread is under
deadlock.
Ma
==========================================================================
faq:
sh
define LiveLock?
faq:
=========================================================================
Application of Threads:
(i)Threads are used in Server Application development
=====================================================================
*imp
i
thi
=>"java.lang.Object" class is the ParentClass or SuperClass of all the classes
ipa
=>The following are some important methods of "Object" class:
1.hashCode()
Ma
2.toString()
3.clone()
4.equals()
sh
5.wait()
6.notify()
ate
7.notifyAll()
8.getClass()
nk
9.finalize()
Ve
1.hashCode():
=>The unique numeric number which is generated while object creation process is
known as hashCode.
syntax:
int hc = obj.hashCode();
2.toString():
syntax:
i
thi
String data = obj.toString();
ipa
when we display object_reference
*imp
3.clone():
Ma
=>The process of creating the duplicate copy of an object is known as cloning
sh
process.
syntax:
Object o = obj.clone();
nk
=>In Deep Cloning process both OuterObjects and reffered Objects are cloned.
---------------------------------------------------------------------
i
thi
=>The following steps are used in Cloning process:
ipa
step-1 : The user-defined class must be implemented from "java.lang.Cloneable"
interface
Ma
step-2 : The user-defined class must be declared with one user-defined Object
step-3 : This user-defined Object return type method will call pre-defined clone()
sh
method to perform cloning process
step-4 : we call user-defined object return type method to start the cloning
ate
process
=======================================================================
nk
EmpContact.java
package test;
public class EmpContact extends Object{
public String mailId;
public long phoneNo;
@Override
public String toString() {
return "MailId:"+mailId+"\nPhoneNo:"+phoneNo;
}
}
Employee.java
package test;
public class Employee extends Object implements Cloneable{
public String empId,name,desg;
public EmpContact ec = new EmpContact();
@Override
public String toString() {
return "EmpId:"+empId+"\nEmpName:"+name+"\nEmpDesg:"+desg;
i
thi
}
public Object startCloning() {
Object o = null;
try {
ipa
o = super.clone();
}catch(Exception e) {e.printStackTrace();}
return o;
} Ma
}
DemoObject1.java(MainClass)
package maccess;
sh
import test.*;
ate
import java.util.*;
//Original Object
ob1.empId = s.nextLine();
ob1.desg=s.nextLine();
ob1.ec.mailId=s.nextLine();
i
thi
ob1.ec.phoneNo = s.nextLong();
System.out.println("********Original Object**********");
ipa
System.out.println("=====Display data from Objects====");
System.out.println(ob1);
Ma
System.out.println(ob1.ec);
System.out.println("====hashCodes===");
System.out.println("********Cloned Object**********");
nk
System.out.println(ob2);
Ve
System.out.println(ob2.ec);
System.out.println("====hashCodes===");
s.close();
}
o/p:
A121
i
thi
Raj
ipa
SE
9898981234
sh
********Original Object**********
EmpId:A121
EmpName:Raj
nk
EmpDesg:SE
MailId:[email protected]
Ve
PhoneNo:9898981234
====hashCodes===
********Cloned Object**********
=====Display data from Objects====
EmpId:A121
EmpName:Raj
EmpDesg:SE
MailId:[email protected]
PhoneNo:9898981234
i
thi
====hashCodes===
ipa
hashCode of EmpContact Object : 999966131
==========================================================
Ma
sh
ate
nk
Ve