📌What are threads?
Threads allow a program to operate more efficiently by doing multiple things at the same time.
Every java application has at least one thread – the main thread. But from the application point of view – main is the first java thread and we can create multiple threads from it.
Multithreading refers to two or more threads executing concurrently in a single program
Threads can be used to perform complicated tasks in the background without interrupting the main program.
📌Life cycle of a thread
🔸New −
A new thread begins its life cycle in the new state. It remains in this state until the program starts the thread. It is also referred to as a born thread
🔸Runnable −
After a newly born thread is started, the thread becomes runnable. A thread in this state is considered to be executing its task
🔸Waiting −
Sometimes, a thread transitions to the waiting state while the thread waits for another thread to perform a task. A thread transition back to the runnable state only when another thread signals the waiting thread to continue executing
🔸Timed Waiting −
A runnable thread can enter the timed waiting state for a specified interval of time. A thread in this state transitions back to the runnable state when that time interval expires or when the event it is waiting for occurs
🔸Terminated (Dead) −
A runnable thread enters the terminated state when it completes its task or otherwise terminates
📌Ways of creating threads
There are two ways of creating threads - 1. Extending Thread class 2. Implementing Runnable interface
🔸Extending Thread class -
We need to override the run() method in the Thread class. To start the thread we use the start() method on the thread object which executes a call to the run() method.
🔸Implementing Runnable Interface -
📌Thread priorities
Every Java thread has a priority that helps determine the order in which threads are scheduled.
By default, every thread is given priority NORM_PRIORITY (a constant of 5)
Many people ask me that 'Which programming language should I learn..?'
Well here are some programming languages with their uses. Choose yourself based on your interest.
📌Python -
🔸Artificial Intelligence
🔸Machine Learning
🔸Data analytics
🔸Data visualization
🔸Web development using the frameworks - Django, Pyramid, and flask
🔸Game development using python
🔸Python used in the field of Search Engine Optimisation (SEO)
“In order to understand recursion, one must first understand recursion.”
📌Fun Activity
Google 'recursion' and you will find that Google will ask 'Did you mean: recursion'. Despite clicking on recursion from spell checker – Did you mean, Google will keep on displaying it. Though the spelling is right, Google keeps on telling it again and again.
📌What is inheritance?
When we want to create a new class and there is already a class that includes some of the code that we want, we can derive our new class from the existing class (and avoid the writing of the same code again). This is referred to as inheritance.
As a programmer you might have come across both these words- coding and programming but do you know the actual difference between the two
Let us look at the difference between both these terms now and let me clear your doubts.
Read to the end of the thread!
📌Coding
Coding is basically the act of translating codes from human language to machine-based language. It can also be called a subset of programming since it is the foundation of programming