0% found this document useful (0 votes)
6 views9 pages

Module6_Chapter1_Core Java

This document is a trainer manual for a Core Java module focusing on threading and exception handling. It covers concepts of threading and multithreading, differences between threads and processes, and includes practical exercises and multiple-choice questions for assessment. The total duration for the lesson is 120 minutes, with 80 minutes of theory and 40 minutes of practical work.

Uploaded by

Dillibabu G
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views9 pages

Module6_Chapter1_Core Java

This document is a trainer manual for a Core Java module focusing on threading and exception handling. It covers concepts of threading and multithreading, differences between threads and processes, and includes practical exercises and multiple-choice questions for assessment. The total duration for the lesson is 120 minutes, with 80 minutes of theory and 40 minutes of practical work.

Uploaded by

Dillibabu G
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

CORE JAVA

MANUAL V8.3

MODULE CODE:
DL.A.01.01

ANUDIP FOUNDATION
Trainer
Manual Core Java

1
Trainer
Manual Core Java

Module 6: Thread and Exception Handling

Chapter 1

Objective: After completing this lesson you will be Materials Required:


able to :
* * Gain an understanding regarding the concepts of 1. Computer
threading and multi-threading 2. Internet access
* Learn the differences between threads and
processes in Java

Theory Duration: 80 minutes Practical Duration: 40 minutes

Total Duration: 120 minutes

2
Trainer
Manual Core Java

Chapter 1

1.1 Concept of Threading and Multithreading

A thread in Java is a flow of control within a program. The java.lang.Thread class is used for generating and

controlling threads in Java.

i) Threading

Threading deals with the management and execution of Java threads within programs. Programmers can perform

threading to execute single or multi-threads, based on the requirements of a program. A single thread executes a

single threading within a process. If many tasks need to be run at the same time, using multiple threads is ideal.

ii) Multiple threading

Multiple threads are used for multiple threading of processes. Multithreading is necessary if two or more tasks are to

be run simultaneously within a Java process. Each thread in a multithreaded process might be assigned different tasks.

They can perform their specified tasks at the same time alongside the other threads, or at different times, or at

intervals. Multithreading can also be explained as multiple threads within a process executing byte-code instructions.

Basic multithreading code example

class Multi extends Thread{


public void run(){

System.out.println("multiple thread");

}
public static void main(String args[]){

Multi t1=new Multi();

3
Trainer
Manual Core Java

t1.start();

}
}

Output: multiple thread

1.2 Thread vs Process

The differences between thread and process in Java

* Process is a program while thread is a part of a program.

* Process cannot communicate effectively while thread provides efficient communication.

* Processes run in an isolated manner while threads share memory resources.

* Processes take more time to create and destroy, while threads take less time to both create and destroy.

* Processes are known as heavyweight tasks, while threads are known as lightweight tasks.

Practical (40 minutes)

See the example programme for Java multithreading below. Write the same programme to show multithreading for
the string “multi threads”. Show the resulting output. Repeat the same programme for the string “thread
multiple”

class Multi extends Thread{

public void run(){

System.out.println("multiple thread");

public static void main(String args[]){

Multi t1=new Multi();

t1.start();

4
Trainer
Manual Core Java

5
Trainer
Manual Core Java

Instructions: The progress of students will be assessed with the exercises mentioned below.

MCQ (10 minutes)

1. A Java thread is a flow of ________ within a program.

a) control

b) commands

c) controllers

d) None of the mentioned

2. What class is used for generating a thread in Java?

a) Java.lang.Thread

b) Java.lang

c) Java.util

d) None of the mentioned

3. If a programmer must create a program where two tasks run simultaneously, he will choose _______________.

a) multi threading

b) single threading

c) both a and b

d) None of the mentioned

6
Trainer
Manual Core Java

4. Multiple threads handle ____________ tasks.

a) different

b) only identical

c) rejected

d) None of the mentioned

5. Can two threads work at the same time?

a) No

b) Yes

c) Very rarely

d) They cannot co-exist

6. Multiple threads execute ____________ instructions.

a) bit-code

b) byte-code

c) both a and b

d) None of the mentioned

7. Is a Java process a part of a thread?

a) No

b) sometimes

c) Thread is a process sub-part

7
Trainer
Manual Core Java

d) None of the mentioned

8. Which communicates better?

a) process

b) thread

c) sub-thread

d) None of the mentioned

9. Can threads share memory resources?

a) yes

b) no

c) only sometimes

d) Memory shares thread resources

10. Threads are also known as ______________ tasks.

a) base weight

b) heavyweight

c) lightweight

d) None of the mentioned

You might also like