What is the use of start () method in multithreading

As we discussed earlier that we can create Thread by using following two mechanisms. By Extending the Thread class By Implementing the Runnable Interface By using above two mechanisms we override run () method and add our piece of code inside this. So why we are not directly calling run () method instead of start () method.   Example:

Deadlock by using Main Thread

When any program start JVM create the Main thread. Main thread first search main () method to initialize a class. The main method is mandatory for any standalone application in Java. Can Deadlock happen by using Main Thread? Yes, please see below code for this. Java Example Source Code: package com;   public class JavaDeadLockMainThread

Set Priority of Thread in Java

As we discussed in the earlier article (Main Thread in Java) that if we are not defining the priority of any thread then it will get priority like Main thread. We can also define any thread priority individually. Please see below source code example. Java Source Code: package com;   class AThreadClass extends Thread {                   public void

Main Thread in Java

When a java Program start a Thread start automatically by JVM. Which is called Main Thread. Other threads spawned by this main thread. The first thing the “Main” thread does is to look for your static void main(String args) method and invoke it. That is the entry-point to your program.   The main thread will be the las thread in

Deadlock in Multithreading

Deadlock situation belongs to java multithreading. Deadlock happens when 1st Thread waiting for an object or resource which is acquired by any 2nd Thread and 2nd Thread waiting for an object or resource which is acquired by 1st Thread. In this case, both threads are waiting for each other to release the lock, the condition is called deadlock. Java Source Code: package com;   public class JavaDeadLock

Difference between Thread vs Runnable interface in Java

As we discussed in earlier (Link) multithreading article we can create a thread by using two mechanisms: By Extending the Thread class By Implementing the Runnable Interface By using #1 (Extend Thread class) approach we cannot extend another class because java does not support multiple inheritance. On another side if we use #2 Runnable interface

Java Multithreading

Multithreading is a very popular feature of java. By using multithreading we can run a program in concurrent pieces. We can say this in another way that multithreading allows concurrent execution of two or more parts of a program for maximum utilization of CPU. Each part is called a thread. This is a lightweight process.

Java Daemon Thread

Daemon threads are low priority threads and run in the background. There are many java daemon threads running automatically in background e.g. garbage collection, finalizer etc. You can see these threads by using jconsole in your system. Java Source Code: package com; public class JavaDaemonThreads extends Thread {                   public void run() {                            

Java Volatile Keyword

To make class thread safe we used volatile. By making a class thread-safe instance of class and method can use by multiple threads at a time. If more than one threads are using any class instance and doing modification in class variables. In that case, every thread has its own memory space so any change

Transient variable in java

Transient variable used in case of non-serialization. If we are using serialization and any variable which we don’t want to serialize than we use transient. At the time of serialization if we don’t want to save the value of some variables in a file, then we use transient keyword. When JVM see transient keyword, it ignores the

Java Nested Interface

An interface inside the class or interface is called nested interface. We can’t access nested interface directly, we can access by using outer interface or class. Nested interface is static by default. Who use Nested Interface? To increase encapsulation. Logically grouping of interfaces. To create more readable and maintainable code. Example Source: interface AI{ interface

JAVA Lambda inner class

We can also use Lambda inner class in place of anonymous inner class. Lambda inner class has some limitation if your inner class has more than one method than we can’t use lambda inner class. public class A { // Some code or main method B b = () -> { }; } @FunctionalInterface interface

JAVA Nested static Class

Static inner class is a nested class. This class can’t access non static member variables and methods. We can access this class by outer class name not by an object. This class can access static member variables and methods of outer class including private. Source Code: package com;  public class A {                 static class

Java Member inner class

A non-static class inside a class is called member inner class. This class should not inside a method. Source Code: package com; public class A { class B{ } } Example Java Code: package com; public class InnerClass { public static void main(String args) { InnerMemberClass innerMemberClass = new InnerMemberClass(); innerMemberClass.setPersonName("Siddhant");   InnerMemberClass.B obj =

Java Anonymous inner class

Java anonymous classes are without name. They are local classes. We create anonymous classes to override a method of interface or class. Anonymous inner class by using a class: Java Source Code: package com; abstract class A { abstract void display(); } public class B { public static void main(String args) { A a =

Java Inner Classes

Java inner class is a class inside a class or interface. To handle user interface events, we should know how to use inner classes, because the event-handling programming makes extensive use of them. Sample Source Code: package com; public class A {                 class B{                 } } Advantages to create an inner class: By

Hindi heart touching poetry

Amazing shayari, best amazing shayri, best hindi poetry, best shayari, bewafai, from the bottom of the heart, heart touching, heart touching poetry, hindi, Hindi emotional shayari, hindi poetry, hindi shayari, Indian poetry, shayari, world best shayari

Difference between the instanceof operator and isInstance () method

Difference between the instanceof operator and isInstance () method: Both uses for the same purpose means instanceof operator and isInstance () method. We can check the class of the object by these two. If we want to check the class of object dynamically, in this case, isInstance () method will work. There is no way we can do this by the instanceof operator.

Difference between arithmetic + (Plus) operator and ++ (Increment) operator.

Difference between arithmetic + (a+1) operator and ++ (a++) operator. Here is some example to understand both operators. Source 1: package com; public class DiffBtwArthOperAndIncreOperator { public static void main(String args) { byte b = 2; b = b+1; System.out.println("Print a value "+b); } }   Response 1: Compile Time Error: Exception in thread "main"

Sum of the Even Numbers in an Array

Sum of the Even Numbers in an Array: Source: package com; public class EvenNumberSum { public static void main(String args) { int intArr = { 4, 7, 1, 2, 8, 9, 56, 12, 1, 34, 2, 56 }; int sum = 0; for (int i = 0; i <= intArr.length-1; i++) { if (intArr[i] %