imsavva.com

Folder icon

Tags / Java

What is a diamond operator?

This is an improvement appeared in Java 7. Consider you have a class with a long name and you need to create a HashMap of Strings and Lists of your class instances. You code will look like this: In Java 7 you can write less code using the diamond operator(< > ):
Posted on
2016-03-19

What data can be stored in a collection?

showPostImage(436047025)

Uncaught exception: the image was stolen by a UFO

You can store anything but primitives. To store primitives consider using wrappers (Integer for int, Double for double, etc…). For example, you can store your own classes: To store primitives: Notice, that you can add primitives, since it will be wrapped automatically:
Posted on
2016-03-19

What benefits does JCF provide?

showPostImage(-1054418192)

Uncaught exception: the image was stolen by a UFO

Java Collections Framework provides the following benefits: Reduces programming effort: you don’t need to invent the wheel anymore, JCF provides useful data structures and algorithms. Increases program speed and quality: JCF provides high-performance, high-quality implementations of useful data structures and…
Posted on
2016-03-19

Whas is a collection?

showPostImage(-1803150519)

Uncaught exception: the image was stolen by a UFO

Collection is an object that groups multiple elements into a single unit. Collections are used to store, retrieve and manipulate data. Live example: several Employee objects can be grouped into a collection: Java has a Java Collection Framework (JCF), which consists of: Interfaces - these are abstract data types that…
Posted on
2016-03-19

Java exceptions handling order

showPostImage(-1069492847)

Uncaught exception: the image is currently being shown in a museum

Consider there is a method which can throw IOException and FileNotFoundException. Is there a difference in which order we catch these exceptions in a single try-catch block? Will this code work correctly? The answer is NO. If you handle IOException first, you will never reach FileNotFoundException handling block…
Posted on
2016-03-19

Java Collections hierarchy

(Self-explanatory image above)
Posted on
2016-03-19

Describing the Java Set collection interface

showPostImage(300406476)

Uncaught exception: the image is currently being shown in a museum

A Set is a Collection that cannot contain duplicates. The Set interface extends Collection interface but has no specific methods. It adds the restriction that duplicates are prohibited. This interface also adds a stronger contract on the behavior of the equals and the hashcode methods, allowing Set instances to be…
Posted on
2016-03-19