Difference between synchronized static and instance methods

This article is about difference between synchronized static and instance methods with example. Here i am going to explain this with 5 different scenarios. Scenario : 1 When one thread accessing synchronized instance method at that time other threads can NOT access ANY synchronized instance methods. Scenario : 2 When one thread accessing synchronized instance […]

Share
Continue reading →

clone method in Java

clone method is a part of Object class like equal method. We can override clone method in any class. But to use clone method we need to implement Cloneable interface. Without implementing Cloneable interface you can not use clone method otherwise It will throws CloneNotSupportedException Clone method is used to create clone of object. IMPORTANT […]

Share
Continue reading →

Selection sort in java

This article is about selection sort in java For example we want to sort below array of integers. int[] index = { 10, 34, 4, 56, 7, 67, 88, 42 }; Selection sort start with first position means here it takes 10 and compares it with each and every other integers in array starting with […]

Share
Continue reading →

Java wait and sleep methods with example

Difference between wait and sleep 1. sleep() is a static method and It sends current running thread into the “Not Runnable” state. wait() is a instance method we are calling it using thread object and it is only affected for that object. 2. sleep() : Thread weak up after time expire or call interrupt() method. […]

Share
Continue reading →

Atomic and Non-Atomic Operations in Java

This article is all about atomic operations in java. Atomic operations are take place in one step. Like read and write operation of variable. atomic operations cannot be interrupted and they are thread safe, In java read and write operations are atomic for all variables which are less or equal to 32 bit. In some […]

Share
Continue reading →

Volatile in Java

volatile is a keyword in java. It is use with variable, You can not use it with method or class. volatile keyword tells JVM and Threads that don’t cache the value, always read from main memory. volatile variable is visible across all threads. All threads will always gets updated values . Use of volatile volatile […]

Share
Continue reading →

Insertion sort in java

This article is about insertion sorting algorithm in java. For example we want to sort below array of integers. int[] input = { 5, 3, 8, 14, 24, 13, 35, 1, 2, 0 }; Insertion sorting start with comparing 2nd integers with first integer like in above array we will compare 3 with 5 here […]

Share
Continue reading →

Constructor reference in java 8

Constructor reference in java 8 This article is about constructor reference in java 8. Like a method reference we can also use constructor reference in java 8. Read more about method reference here. Now before start with example code you need to take care of few things. Constructor reference only works with Functional Interface. Read […]

Share
Continue reading →

Method references in java 8

Method references in java 8 In java 8 we can pass method references. In this article I am going to explain how to pass static and instance method reference. :: is use for passing a method reference to another method call. Example Code : In this example we are going to create one interface and […]

Share
Continue reading →