Difference between Concurrent hash map and Synchronized hashmap in Java

Mahesh Parahar
Updated on 18-Nov-2019 06:43:10

6K+ Views

Concurrent Hashmap is a class that was introduced in jdk1.5.  Concurrent hash map applies locks only at bucket level called fragment while adding or updating the map. So, a concurrent hash map allows concurrent read and write operation to the map. Synchronized hashmap(Collection.syncronizedHashMap()) is a method of Collection framework. This method applies a lock on the entire collection. So, if one thread is accessing the map then no other thread can access the same map. Sr. No.KeyConcurrent hash mapSynchronized hashmap1ImplementationIt is a class that implements a Concurrent hash map and serializable interface. It is a method in Collection class.  2Lock mechanismLocks the portionLocks ... Read More

Difference between Iterator and Enumeration in Java

Mahesh Parahar
Updated on 18-Nov-2019 06:30:54

5K+ Views

Iterator and Enumeration both are the cursors to traverse and access an element from the collection. They both belong to the collection framework. Enumeration was added in JDK1.0 and Iterator in the JDK.1.2 version in the collection framework. Enumeration can’t make structural changes in the collection because it has read-only access to the element in the collection. It has the following methods :*hasMoreElements()*nextElement()On the other hand, an iterator can read and remove the element in the collection. It has the following methods −*hasNext()*next()*remove()Sr. No.KeyIteratorEnumeration1BasicIn Iterator,  we can read and remove element while traversing element in the collections. Using Enumeration, we can only ... Read More

Difference between lazy and eager loading in Hibernate

Mahesh Parahar
Updated on 18-Nov-2019 06:20:10

12K+ Views

Lazy and Eager are two types of data loading strategies in ORMs such as hibernate and eclipse Link.  These data loading strategies we used when one entity class is having references to other Entities like Employee and Phone (phone in the employee). Lazy Loading − Associated data loads only when we explicitly call getter or size method.Use Lazy Loading when you are using one-to-many collections.Use Lazy Loading when you are sure that you are not using related entities. Egare Loading − Data loading happens at the time of their parent is fetched. Use Eager Loading when the relations are not too much. Thus, ... Read More

\Difference between Save and SaveAndFlush in Spring Java\

Mahesh Parahar
Updated on 18-Nov-2019 06:14:24

4K+ Views

Save and saveAndFlush both can be used for saving entities. They both are both belong to the Spring data library. save may or may not write your changes to the DB straight away. When we call saveAndFlush system are enforcing the synchronization of your model state with the DB.Sr. No.KeySaveSaveAndFlush1RepositoryIt belongs to CrudRepositoryIt belongs to JPARepository2Data flush StrategyIt doesn't flush data directly to a database until and unless we explicitly call flush and commit method.It's flush directly flush data to a database.3Bulk SaveCrudRepository provides bulk save methodsaveAndFlush method doesn't support the bulk operation 4Data Visibility after savingIt doesn't flush data directly ... Read More

Difference Between CrudRepository and JPARepository in Java

Mahesh Parahar
Updated on 18-Nov-2019 06:07:52

18K+ Views

CrudRepository and JPA repository both are the interface of the spring data repository library. Spring data repository reduces the boilerplate code by providing some predefined finders to access the data layer for various persistence layers.JPA repository extends CrudRepository and PagingAndSorting repository. It inherits some finders from crud repository such as findOne, gets and removes an entity. It also provides some extra methods related to JPA such as delete records in batch, flushing data directly to a database base and methods related to pagination and sorting.We need to extend this repository in our application and then we can access all methods ... Read More

How to display count of notifications in Android App?

Azhar
Updated on 15-Nov-2019 12:31:36

256 Views

This example demonstrates how How to display the count of notifications in Android App launcher.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Add the following code to src/MainActivity.javapackage com.app.sample; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.NotificationCompat; import android.annotation.SuppressLint; import android.os.Bundle; import android.app.NotificationChannel ; import android.app.NotificationManager ; import android.app.PendingIntent ; import android.content.Intent ; import android.os.Bundle ; import android.view.View ; import static android.app.Notification. BADGE_ICON_SMALL ; public class MainActivity extends AppCompatActivity {    static ... Read More

How to implement a custom AlertDialog View in Android?

Azhar
Updated on 15-Nov-2019 12:23:59

903 Views

This example demonstrates how to implement a custom AlertDialog View in Android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Add the following code to res/layout/my_dialog.xml.                           Step 4 − Add the following code to res/drawable/button_background.xml.                                   ... Read More

What is the height of the status bar in Android?

Azhar
Updated on 15-Nov-2019 12:14:57

2K+ Views

This example demonstrates how to height of the status bar in Android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Add the following code to src/MainActivity.javapackage com.app.sample; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.content.res.Resources; import android.os.Bundle; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       getStatusBarHeight();    }    private int getStatusBarHeight() ... Read More

How to animate RecyclerView items when they appear on screen?

Azhar
Updated on 15-Nov-2019 12:11:51

900 Views

This example demonstrates how to animate RecyclerView items when they appear on the screen .Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to res/anim/down_to_up.xml.         Step 4 − Add the following code to res/anim/left_to_right.xml.         Step 5 − Add the following code to res/anim/right_to_left.xml.         Step 6 − Add the ... Read More

How to make the corners of a button round in Android?

Azhar
Updated on 15-Nov-2019 11:59:19

2K+ Views

This example demonstrates how to make the corners of a button round in Android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.javapackage com.app.sample; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);    } }Step 4 − Add the following code to res/drawable/mybutton.xml.       ... Read More

Advertisements