Found 33676 Articles for Programming

Difference between new and malloc( )

AmitDiwan
Updated on 24-Mar-2021 12:48:23

1K+ Views

In this post, we will understand the difference between ‘new’ and ‘malloc’.newIt is present in C++, Java, and C#.It is an operator that can be used to call the constructor of the object.It can be overloaded.If it fails, an exception is thrown.It doesn’t need the ‘sizeof’ operator.It doesn’t reallocate memory.It can initialize an object when allocating memory for it.The memory allocated by ‘new’ operator can be de-allocated using ‘delete’ operator.It reduces the execution time of the application.Example#include using namespace std; int main(){ int *val = new int(10); cout Read More

Difference Between dispose() and finalize() in C#

AmitDiwan
Updated on 24-Mar-2021 12:47:38

1K+ Views

In this post, we will understand the difference between the methods ‘dispose’, and ‘finalize’ in C#.DisposeThis method is defined in the IDisposable interface.It has to be invoked by the user.Whenever it is invoked, it helps free the unmanaged resources.It can be implemented whenever a close() method is present.It is declared as public method.It is quick, and instantly disposes an object.Since it performs instantaneously, it doesn’t affect performance.FinalizeIt is a method that is defined in the java.lang.object class.It is invoked by the garbage collector.It helps free the unmanaged resources just before the object is destroyed.It is implemented to manage the unmanaged ... Read More

Difference Between extends and implements keywords in Java

AmitDiwan
Updated on 24-Mar-2021 12:42:58

2K+ Views

In this post, we will understand the differences between ‘Extends’ and ‘Implements’ keyword.ExtendsUsing this, a class can be used as a base class, and another class inherits this base class.An interface can also inherit other interfaces using this keyword.Only one superclass can be extended by a class.Any number of interfaces can be extended by an interface.It is not required for the subclass (that extends a superclass) to override all the methods in the superclass.Following is an example of the extends keyword −Exampleclass Super { ..... ..... } class Sub extends Super { ... Read More

Difference Between List and ArrayList in Java

Kiran Kumar Panigrahi
Updated on 23-Jun-2023 13:29:42

3K+ Views

A collection framework in Java consists of a set of classes and interfaces which helps in implementing various data structures. List and ArrayList belong to this collection framework. List is an interface and ArrayList is a class. Their main motto is to create a list data structure. List is a collection of ordered elements arranged using the concept of indexing. Arrays use the concept of dynamic array to store elements. What is a List in Java? A list is one of the interfaces of the collection framework. It stores objects in an ordered manner. Here, the elements are stored sequentially. ... Read More

Difference Between HashMap and LinkedHashMap in Java

AmitDiwan
Updated on 24-Mar-2021 12:38:17

1K+ Views

In this post, we will understand the difference between HashMap and LinkedHashMap in Java.HashMapIn this structure, the order of insertion is not preserved.It uses the HashTable to store maps.It extends the ‘AbstractMap’.It implements the ‘Map’ interface.This was introduced in JDK 2.0.It has a relatively low overhead.LinkedHashMapIn this structure, the order of insertion is not preserved.It uses the HashTable and Linked List to store maps.It extends the ‘Hashmap’.It implements the ‘Map’ interface.This was introduced in JDK 4.0.It has a relatively higher overhead.This is because it has to maintain the order of entries in the map structure.Read More

Difference Between Iterator and Enumeration Interface in Java

AmitDiwan
Updated on 24-Mar-2021 12:34:07

568 Views

In this post, we will understand the difference between iterator and enumeration interfaces in Java.IteratorIt is a universal cursor.It can be applied to all collection of classes.It contains the ‘remove’ method.It is not a legacy interface.It can be used to traverse over HashMap, LinkedList, ArrayList, HashSet, TreeMap, and TreeSet .It can perform modifications to perform operations on the collection while traversing through it.EnumerationIt is not a universal cursor.It is applied only to legacy classes.It doesn’t contain the ‘remove’ method.It is a legacy interface.This interface acts like a read-only interface.Hence, no modifications can be performed on a collection while traversing over ... Read More

Difference Between HashMap and TreeMap in Java

Pradeep Kumar
Updated on 29-Jul-2022 11:42:50

3K+ Views

Both HashMap and TreeMap are considered to be Map classes because they both carry out the responsibilities of the Map interface. A Map is an object that stores key-value pairs, in which there is only one instance of each key but there may be multiple instances of the value. The hash table is a type of data structure that is utilised by the HashMap class. As a form of data storage, the red-black tree is utilised by the TreeMap.What is a HashMap?A HashMap uses a data structure known as the hash table in order to store the map's key-value pair. ... Read More

Difference Between malloc and calloc

AmitDiwan
Updated on 24-Mar-2021 12:31:57

905 Views

In this post, we will understand the difference between malloc and calloc.MallocThe method ‘malloc’ is used to assign a block of memory when it is requested.It doesn’t clear the memory.It only initializes the allocated memory when explicitly requested.It allocates memory of a specific ‘size’.This size is passed as parameter to it.This size is allocated from a heap.It performs its job quickly.Examplevoid *malloc(size_t size);CallocIt assigns the requested memory to multiple blocks.This memory allocated is initiated to zero.This initialization to 0 is done by ‘calloc’ method.It allocates memory to the required operation of a specific ‘size’, i.e num * size.The ‘num’ refers ... Read More

Difference Between Stack and Queue

AmitDiwan
Updated on 24-Mar-2021 12:28:30

925 Views

In this post, we will understand the difference between Stack and Queue.StackThey are based on LIFO- Last In First Out.This means the element inserted at the end is the first element to get deleted.Insertion and deletion happen in a stack from one end only, i.e the top.Insert operation is known as ‘push’ operation.Delete operation is known as ‘pop’ operation.A pointer is used to access the list, it is known as ‘top’.The ‘top’ points to the last element of the list.It helps work with problems associated with recursion.Representation of Stack (LIFO)QueuesThey are based on FIFO- First In First Out.This means the ... Read More

C program to find the sum of arithmetic progression series

Bhanu Priya
Updated on 24-Mar-2021 12:55:26

2K+ Views

ProblemFind the sum of an arithmetic progression series, where the user has to enter first number, total number of elements and the common difference.SolutionArithmetic Progression (A.P.) is a series of numbers in which the difference of any two consecutive numbers is always the same. Here, total number of elements is mentioned as Tn.Sum of A.P. Series: Sn = n/2(2a + (n – 1) d) Tn term of A.P. Series: Tn = a + (n – 1) dAlgorithmRefer an algorithm given below to find the arithmetic progression.Step 1: Declare variables. Step 2: Initialize sum=0 Step 3: Enter first number of series ... Read More

Advertisements