Programming Articles

Page 1671 of 2547

Difference between Stack and Heap memory in Java

Teja Kolloju
Teja Kolloju
Updated on 15-Apr-2025 7K+ Views

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 More

Difference Between ReentrantLock and Synchronized in Java

Teja Kolloju
Teja Kolloju
Updated on 15-Apr-2025 5K+ Views

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 More

Difference between Serialization and Externalization in Java

Teja Kolloju
Teja Kolloju
Updated on 15-Apr-2025 4K+ Views

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

Difference between Concurrent hash map and Synchronized hashmap in Java

Teja Kolloju
Teja Kolloju
Updated on 15-Apr-2025 9K+ Views

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

Difference between Comparable and Comparator in Java

Teja Kolloju
Teja Kolloju
Updated on 15-Apr-2025 7K+ Views

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

C++ Program to Check the Connectivity of Directed Graph Using BFS

Farhan Muhamed
Farhan Muhamed
Updated on 15-Apr-2025 964 Views

The Breadth-First Search (BFS) algorithm is a graph traversal algorithm that starts at the tree root and explores all nodes at the present depth before moving to the nodes at the next level. In this article, we will discuss how to check the connectivity of a directed graph using BFS traversal algorithm. Understanding Connectivity of a Graph A graph is said to be connected if there is a path between every pair of vertices. To check connectivity of a graph, we will try to traverse all nodes using any traversal algorithm. After completing the traversal, if there is any ...

Read More

Why is the size of an empty class not zero in C++?

Ravi Ranjan
Ravi Ranjan
Updated on 15-Apr-2025 2K+ Views

The size of an empty class is not zero in C++ as it allocates one unique address to the object in the memory. The size can not be 0, because the two classes can not have the same memory address. So, the size of an empty class is 1 byte which does not hold any data, it is just for memory allocation. In this article, we will see an example of checking the size of an object of an empty class in C++. Demonstrating Size of an Empty Class In this approach, we have two C++ classes. One class ...

Read More

C++ Program to Find Minimum Element in an Array using Linear Search

Ravi Ranjan
Ravi Ranjan
Updated on 15-Apr-2025 1K+ Views

Linear search is a sequential searching algorithm where we traverse every element within the input array and compare it with the key element to be found. The minimum element refers to the smallest element in the array. In this article, we have an array of integers. Our task is to find the minimum element in that array using linear search. Here are the three approaches you can use to find the minimum element: Using Value Using Index Using Pointer Using Value In this approach, ...

Read More

C Program to print numbers from 1 to N without using semicolon

Ravi Ranjan
Ravi Ranjan
Updated on 15-Apr-2025 2K+ Views

Printing numbers from 1 to N is an easy task that can be achieved using loops, but to print numbers from one to N without using a semicolon is a tricky question. We will discuss two different methods to solve this question using iteration and recursion approaches. In this article, our task is to print numbers from 1 to 'n' and we don't have to use a semicolon. The approaches are listed below: Using Iteration Using Recursion Using Iteration This approach uses the iterative approach, where we have used the while loop to print the numbers from 1 to N. The num

Read More

C Program to sum the digits of a given number in single statement

Ravi Ranjan
Ravi Ranjan
Updated on 15-Apr-2025 673 Views

The calculation of the sum of the digits of a number in a single statement means that only one line of code will be doing the addition operation. The addition operation should not extend more than one statement. In this article, we have a number and our task is to calculate the sum of the digits of the number in a single statement in c. Here is a list of approaches: Using for Loop Using Recursive Function Using for Loop This approach uses a for loop to calculate the ...

Read More
Showing 16701–16710 of 25,466 articles
Advertisements