Found 2617 Articles for Java

Merge a linked list into another linked list at alternate positions in Java

Sunidhi Bansal
Updated on 22-Oct-2021 10:00:39

489 Views

We are given two data structures as linked list Let’s say, List_1 and List_2. The task is to merge the elements of linked list ‘List_2’ into the linked list ‘List_1’ at an alternate position and if we are left with the elements which can't be merged into ‘List_1’ then it will be printed as the ‘List_2’ remaining elements.For Example-:In −List_1 =List_2 =Out − Merged List is-:Explanation − we are given with two lists i.e. List_1 and List_2. We had merged the possible elements of list_2 into List_1 at alternate positions. So, elements after merging in List_1 are 10- >3->2->1->1->4->2->5->5 and in List_2 are ... Read More

Difference Between Checked and Unchecked Exception in Java

AmitDiwan
Updated on 24-Mar-2021 13:17:47

12K+ Views

In this post, we will understand the difference between checked and unchecked exceptions in Java.Checked ExceptionsThey occur at compile time.The compiler checks for a checked exception.These exceptions can be handled at the compilation time.It is a sub-class of the exception class.The JVM requires that the exception be caught and handled.Example of Checked exception- ‘File Not Found Exception’Unchecked ExceptionsThese exceptions occur at runtime.The compiler doesn’t check for these kinds of exceptions.These kinds of exceptions can’t be caught or handled during compilation time.This is because the exceptions are generated due to the mistakes in the program.These are not a part of the ... Read More

Difference Between Interface and Abstract Class in Java & C#

AmitDiwan
Updated on 24-Mar-2021 13:13:43

467 Views

In this post, we will understand the difference between abstract class and interface in Java and C#.Abstract ClassIt contains the declaration and definition part.Multiple inheritance can’t be implemented using abstract class.It contains the constructor.It can also contain some static members.It can contain multiple types of access modifiers such as public, private, protected.The performance of an abstract class is very good, because it is quick.It is used to implement the core identity/functionality of a class.A class can use only one abstract class.If many implementations are same, and they have a common behaviour, it is suggested to use an abstract class.Abstract classes ... Read More

Difference Between Static and Final in Java

AmitDiwan
Updated on 24-Mar-2021 13:10:17

15K+ Views

In this post, we will understand the difference between ‘static’ and ‘final’ keywords in Java.StaticIt can be applied to nested static class, variables, methods and block.It is not required to initialize the static variable when it is declared.This variable can be re-initialized.It can access the static members of the class only.It can be called only by other static methods.Objects of static class can’t be created.Static class can only contain static members.It is used to initialize the static variables.FinalIt is a keyword.It is used to apply restrictions on classes, methods and variables.It can’t be inherited.It can’t be overridden.Final methods can’t be ... Read More

Difference Between Packages and Interfaces in Java

AmitDiwan
Updated on 24-Mar-2021 13:06:17

4K+ Views

In this post, we will understand the difference between packages and interfaces in Java.PackagesIt is a group of classes and/or interfaces that are together.It can be created using the "Package" keyword.It can be imported.It can be done using the "import" keyword.Examplepackage package_name; public class class_name {    .    (body of class)    . }InterfacesIt is a group of abstract methods and constants.It can be created using the "Interface" keyword.It can be extended by another interface.It can also be implemented by a class.It can be implemented using the ‘implement’ keyword.Exampleinterface interface_name { variable declaration; ... Read More

Difference Between extends and implements keywords in Java

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

1K+ 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

2K+ 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

796 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

418 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

2K+ 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

Advertisements