Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Java Notes

Rating
-
Sold
-
Pages
6
Uploaded on
25-06-2025
Written in
2024/2025

Exception Handling in Java is a powerful mechanism to handle runtime errors gracefully, ensuring that the normal flow of the application is maintained. It uses keywords like try, catch, throw, throws, and finally to detect and manage exceptions such as ArithmeticException, IOException, and user-defined exceptions.

Show more Read less
Institution
Course

Content preview

MULTI THREADING IN JAVA


🌟 What is Multithreading in Java?
Multithreading in Java is a process of executing multiple threads
simultaneously. A thread is the smallest unit of execution in a program.

Multithreading allows:

 Efficient CPU utilization.
 Better performance for programs with multiple tasks.
 Parallel execution of code.



🔁 Difference Between Process and Thread
Feature Process Thread
Definition An independent program A smaller unit of a process

Memory Each process has its own memory Shares memory with other threads

Communic-
Complex Easy (since memory is shared)
-ation
Overhead More Less

Example Chrome, Word Tabs in Chrome, background tasks

, 🧵 Life Cycle of a Thread
Java threads go through five stages:

Stage Description
New Thread is created using a constructor
Runnable Thread is ready to run but waiting for CPU
Running Thread is executing
Blocked Thread is waiting to acquire a lock
Terminated Thread has finished execution or has been stopped

(Image for reference only)


🛠️Creating Threads in Java
Java provides two main ways to create threads:

1. By extending the Thread class
java
CopyEdit
class MyThread extends Thread {
public void run() {
System.out.println("Thread running...");
}

public static void main(String[] args) {
MyThread t1 = new MyThread();
t1.start(); // starts the thread
}
}

2. By implementing the Runnable interface
java
CopyEdit
class MyRunnable implements Runnable {
public void run() {
System.out.println("Runnable thread running...");
}

public static void main(String[] args) {
Thread t = new Thread(new MyRunnable());
t.start();
}
}

Written for

Course

Document information

Uploaded on
June 25, 2025
Number of pages
6
Written in
2024/2025
Type
Class notes
Professor(s)
Mr. amit
Contains
All classes

Subjects

$10.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
sanjanasingh6

Get to know the seller

Seller avatar
sanjanasingh6 Maharaja Agrasen
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
10 months
Number of followers
0
Documents
2
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions