Oops Iat3
Oops Iat3
Diagram:
2 a) How can we create a Thread in java? Write a program to create a thread using any one
way. [5] CO5 L2
Explanation: There are two ways to create a thread:
1. By extending Thread class
2. By implementing Runnable interface.
1. Program:
class Multi extends Thread{
public void run(){
System.out.println("thread is running...");
}
public static void main(String args[]){
Multi t1=new Multi();
t1.start();
}
}
// Synchronized block
public void synchronizedBlock() {
synchronized (lock) {
// Code that needs to be synchronized
}
}
}
1. b) Write details about the below methods used in multithreading.
1. sleep() , 2. yield(), 3. join() [5] CO5 L1
4. suspend()
5. resume()
6. stop()
7. getName()
8. isAlive()
9. start()
10. run()
Explanation :
1. sleep(): Pauses the execution of the current thread for a specified amount of time,
allowing other threads to execute.
2. yield(): Suggests to the scheduler that the current thread is willing to yield its current
use of a processor, allowing other threads to run.
3. join(): Waits for the specified thread to finish its execution before the current thread
continues.
4. suspend(): Deprecated method that temporarily halts the execution of a thread. Should
be avoided due to potential deadlock issues.
5. resume(): Deprecated method that resumes the execution of a suspended thread.
Should be avoided due to potential deadlock issues.
6. stop(): Deprecated method that abruptly stops the execution of a thread. Should be
avoided due to unsafe termination.
7. getName(): Returns the name of the thread.
8. isAlive(): Checks if the thread is still alive (has been started and not terminated).
9. start(): Initiates the execution of a thread by invoking its run() method.
10. run(): Contains the code to be executed by the thread when started using the start()
method.
4 a) Explain how autoboxing and unboxing work for boolean and character values in Java.
Explanation: [5] CO5 L3
Autoboxing and unboxing are mechanisms in Java that allow automatic conversion
between primitive data types and their corresponding wrapper classes. Autoboxing is the
process of converting a primitive type to its corresponding wrapper class, while unboxing is
the process of extracting the primitive value from the wrapper class. This process simplifies
code and enhances readability.
For boolean and character values:
1. Autoboxing (Primitive to Wrapper):
b) What is Inter Thread communication in java? Define the working of wait(), notify() and
notifyAll() methods with example. [5] CO5 L3
Explanation: Inter Thread Communication in Java refers to the communication between
two or more threads to synchronize their actions and coordinate their execution. This is
achieved using methods like wait(), notify(), and notifyAll() provided by the Object class.
1. wait():
The wait() method is used by a thread to release the lock it holds and wait until
another thread invokes notify() or notifyAll() on the same object.
It should be called within a synchronized block or method to avoid illegal monitor
state exception.
2. notify():
The notify() method is used to wake up one of the threads that are currently
waiting on the same object.
It is important to note that notify() does not release the lock immediately; the lock
is released only when the synchronized block or method is exited.
3. notifyAll():
The notifyAll() method is used to wake up all threads that are currently waiting on
the same object.
Like notify(), notifyAll() does not release the lock immediately.
Example:
enum Days {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY
}
Autoboxing: It is the process of converting a primitive data type into its corresponding
wrapper class object automatically by the Java compiler.
Unboxing: It is the process of converting a wrapper class object into its corresponding
primitive data type automatically by the Java compiler.
Example:
public class WrapperExample {
public static void main(String[] args) {
// Autoboxing: converting primitive to wrapper
Integer intValue = 42; // int to Integer
Double doubleValue = 3.14; // double to Double
Boolean boolValue = true; // boolean to Boolean
// Autoboxing in collections
java.util.List<Integer> integerList = new java.util.ArrayList<>();
integerList.add(1); // int to Integer
integerList.add(2); // int to Integer
}
class MyThread2 implements Runnable {
// Complete the code print “thread-2” 5 times
}
public class GFG {
public static void main(String[] args)
{
// (create both threads and start the threads to print the output)
Complete the code
}
Complete Program:
class MyThread1 implements Runnable {
@Override
public void run() {
for (int i = 0; i < 5; i++) {
System.out.println("thread-1");
}
}
}
Program :
public class MainThreadPriorityExample {
public static void main(String[] args) {
// Getting the current main thread
Thread mainThread = Thread.currentThread();
CI CCI HOD
PO Mapping
COGNITIVE
REVISED BLOOMS TAXONOMY KEYWORDS
LEVEL
List, define, tell, describe, identify, show, label, collect, examine, tabulate, quote, name, who,
L1
when, where, etc.
summarize, describe, interpret, contrast, predict, associate, distinguish, estimate, differentiate,
L2
discuss, extend
Apply, demonstrate, calculate, complete, illustrate, show, solve, examine, modify, relate,
L3
change, classify, experiment, discover.
L4 Analyze, separate, order, explain, connect, classify, arrange, divide, compare, select, explain,
infer.
Assess, decide, rank, grade, test, measure, recommend, convince, select, judge, explain,
L5
discriminate, support, conclude, compare, summarize.
CORRELATION
PROGRAM OUTCOMES (PO), PROGRAM SPECIFIC OUTCOMES (PSO)
LEVELS
PO1 Engineering knowledge PO7 Environment and sustainability 0 No Correlation
PO2 Problem analysis PO8 Ethics 1 Slight/Low
Moderate/
PO3 Design/development of solutions PO9 Individual and team work 2
Medium
Conduct investigations of Substantial/
PO4 PO10 Communication 3
complex problems High
PO5 Modern tool usage PO11 Project management and finance
PO6 The Engineer and society PO12 Life-long learning
PSO1 Develop applications using different stacks of web and programming technologies
PSO2 Design and develop secure, parallel, distributed, networked, and digital systems
PSO3 Apply software engineering methods to design, develop, test and manage software systems.
PSO4 Develop intelligent applications for business and industry