Java Fundamentals: Fast Introduction | Alexandru Rosu | Skillshare

Playback Speed

  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Java Fundamentals: Fast Introduction

teacher avatar Alexandru Rosu, Technology matters

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

8 Lessons (31m)
    • 1. Introduction

    • 2. Collection interface

    • 3. List interface and implementations

    • 4. List examples

    • 5. Set interface and implementations

    • 6. Set examples

    • 7. Map interface and implementations

    • 8. Map examples

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class


Under the following sections I would like to present a short Introduction to Java Collections Framework.

New to this topic or just want to refresh your memory really quick on Java Collections? In this case this course is for you!

Under this class I will provide an initial overview of the main principles that should be known under a Java Interview preparation process in terms of Java Collections.

Will provide the overview of what we will discuss about:

  • List<E>

    • ArrayList<E>

    • LinkedList<E>

  • Set<E>

    • HashSet<E>

    • LinkedHashSet<E>

    • TreeSet<E>

  • Map<K,V>

    • HashMap<K,V>

    • LinkedHashMap<K,V>

    • TreeMap<K,V>

By following this class, students will be able to:

  • Gather knowledge on one of the most important topic in Java interviews - Collections
  • Get a better understanding on how to use a specific collection based on requirements
  • Gain info on the basics of Java Collections Framework

Meet Your Teacher

Teacher Profile Image

Alexandru Rosu

Technology matters



My name is Alex and I am happy to join skillshare as an teacher.

I have a bachelor degree in Computer Science and a Master Degree in Multi modal distributed virtual environments.

With a strong passion for programming, I enjoy finding solutions to various IT related problems.

My favorite programming language? I can tell you that it's Java, but I have also worked with other languages such as NodeJS, Angular, Typescript, Python, etc in my previous 10 years of experience.

Will be happy to share my knowledge and create great content for everybody who wants to join my classes.

Let's build awesome things together :)

See full profile

Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.


1. Introduction: Hi. Welcome to the Java collections, frame or presentation in the following sections. All present the main principles off this framework. Our collection can be seen as a type of structure that can group together objects. Each object that this present under collection can be identified as an element. The general collections is an extremely powerful, flexible frame or that is used to represent and manipulate collections. You can look at this framer as a set of interfaces that provides support for storing data environments four months and offers functionality such as sorting or that thing uniqueness off elements, etcetera, interfaces that will mention a sparked off. The scores are least set and map and also their corresponding concrete implemented classes . So let's start by looking at the base interface for the jar collections for a more that is the collection. 2. Collection interface: the collection interface presents the base support in starting in manipulating a list off objects under the job collections framework will not find the class that directly implements this interface. But instead this interface is extended by more particular interfaces with specific functionality list interface that keeps the order off. Inserting objects sip interface that allows only unique objects to be inserted under the group off objects Sort that set interface that allows only unique elements but also provides support for ordering the Collection Cube interface that acts similar talk You first in four stop de que interface that can be seen as both a cue for steam forced out and the stack lasting for stop. As you can see, the collection interface is generic in the way that it needs to define its own pere mentors . But was this these means It means that you can define a collection off specific objects that we want to manipulate shrink integer, long etcetera. But you can also define your custom objects such as partisan. There is also an important concept that we need to address the fact that the collection interface extends the terrible interface. Using the terrible interface we can either it over any collection that's being said since collection interface is the base awful collection interfaces and it extends, or so the terrible interface. That means that all concrete classes under the collections framework will be able to use the operator to iterating over its elements. Collection Interface provides the group off corresponding metals that can be used in the actual concrete implementation classes for various purposes. Will is the most popular methods that are used frequently. Add in certain element into the collection at the in certain specified collection. In the evoking collection Clear used to remove or elements from a collection. Remove. Remove one element from the collection equals checks for equality contents searches for a element in the collection. Sighs returns the number off elements in the collection and the last but not least is empty . Verifies if the collection is empty before moving to the collection workflow and discuss about different interfaces in concrete class implementations. We need to know that the collection interface is not sing cries. That means that all its extended interfaces and actual class implementations will not work properly under a multi treaded environment. Now there's going to detail and discuss about one of the most popular interface that extends collection aimed at least 3. List interface and implementations: hissed interface, extends the collection interface and has the main characteristic death. It retains the order off insurgent for its objects and can also store duplicate elements under released. You can control the position where you want to store a new element. Due to this reason, we can find specific methods that apply to this interface. We list a few ad at Element E At position index in the list collection, get 33. The element from the collection that can be found that position index remove. Remove the element from the list that is found that position especially fight by the index . There are also other methods that will present under the following video as called examples . In terms off concrete class implementations will focus on two main classes or a list, and the LICH list or a wrist represents one off the most used type of collection. This type of collection is backed by an IRA has its base structure constructed by using ordinary. This being said once you initializing or a lease is dimension will have the initial capacity off 10 elements. You can add elements to the Israelis and if, for example, the least is full It has the initial capacity for off 10 elements and the one toward another element. The raid that is used behind the scenes will increase in size with another 50% off the current or a capacity no for a link list. Please know that this type of structure implements the least interface, but also interfaces such askew and dick You double in the Cube in this way will get by default of functionality off keeping the order off elements by its index from least interface, but also will inherit the principles from Q and Dick you By following this, concepts are linked. List can be used in places where they want to simulate the principal off leaf or last in first out and also fearful for steam for stopped. So now one exactly. We should use an array list versus a linked list. Honore list can be used in situations where we need fast iteration over collection. Whether a link list is better on adding or removing elements from the collection in terms off for four months, there are some facts that we can review. Honore List offers oh, off one complexity for adding searching for elements and off end for the moving elements from the collection. In the other case, a link, Lis offers off one for searching, removing elements and off one arm Ortiz, it value for adding elements. 4. List examples: Let's look on some simple examples off his internalised interface under Java. So under our job collections project least package, we can identify, pray different example classes under the released example. One. We can identify a public static void method and also a main constructor. You can see that we're instance, eating on a released off strings. We can use both of our A list, but also the least interface to create this list. Let's use the least interprets. I'm adding free names under the list, and you can see that we're allowed toe add duplicate that values. We have the ability to list the number of elements in the list using the size metal. We can also removal value from the list, using the remove method that, behind the scenes uses the equals method to check. If that value is present in the list, we can also set a value in the least at the specified position. We can check if our value is present in the list using the contents method. Last but not least, let's literate over the list is in Garnett aerator. We can run the application. You can see the results initially. Size was free list contains the Jack Element. And since we really move one entry from the list, we have two names left. Joan and Jack. Let's move to the second example. We will see the equals metal importance for custom implemented object. So under the constructor, we can identify the fact that we're creating a list of persons. This is a custom implemented object. Let's take a look on his structure. It has a first name, a last name. Also constructor. The equals method is commented out. Now let's add two persons in the list. We'll check if seven or more Alice is presenting the least using both the contents. An index off method. Since the person object does not have a properly implemented equals method, the equals method from the object last will be used, and this will check mainly if two objects are identical in terms off there. Reference value. In order to fix this, we need to remove the comments from the equals method on the person class. So let's do this. We're removing the comments from the equals method. Let's save every around the application. Once again, you can see that Sabrina more Alice is present in the least, and we were also able to find the position of the person object in the list. Let's move to the final example. Over here, you can see that we are creating a link list under the link list. Example. One constructor. This link list has the integer type. We're adding free. We have the ability at an integer at the beginning off the list and also add an integer. At the end of the least. We can simulate a stack process using the push method and also que process using the offer method. Let's also literate over the link list. You will see the elements in order from 1 to 7. 5. Set interface and implementations: a set interface presence on our norther collection off elements objects in which duplicated values cannot be stored in order to determine the quality off objects. The equals method is to be used and properly overridden. For custom implemented objects. There are free main concrete classes that diplomat those set interface those are have set her set entry set in the following sections will discuss each one of them in more detail, has said, is a common structure that is used to start unique elements in a collection. However, we should keep in mind that this collection type does not guarantee the order of inserting data. For example, suppose we have ah Hassett of integers, and we need to insert the falling values into it. 12345 If you want to enter it on the hassle at a later point, we can't guarantee that we received the same order off the elements as who used to insert them. Unimportant aspect to be aware of is that in addition from a list where we use the equals metal toe very far, elements for equality has that uses also the hash code method. So let's introduce this Freeman concepts that are important for a has said buckets are places where we're store objects, hash code and equal Smith. Imagine that we now want to store some persons under a hassett, each person having a first name and the last name whenever we need to insert on your object under A has said. The first thing is that the corresponding hash coat value for that object is calculated based on the hash code. Value will search on the corresponding bucket. If we were able to find the bucket we now need to find out if we are able toe, add the object into the collection or not, since if you recall has set allows only unique values to be in separate at this moment, we need to introduce the equals methods, such as we can identify if object is already present in the collection or not. If it's not present, were introduced. A new object into the has set. Once again, a more detailed example will be presented under coding exercise. Darling has set uses the same principles as ah has set uses, but in a combination with a link list. This being said, we have the possibility to retrieve objects in the same order that we inserted them. This collection type can be used when we want to store unique objects and want to retrieve them in the same order as we inserted them. But Reset, on the other hand, is capable of storing unique elements in a sorted order. The sorting mechanistic can be created using two ways. Natural order or just on the three set collections will implement the comparable interface or using a specific operator if neither off these two ways off sorting garden use. Basically, if we don't specify a sorting way for the three set we receive or random exception on adding the first element to the collection, there is a specific difference between a three set and the other concrete classes that implement the set interface has said anything has said, while there later too, are using the equals method to check objects for equality. Three set uses the compared to matters from the comparable interface or the compare metal from the comp aerator interface, depending on which type off sorting will be used, we will identify these cases while we will present this collection under according example , if we want to focus on for four months. Ah has said anything has said overs, constant time for four months for adding searching, any moving elements, whether three set off words log and time for four months due to the fact that this type of collection is based on a tree to store it elements. 6. Set examples: Under this section, we'll see some examples of using the set interface. So we have a set package with four different example classes, and we're never get forced toe. The initial class has said. Example. One, This class has a main method and also constructor, where will set up a new has set off car objects. Please keep in mind that since this is ah, her set or cars should be unique. Your card is defined by a model on here. It has a constructor, but to stick method, and both the hash coat and equals method are currently commented. Out initially will add free cards under the Hassett. What we want now is to remove that common and at the four car into the Hassett, even if that car, it's the same in terms of the structure as the second value added to the Hassett for ality as a final step, we can literate over the half set using the 40 Method. You can see it that currently we have four cars in the passage. This is actually wrong. Since we have the hour, the corresponding card twice. We can fix this by removing the comments from the hash code and the equals method on the car class soldiers to this. Now the hash coat and I course method from the car class will be used and we were only have free cards added into the hassett. The hash coat nd calls method will not be used from the main object class. We can now move to the second example this first clean up the console. We have a main method, a public constructor, and we're creating initially a normal early list. You think integer values in a corresponding order from 1 to 7. We want to take this list the intercourse list and added as a perimeter toe the link has set in. This way will have ordering for the link has set. You can see that we're able to eat a rate data in the corresponding order similar to the integers list. Let's move to a three set example under the class constructor world. Great. A new tree set off in tigers. Now we'll add free tigers under the tree set and we will illiterate over the to set using the forage mental. You would see that the values will be ordered due to the fact that we use the integer as a type off the tree set. This is happening due to the fact that the dagger implements comparable interface well, clearly the council and moved to the less example over the street set. Example to you can see that we're creating a new tree set off pet objects. This is a custom implemented object that has named type and age fields corresponding getter and setter methods. Ah, constructor and also the to seeing method well at now free pets under the three set corresponding collection as a final step will deter it over the tree set using the forage method says that is a constant implement that object. We need the sorting mechanism for our tree. Sit for these will use a comparator toe. Compare our pets based on the age. So we received the pet with H 58 and 10 in this corresponding order 7. Map interface and implementations: map interface has different particularities from the least and set interfaces. The first thing to note is that the map interface does not extend the collection interface , so it will nothing hurt its corresponding methods. The next important aspect is that a map is capable of starting key value pairs, with each key being unique in the collection. Also, please know that items that that added to a map are not ordered will present the following map implementations hash map link Hash map entry map. The hash map can be seen as a con, creepy implementation of ah hash based map that uses the hash value generator from its key to save and also retrieve key value pairs under the collection. Similar Toe has said that I inserted into a hash map is not order. If you recall, we have seen the contains method use for both least and set interfaces. This is not the place for a map we have in place metals such as content, ski and contains value that check or the existence of a key or appropriate value under the hash map method. Kandinsky uses both hash coat and equals to determine the quality off objects whether contains value uses only the equals method. That is an important concept we need to discuss about related toe, adding duplicate keys in case we want to start duplicate keys, such as we have on existing key in the map with our value and want toe add the same key with a new value. The couldn't key value will be over, even unlike a hash map. Pulling hash map follows the concepts defined under the hash map, but it also capable off keeping on inception order. Similar tolling has set, but three map is a complete implementation for the map interface that offers also sorting functionality. The sorting is made on the keys off the collection, using the natural ordering off the keys. Order Comparator interest for four months. Ah, hash map and leek hash map have off one for insurgent and look of processes. Whether the three map has oh off Logan for its operation at its is based on a tree structure behind the scenes 8. Map examples: Let's look on some quick examples of using the map interface under job. So under Java Collections project, we have a map package with three different classes will open the first class, and you can see that under the constructor will create a new hash map with integer as keys and employees as values, but can now look on the employee objects structure. It has a first name, last name salary. Also constructor the equals metal. It's commented up, and it also has a two string metal. I added a bunch of data under the hash map. In no particular order, we can illiterate over the hash map using the 40 each corresponding Met by is in the contains key will identify if he's present in the hash map or not using the contains value , we can check it for values present in the map. We have the ability toe ad booking the map, and if that Keyes present, the corresponding value will be overridden. Let's run the probe. U K C. The alteration off the map hash map contains key with corresponding value for its true and for the contains employees. Hardly green. We received false. This is happening due to the fact that the employee object is to override the equals method . Let's fix the issue for the employees object and remove the comments from the equals method so that will not rely on the object equals method that is used by default to check if two employees are identical or not, this will fix our issue. Now you can see that the issue is fixed. Let's move to the second example. Over here we have a link. Hashmat, will you string for the key and string for the value with add some sample data over here? We can deter it over the ling hash map, and the keys will be order in the same order as we used to insert the daytime toe the bling . Hashmat. We also have the ability to replace a key and also put a key. If it's not present in darling. Hashmat last, but not least, will enter it over the link. Hashmat. Let's run the application. You can see the four situation contains the same order as we used to insert data. We were able to also replace a value and add a new key in the link hash map. Let's move to the final example. Under this class, we have a three mapping stance. See, ation string will be used for the keys and the list of integers will be use for values. I'm adding some sample data that we can play with. Now we are able to eat or it over the to remap. We can retrieve the four ski the Lasky, as the next step will create the new tree map. Greater new comparator that will be used to reverse the order off the keys. Order off string, please. As a final step will illiterate over the new tree map mostly the results. As the first iteration the string corresponding ordering will be used. We are able to extract the first key Also Dyleski as a second iteration, you see that the reverse order is usedto retrieve data.