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 More
In this article, we will compare the Java Error class and the Java Exception class. Both exceptions and errors are subclasses of the Throwable class. The error indicates a problem that mainly occurs due to the lack of system resources and our application should not catch these types of problems. It's important to note that the term error in general programming refers to mistakes in code, logic, or unexpected behavior. The Java Error class is not the same as general errors. What is an Error? An Error is a subclass of the Throwable class that represents serious problems that ... Read More
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 More
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
What is Linked List? A linked list is a linear data structure which can store a collection of "nodes" connected together via links i.e. pointers. Linked lists nodes are not stored at a contiguous location, rather they are linked using pointers to the different memory locations. A linked list can be used for graph representations. In the graph representation: Each vertex has its own linked list that stores its adjacent vertices. This forms an adjacency list using linked lists instead of vectors or arrays. Graph The image below ... Read More
What is Adjacency List? An adjacency list is a collection of unordered lists that are used to represent a finite graph. Each list in the collection represents one of the vertex of the graph and it will store the adjacent vertices of that vertex. Let's see an example: Graph The image below represent a simple undirected graph with 6 vertices and 8 edges. Adjacency List The adjacency list of the above graph is shown below. Algorithm The following are the steps to create (represent) a graph using an adjacency list: ... Read More
What are Python Modules? Python module is a ".py" file that contains Python definitions, functions, classes, variables, constants, or any other objects. Contents in this file can be re-used in any other program. Packaging in Python Python packaging involves compressing bundles of Python code in a particular format that can be publically shared and can be installed by a tool like pip. Importing Modules To use the functionality present in any module, you need to use the import keyword along with the module name. This keyword will import the module to your current program. Syntax for this keyword is - ... Read More
What is incidence matrix? An incidence matrix is a mathematical representation of a graph that shows the relationship between vertices and edges. In other words, it is a matrix M of size v x e, where v = number of vertices and e = number of edges. For example, if the graph has an edge number n from vertex i to vertex j, then in the incidence matrix at ith row and nth column it will be 1. Graph The image below represent a simple undirected graph with 6 vertices and 8 edges. Incidence Matrix The incidence ... Read More
What is Adjacency Matrix? Adjacency matrix is a square matrix that represent a finite graph data structure using a 2D array. The each elements in the matrix represent the edges of the graph. For example, if the graph has some edges from i to j vertices, then in the adjacency matrix at ith row and jth column it will be 1 (or some non-zero value for weighted graph), otherwise that place will hold 0. Graph The image below represent a simple undirected graph with 6 vertices and 8 edges. Adjacency Matrix The adjacency matrix of the ... Read More
A tuple is an ordered, immutable sequence of elements. In Python, the grouping of elements in a tuple list based on the values of their second elements can be done using various methods like using a dictionary or using itertools.groupby() method and using defaultdict from collections. Grouping the first elements by second elements in the Tuple list means the tuple having the same second element can be grouped into a single group of elements. In this article, we will discuss how we can implement these methods so that we are able to easily group the first elements based on ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP