#1 - Java Collection Framework || Hierarchical Diagram - Very Important for Interview

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys this is naveen welcome back to naveen automation labs so guys today onwards i'm going to start one very important series in java that is java collection framework series it will be a long series because lot of things we have to cover and this time i'm planning to cover each and everything about java collection this chapter is very very important for interview point of view either you are an experienced person or a fresher that doesn't matter or if you are in college college and you're preparing for your college placement also very very important chapter so it will help you a lot to learn data structure and algorithm also later on if you really want to understand what is a time complexity what is algorithms what are different data structures sorting algorithms and all those things and if you really want to solve some really good questions on data structures and algorithm java collections plays a very important role over here okay so if you know java and if you really want to become expert in core java java collection framework is very very important to know okay but there are different things how to explain at a time of interview how to learn java framework collection framework properly let's talk about it today so guys what is the mean of java collection framework java collection framework provides a lot of interfaces lot of classes which are already inbuilt under jdk package under java and they provide various data structure implementation and already inbuilt algorithms also they will give it to you so we don't need to write those data structure and algorithm mechanism again and again let's see i really want to sort the data i really want to iterate the data so for that i don't want to write the program for that i don't want to write the logic for that i simply use these interfaces and the classes and the methods and the implementation i simply use it and solve my query and solve my purpose and the use case quickly let's say i want to store the data in the form of order base so in that case or dynamic data in that case i'll go for error list let's see i want to store my data in the form of key and value pair format in that case i'll go with the map interfaces or hash map like that so there is a specific hierarchy guys that we have to understand what are different interfaces and the collections are available in this particular java collection package okay now the first thing is that we have to understand the first interface which is the top interface that is called okay collection so this rectangle means okay i'm going to create as a interface so this is the interface the name of the interface is that remember this guys the top interface name is the collection interface so i'll write collection over here fine under this particular collection interface we have three sub interfaces are available so i would write this is the first one second one and let's see the third one okay so the first one is i'm going to create that is the set interface the second one is that i'm going to write the list interface and the third one is the q interface so i'm going to cover the most important one 100 people will ask you these kind of questions at a time of interview and these three interfaces they are okay extending this particular interface it means they are the child of collection interface remember this thing right so it's implement a collection to collection mapping it means they are extending a collection interface as a parent interface over here now then we talk about under set we have other classes are available so i'm going to create classes with a circle like that so class number one class number two and the class number three so these classes i quickly write so my first class is hash set over here and the second class is a linked headset so i'll write it over here it's a big name linked hedge set and the third one is the preset okay so let me write it over here preset over here so hash set is a directly implementing set interface and the linked hash set also is directly implementing set interface but between preset and the set interface there is one more interface guys so let me create one more interface over here that is called sorted test so remember this thing this is sorted sorted set and now this particular class is actually implementing this sort of set interface and this interface is extending set interface so remember whenever there is a parent interface set and this is the child interface we have to use extends keyword but whenever there is a class is is a child of a parent interface in that case we have to use implements keyword so this is implementing and this is extending remember this thing so for your reference let me just simply write this is called implementing i and this is called extending x over here class to class parent and child that is also called extends keyword and this is implements keyword remember this thing then let's talk about the list interface so under this particular list interface we have uh actually three important classes are available so let me quickly write so we have class will be with circle so at the same at a time of nw you can explain like this with the same diagram you can explain so let's see we have one error list then we have the vector and then we have linked list so uh let me quickly write these names so errorless we know that very popular we always use for dynamic arrays for dynamic collections in that case we will be using error list and then we will the second one is the vector which is like quite old collection and then we have the linked list that is also quite famous to provide a doubly linked list and to store the data on the basis of node and value so this is a linked list so don't worry we will cover each and every topic individually today i'm just going you going to give you the overview the pictorial view of all these collections interfaces and the respective classes then these errors this error list all these sub classes they are implementing list interface over here okay so linked list is also implementing this but linked list is remember one thing guys is also implementing q interface so this is the interview question people might ask you that linked list is implementing list as well as queue okay because it gives the implementation for the queue also and then we have another class for queue let me create another class that is called priority queue so remember this thing this is priority queue okay so priority queue is also available which is implementing queue interface simple like that so this is the main uh thing that you have to understand so collection is the main interface having three sub interfaces set list and queue set is having three classes preset is implementing a sorted set so set is the grand parent of a tree set class and then we have error list vector and linked list implementing list interface and then linked list is also implementing queue and then we have priority queue which is implementing queue interface like that okay so this is the part of collection interface guys okay we have another interface that is called map interface so that is different from this hierarchy it's not mapping map is not coming from the collection collection family okay not from this particular interface family we have a different family over here that is called map okay this is again one interface is available so i'll quickly write map interface this is also an interface which store the data in the form of key and value pair format so how to store the data how to write the code all those things guys we will do it later not now and then remember one thing there are four classes that you have to understand class number one class number two class number three and then class number four the four classes are available they provide the implementation of map interface with different features so let me quickly write their name the first name is that remember hash table okay hash table then we have linked hash map linked hash map i'll quickly write it over here like and then we have very popular that is hash map you must have already heard about it store the data in the form of key and value pair format and then we will see what is the difference between hash map and the hash a table in terms of synchronization in terms of thread safety in terms of null values and the null key very popular question difference between hash table and hash map and then we have one more class which is called tree map now all these three classes first three classes are implementing directly with map interface so linked hash map is also implementing hashmap also implementing map interface but again between these two guys tree map and map there is one more interface is called that is called sorted map so remember this thing this is sorted map that's why whatever the data that we are storing inside a tree map the data will be stored in the form of sorted order very popular for sorting point of view we can use this particular map over here so this is sorted map so if you know the proper definition you can easily learn guys you can easily solve multiple problems over here so uh sorted map is also an interface and this a tree map is actually uh doing what implementing this guy and ex sorted back is extending this guy so yeah so if we quickly write that which one is extending what this is also extending so i would write extending so you have to explain same thing at a time of interview list is also extending this guy collection interface and these three classes okay these three classes they are implementing so i will write i over here this is also implementing i and i'll write this is x over here this is extending because this is this is what this is extending this is interface to interface relationship then again this is i i would say this is again i implementation and this is again i i means implements linked list is implementing a queue interface and priority queue is implementing queue interface over here like that perfect and then hash table is also implementing a map interface this is also implementing map interface hash map is also implementing map interface sorted map is actually extending map interface and tree map is actually implementing sorted map over here now other than that you need to understand one more i would say uh class simple right let's see one object class is also there so i'll quickly write let's see and we will see we will talk about two more classes that is arrays and collections so we know that okay object is a superclass of all the classes in java but under that we have two classes i would say so object is a class so let me do one thing let me create a circle over here so we will talk about one more class that is object class and under this particular object class guys we have two more classes so let me quickly write for you guys so one is for object and then we will talk about arrays also so arrays is a separate class which is available in java and then we have one more class that is called collections class right collections class and then they are extending this particular object class over here as a okay they are the two child classes available under object class now the question is what is java collection framework guys this entire diagram that you see this entire family collection and the map they are called they combine them together if you combine them together that is called java collection framework so don't be confused between what is java collection framework and the collection interface collection technically point of view java point of view collection is just an interface over here right and map is a separate interface so some people they do mistake when they talk about that okay no collection is a collection framework no this entire thing is a collection framework which is they provide a lot of interfaces and their respective implemented classes and the respective extended interfaces are available so they provide certain features certain algorithms and certain data structures to solve some problems to store the data on the basis of a specific data structure and the algorithms right so this is this entire step is called collection framework that you need to understand and this is called this entire diagram is called what if somebody is asking you how will explain the java collection framework hierarchy so this is called java collection framework hierarchy over here like that let's quickly talk about one by one that let's pick this list interface so remember this thing guys when we are talking about the list interface list is an order based so i'll write some basic notes okay for you guys so let's talk about the first list interface over here so let me quickly write it over here let's see this is for list remember one thing that list means it's order based collection so i would write an order based collection okay it means it maintains the indexing so i would say index based also you can say that index based collection right for example error list error list for example linked list like that okay and it provides the dynamic implementation for the arrays so i would say these are dynamic arrays also so we have two types of array one is a static array where the size is fixed second one is a dynamic dynamic array where size will be increased automatically and when we have the small number of data then the size will be decreased automatically so this is the list okay we will talk more and more list each and every example we will see in upcoming chapters don't worry about that now second one is the set interface what is the site implementation from the set family what exactly these people they do said family there does couple of things first of all that different sets similar to the set in mathematics and remember one thing it cannot have duplicate values or duplicate elements remember a said in mathematics in our school time same thing over here that it cannot have duplicate elements over here okay this is the main property of then let's talk about the queue q means this one is also coming from the collection family this is again interface when we want to store and access the elements in first in first out order simple q means f i f o first in first out order in that case we will be using okay q interfaces okay so some string based question also can be solved by using queue like that and then yeah there are specific use cases we will talk about later the implementation and different examples how to write the code with queue and everything we will set it let's see it later then you back to this map interface as a as i as i told you that map is what is again interface and which will help you to store the data in the form of key and values pair format so i would write stores data into key and value pair format okay it's key and value pair format which is very important to know just like we have a hash map we have hash table and then we have linked hash map then we have concurrent hash map also and then tree map also for the sorted map we can simply do that okay then other than that guys we have to understand one more concept that is called iterator iterator means to iterate okay the to iterate the elements from a collection now this collection could be anything this collection could be a list also a map also a set also so whatever the element that you see and you really want to let's see from the set object or let's see from the map object which is not an order based set does not store the data on the basis of indexing so you cannot use a typical for loop in that case i have to apply an iterator over there you can apply a trader on list also so it later remember one thing this is another interface which provides the methods that can be used to access the elements of a particular collection different advantages why we are using collections guys okay it's very important people might ask you a time of interview that why why we are using we should know right so i would say that advantages the first point is that first of all it reduces your programming effort we don't need to write the same code again and again let's see if i say that i want to use error list i want to use a dynamic array so in that case i can directly use that i just need to create the object of error list i want to store the data let's see in the form of set objects so i can just use any of this particular set okay i can use it over here i can use hash set i can use preset on the basis of my requirement right but i'm not going to create one more errorless class and implementing all the methods and creating the method implementation for all the error list and vector no these method these classes are already available and i just need to use them and that's it so that's why we can reduce the programming effort we don't need to write that particular classes and those interfaces and the methods okay i just need to use them that's it provides first of all very important concept over here that provides inbuilt methods and classes which i can use according to my use cases so just because of this what will happen the performance it will be optimized okay their highly improved performance collections are there because it's already written already tested and then my code will be more and more optimized and highly perform okay i would say highly performance what else other than that that uh definitely if you are writing the code in and you're using these kind of utilities and these are the different collections you are using it definitely you will increase your productivity so development team definitely will increase the productivity all right it will reduce the operational time also operational time let's see two systems they can interact with each other if they are passing the collection from one system to another function so i would say inter operability they provide this particular feature also let's say two system they really want to interact in the form of apis i can i can give you let's see i'm returning you one hash map you can collect the same hashtag and use it for for your purpose so with the help of a collection i can simple do that that is another advantage with collections okay so remember these are the important points first of all that there are some common methods also guys that you have to understand we will be using these common methods in our upcoming chapters so quickly i'll write it over here for you guys that uh okay so we have some common methods which will return let's see we have add method we have add uh all method in collection okay these are the common methods are available in collection framework then we have a remove method then we have remove all method which is available then if you very common method we will be using a size method to get the size of the collection that how many elements are there then if you really want to clear the collection we can use clear method we will be using this and then we will be using contains function also that is also there okay contains and then contains all contains all function is also there so remove and then we will talk about let's see retain and retain so these are the 10 important methods okay other than that we have other methods also but these are the 10 important methods we will be seeing okay in collection so these are the very common method that every time you have to use it to add the method to to add the element to remove the element to get the size to clear the collection well i really want to check that okay in my hash map that contains uh that particular element contains or not right so we will do all these we will see all these methods with proper examples other than that one last topic over here that uh what are the different common exceptions the right days common exceptions that you will be getting it so common exceptions in connections so okay first of all that null pointer exception which is like everywhere whenever your object is none so and having null reference are having no reference and then a reference is pointing to a null in that case you will be getting the null pointer exception you might get class a cast exception also which is also common whenever you are timed okay trying to convert a down casting over there in that case you will be doing uh getting a class cast exception and then we will be having illegal argument exception if you are okay that is also common exception so we will take couple of exception examples people might ask you what are the different exceptions you will be seeing because these are the very common questions you will be seeing in your collection framework tell me four or five different exception names so illegal argument exception whenever you are invalid argument that you are going to pass in that case you will be getting illegal argument exception then we have illegal state exception also other than that uh you can have a unsupported operation exception also that is also quite common unsupported operation okay so you will get this particular message this particular exception when you have let's see it will come when collection cannot be modified i cannot modify that particular collection in that case you will be getting unsupported operation exception so remember uh these three plus two five exceptions in collection framework okay so these are the four important uh points different features advantages common methods common exceptions along with okay this particular hierarchy okay guys that's all for today that's all for this particular chapter and the next upcoming videos we'll be talking about each and every each and every method each and every uh you know uh class is variable so that's all for today guys so in the next in the next upcoming videos we will be seeing different classes their implementation and a different example different use cases we'll be seeing that but please remember this hierarchy take a printout and then please practice this particular hierarchy diagram exactly same thing you have to explain at the time of interview so thank you so much guys thanks for watching this particular video if you have any questions please put your question in the comment section and please like subscribe and share this particular video it will be really useful for your interview point of view thank you so much guys
Info
Channel: Naveen AutomationLabs
Views: 172,318
Rating: undefined out of 5
Keywords: Java Collections, collections in java, collection framework, list set map in java, Collection interface in java, collections by Naveen automationlabs, core java tutorials, naveen automationlabs, java collection tutorials, java collection interface and classes
Id: B4WmfcjQ9QA
Channel Id: undefined
Length: 23min 23sec (1403 seconds)
Published: Wed Oct 14 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.