Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles by Teja Kolloju
10 articles
Difference between Iterator and Enumeration in Java
Iterator and Enumeration are both cursors to traverse and access elements from the collection. They both belong to the collection framework. Enumeration was added in JDK1.0 and Iterator in JDK 1.2 version in the collection framework. Java Enumeration Enumeration: An enumeration is a special "class" that indicates a collection of constants. Enumeration can’t make structural changes in the collection because it has read-only access to its elements. It has the following methods − hasMoreElements(): The hasMoreElements() method checks to see if more elements exist in the underlying collection class nextElement(): The ...
Read More\\nDifference between Save and SaveAndFlush in Spring Java\\n
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 is enforcing the synchronization of your model state with the DB. What is the save method? The save method is used to store an entity in the database. It adds the entity to the transactional buffer, and when the transaction is committed, the data is saved. It then returns the stored entity. Example The following is an example of the save method ...
Read MoreDifference between fail-fast and fail safe in Java
In this article, we will find the differences between Fail-Fast and Fail-Safe Iterators. They both describe how collections behave when they are modified during iteration. What is an iterator? An Iterator is an object in Java used to cycle through a collection, accessing or removing elements. It can be obtained by using the iterator() method of a collection. What is FailSafe? Fail-safe also called a Non-Fail-fast Iterator, does not throw ConcurrentModificationException. It works on a copy of the collection. Any changes made in the iterator only affect the copy but not the original collection. Example The following is an ...
Read MoreDifference between volatile and transient in java
In this article, we will find the differences between volatile and Transient. Both have a different purpose for specifying before a variable. These modifiers are important in determining the behavior and characteristics of variables in different cases. What is volatile? A volatile keyword is used in a multithreading environment where two threads reading and writing the same variable simultaneously. The volatile keyword flushes the changes directly to the main memory instead of the CPU cache. Example of Volatile The following is an example of Volatile in Java: public class VolatileExmaple extends Thread { volatile boolean isRunning ...
Read MoreDifference Between CrudRepository and JPARepository in Java
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. What is JPA repository? JPA is a repository interface that 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 ...
Read MoreDifference between Stack and Heap memory in Java
JVM has divided memory space between two parts: one is Stack and another one is Heap space. Stack space is mainly used for storing order of method execution and local variables. Stacks always store blocks in LIFO order whereas heap memory uses dynamic allocation for allocating and deallocating memory blocks. Memory allocated to the heap lives until one of the following events occurs : Program terminated Memory free What is a Heap memory? Heap memory is allocated for storing objects, arrays, and JRE (Java Runtime Environment) classes. Memory may be ...
Read MoreDifference Between ReentrantLock and Synchronized in Java
There are two ways to get a lock on the shared resource by multiple threads. One is a Reentrant Lock (or read/write lock), and the other is by using the Synchronized method. The reentrant lock class has been provided in the Java concurrency package from Java 5. It is the implementation of the Lock interface, and according to Java docs, the implementation of the Lock interface provides more extensive operation than can be obtained using synchronized method. What is the Reentrant lock? ReetrantLock is a class that implements the Lock Interface. It provides the synchronization feature with great flexibility, ...
Read MoreDifference between Serialization and Externalization in Java
Serialization and externalization both are the processes of converting an object to stream byte and storing byte stream in database or memory. The class that implements java.io.Serializable interface can be serialized. What is Serialization? Java provides a mechanism called object serialization where an object can be converted into a byte stream that includes the object's data and details about the object's type. Example The following is an example of Serialization in Java: import java.io.Serializable; class SerializableExample implements Serializable { private static final long serialVersionUID = 5081877L; String name; } public ...
Read MoreDifference between Concurrent hash map and Synchronized hashmap in Java
A Map is an object that stores key-value pairs, where each key is unique but values can repeat. The HashMap is a type of Map that uses a hashtable in order to store these pairs. Now we will discuss the differences between ConcurrentHashMap and Synchronized Hashmap. What is a ConcurrentHashMap? ConcurrentHashMap is a class that was introduced in jdk1.5. ConcurrentHashMap applies locks only at bucket level called fragment while adding or updating the map. So, aConcurrentHashMap allows concurrent read and write operation to the map. Example of ConcurrentHashMap The following is an example of ConcurrentHashMap in java − import java.util.Map; ...
Read MoreDifference between Comparable and Comparator in Java
Comparable and Comparator both are an interface that can be used to sort the elements of the collection. Comparator interface belongs to java.util package while comparable belongs to java.lang package. Comparator interface sort collection using two objects provided to it, whereas comparable interface compares" this" refers to the one objects provided to it. What is a Comparable interface? The Comparable interface is an interface which is used by Java Collections to sort and compare custom objects. It belongs to java.lang package and has a single method called compareTo(). Example of Comparable The following is an example of Comparable in ...
Read More