Object Oriented Techniques Using Java (ACSE0302) : Unit: 4
Object Oriented Techniques Using Java (ACSE0302) : Unit: 4
Object Oriented Techniques Using Java (ACSE0302) : Unit: 4
Unit : 4
Sl. Subject Ev E
No. Codes Subject Name
P alu nd Total Credit
e ati
on
Se
m
r Sc est
he er
i me
o s
d
s
L T P C TA TO PS T P
T TAL E E
W
E
E
K
S
C
O
M
P
U
L
S
O
R
Y
11/24/2021 Ms. SAVITA YADAV OOT Using
I Java Unit-4
N
Syllabus
Course
Contents /
Syllabus
UNIT-I Introduction 8 Hours
Object Oriented Programming: Introduction and Features:
Abstraction, Encapsulation, Polymorphism, and Inheritance.
Modeling Concepts: Introduction, Class Diagram and Object
Diagram.
Control Statements: Decision Making, Looping and Branching,
Argument Passing Mechanism: Command Line Argument.
Image Recognition
Speech Recognition
Stock market trading
AI Programming
Genetic programming
11/24/2021
Ms. SAVITA YADAV OOT Using Java Unit-3
Course Outcomes
Course outcomes : After completion of this course students will be able to
11/24/2021
Ms. SAVITA YADAV OOT Using Java Unit-4
CO-PO Mapping
CO.2 3 3 3 2 1 2 3
CO.3 3 3 3 2 1 2 3
CO.4 3 3 3 2 1 2 3
CO.5 3 3 3 2 1 2 3
General Instructions:
All questions are compulsory. Answers should be brief and to the point.
This Question paper consists of …………pages & …8………questions.
It comprises of three Sections, A, B, and C. You are to attempt all the sections.
Section A -Question No- 1 is objective type questions carrying 1 mark each, Question No- 2 is very short
answer type carrying 2 mark each. You are expected to answer them as directed.
Section B - Question No-3 is Long answer type -I questions with external choice carrying 6 marks each.
You need to attempt any five out of seven questions given.
Section C - Question No. 4-8 are Long answer type –II (within unit choice) questions carrying 10 marks
each. You need to attempt any one part a or b.
Students are instructed to cross the blank sheets before handing over the answer sheet to the invigilator.
No sheet should be left blank. Any written material after a blank sheet will not be evaluated/checked.
3- Question-
(6)
a.
3- Question-
(6)
b.
3- Question-
(6)
c.
3-
11/24/2021 Question- Ms. SAVITA YADAV OOT Using Java (6)
Unit-3
Prerequisite and Recap
https://www.youtube.com/watch?v=OjdT2l-EZJA
Creating Threads
Thread Life-Cycle
Thread Priorities
Daemon Thread
Runnable Class
Synchronizing Threads
I/O Stream: Introduction and Types
Custom Annotations
Applying Annotations
Threads
Threads allows a program to operate more efficiently by
doing multiple things at the same time.
Threads can be used to perform complicated tasks in the
background without interrupting the main program.
Java is a multi-threaded programming language which
means we can develop multi-threaded program using Java.
A multi-threaded program contains two or more parts that
can run concurrently, and each part can handle a different
task at the same time making optimal use of the available
resources specially when your computer has multiple CPUs.
Multitasking is when multiple processes share common
processing resources such as a CPU.
Types of threads
There are two types of Threads in java.
User threads are threads which are created by the
application or user.
They are high priority threads.
JVM (Java Virtual Machine) will not exit until all user
threads finish their execution.
JVM wait for these threads to finish their task. These
threads are foreground threads.
Step 2
As a second step, you will instantiate a Thread object using the
following constructor −
Thread(Runnable threadObj, String threadName);
Where, threadObj is an instance of a class that implements the
Runnable interface and threadName is the name given to the new
thread.
Step 3
Once a Thread object is created, you can start it by calling start()
method, which executes a call to run( ) method. Following is a
simple syntax of start() method −
void start();
11/24/2021 Ms. SAVITA YADAV OOT Using Java Unit-4
Creating Threads
Example:
Step 2
Once Thread object is created, you can start it by
calling start() method, which executes a call to run( )
method. Following is a simple syntax of start()
method-
void start( );
Example:
Blocked
Waiting
For example, when a thread is waiting for I/O to
complete, it lies in the blocked state.
It’s the responsibility of the thread scheduler to
reactivate and schedule a blocked/waiting thread.
A thread in this state cannot continue its execution any
further until it is moved to runnable state. Any thread in
these states does not consume any CPU cycle.
A thread is in the blocked state when it tries to access a
protected section of code that is currently locked by
some other thread.
Every Java thread has a priority that helps the operating system determine
the order in which threads are scheduled.
Java thread priorities are in the range between MIN_PRIORITY (a constant
of 1) and MAX_PRIORITY (a constant of 10). By default, every thread is
given priority NORM_PRIORITY (a constant of 5).
Threads with higher priority are more important to a program and should be
allocated processor time before lower-priority threads.
However, thread priorities cannot guarantee the order in which threads
execute and are very much platform dependent.
Types of Synchronization
There are basically two types of synchronization
available. They are:
Process Synchronization: It means sharing system
resources by processes in such a way that, Concurrent
access to shared data is handled thereby minimizing
the chance of inconsistent data.
Thread Synchronization: It means that every access to
data shared between threads is protected so that
when any thread starts operation on the shared data,
no other thread is allowed access until the first
thread is done.
@Override
@Override annotation assures that the subclass method is
overriding the parent class method. If it is not so,
compile time error occurs.
@SuppressWarnings
@SuppressWarnings annotation is used to suppress
warnings issued by the compiler.
@Deprecated
@Deprecated annotation marks that this method is
deprecated so compiler prints warning. It informs user
that it may be removed in the future versions. So, it is
better not to use such methods.
11/24/2021 Ms. SAVITA YADAV OOT Using Java Unit-4
Custom Annotations
Q1. Which of these method of Thread class is used to find out the priority
given to a thread?a) get()b) ThreadPriority()c) getPriority()d)
getThreadPriority()
Q2. Which of these method of Thread class is used to Suspend a thread for
a period of time?a) sleep()b) terminate()c) suspend()d) stop()
Q9. Which of these stream contains the classes which can work on
character stream?
a) InputStream
b) OutputStream
c) Character Stream
d) All of the mentioned
Q10.Which of these method of FileReader class is used to read characters
from a file?
a) read()
b) scanf()
c) get()
d) getInteger()
https://www.youtube.com/watch?v=qQVqfvs3p48
https://www.youtube.com/watch?v=TCd8QIS-2KI
https://www.youtube.com/watch?v=vd9nJK22BwU
Q1.Which version of Java introduced annotation?a) Java 5b) Java 6c) Java
7d) Java 8
Q2.Annotations which are applied to other annotations are called meta
annotations.a) Trueb) False
Q3.Which of these is used to perform all input & output operations in
Java?a) streamsb) Variablesc) classesd) Methods
1. Discuss how to set the priority to threads? What are the different
ranges.
2. Write a java program to create two threads and execute
simultaneously
3. Write a Java program that creates three threads. First thread
displays “Hello!” every one second, the second thread displays
“Wear Mask !” every two seconds and “Use Sanitizer !” every 5
seconds.
4. Write the difference between Extending thread and implementing
runnable?
5. Explain in detail about thread methods?
THANK YOU !!