0% found this document useful (0 votes)
9 views

Class Running Notes 23rd Nov

Uploaded by

Sai Susmitha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Class Running Notes 23rd Nov

Uploaded by

Sai Susmitha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Dt : 23/11/2022

1.Thread Creation:

=>The process of creating thread using start() method is known as Thread

creation process or New 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

is known as Thread-Completion state.


Ve

(b)Thread-Blocked-state:

=>The state in which the thread is temporarly blocked from execution is

known as 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

form of notify() or notifyAll()

=>sleep() method will block the thread execution in sime timer

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?

=>The temporary blockage of thread is known as LiveLock.


ate

(Blocked state of thread is known as LiveLock)


nk

faq:

define Daemon Thread?


Ve

=>The thread which executes contineously is known as Daemon Thread

(Server Service threads are daemon threads)

=========================================================================

Application of Threads:
(i)Threads are used in Server Application development

(ii)Threads are used in Server Development

(iii)Threads are used in Gaming Applications

=====================================================================

*imp

define "java.lang.Object" class?

i
thi
=>"java.lang.Object" class is the ParentClass or SuperClass of all the classes

declared in the application.

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.

=>we use hashCode() method to display the hashCode of an object.

syntax:
int hc = obj.hashCode();

=>we display the hashCode to check the object is created or not.

2.toString():

=>toString() method is used to display the content from the object.

syntax:

i
thi
String data = obj.toString();

=>toString() method is auto-executable method and which is executed automatically

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.

=>we use clone() method to perform Object-Cloning process.


ate

syntax:

Object o = obj.clone();
nk

Types of Cloning processes:


Ve

=>Cloning process is categorized into two types:

(a)Shallow Cloning process

(b)Deep Clonning process

(a)Shallow Cloning process:


=>In Shallow Cloning process only OuterObjects are cloned and referred objects

are not cloned.

(b)Deep Clonning process:

=>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

return type method

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

Ex-program : Demonstrating "Shallow Cloning Process".


Ve

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.*;

public class DemoObject1 {


nk

public static void main(String[] args) {

Scanner s = new Scanner(System.in);


Ve

//Original Object

Employee ob1 = new Employee();

System.out.println("Enter the empId:");

ob1.empId = s.nextLine();

System.out.println("Enter the empName:");


ob1.name=s.nextLine();

System.out.println("Enter the empDesg:");

ob1.desg=s.nextLine();

System.out.println("Enter the MailId:");

ob1.ec.mailId=s.nextLine();

System.out.println("Enter the PhoneNo:");

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("hashCode of Employee Object : "+ob1.hashCode());


sh
System.out.println("hashCode of EmpContact Object : "+ob1.ec.hashCode());

//Cloned Object or Duplicate Object


ate

Employee ob2 = (Employee)ob1.startCloning();

System.out.println("********Cloned Object**********");
nk

System.out.println("=====Display data from Objects====");

System.out.println(ob2);
Ve

System.out.println(ob2.ec);

System.out.println("====hashCodes===");

System.out.println("hashCode of Employee Object : "+ob2.hashCode());

System.out.println("hashCode of EmpContact Object : "+ob2.ec.hashCode());

s.close();
}

o/p:

Enter the empId:

A121

Enter the empName:

i
thi
Raj

Enter the empDesg:

ipa
SE

Enter the MailId:


Ma
[email protected]

Enter the PhoneNo:

9898981234
sh
********Original Object**********

=====Display data from Objects====


ate

EmpId:A121

EmpName:Raj
nk

EmpDesg:SE

MailId:[email protected]
Ve

PhoneNo:9898981234

====hashCodes===

hashCode of Employee Object : 2074407503

hashCode of EmpContact Object : 999966131

********Cloned Object**********
=====Display data from Objects====

EmpId:A121

EmpName:Raj

EmpDesg:SE

MailId:[email protected]

PhoneNo:9898981234

i
thi
====hashCodes===

hashCode of Employee Object : 1989780873

ipa
hashCode of EmpContact Object : 999966131

==========================================================
Ma
sh
ate
nk
Ve

You might also like