Vous êtes sur la page 1sur 69

NoSQL, which stand for "not only SQL," is an alternative to traditional relational databases in

which data is placed in tables and data schema is carefully designed before the database is
built. NoSQLdatabases are especially useful for working with large sets of distributed data.

What is NoSQL?
NoSQL encompasses a wide variety of different database technologies that were
developed in response to the demands presented in building modern applications:

 Developers are working with applications that create massive volumes of new,
rapidly changing data types — structured, semi-structured, unstructured and
polymorphic data.

 Long gone is the twelve-to-eighteen month waterfall development cycle. Now


small teams work in agile sprints, iterating quickly and pushing code every week
or two, some even multiple times every day.

 Applications that once served a finite audience are now delivered as services
that must be always-on, accessible from many different devices and scaled
globally to millions of users.

 Organizations are now turning to scale-out architectures using open source


software, commodity servers and cloud computing instead of large monolithic
servers and storage infrastructure.

Relational databases were not designed to cope with the scale and agility challenges
that face modern applications, nor were they built to take advantage of the commodity
storage and processing power available today.

NoSQL Database Types


 Document databases pair each key with a complex data structure known as a
document. Documents can contain many different key-value pairs, or key-array
pairs, or even nested documents.

 Graph stores are used to store information about networks of data, such as
social connections. Graph stores include Neo4J and Giraph.
 Key-value stores are the simplest NoSQL databases. Every single item in the
database is stored as an attribute name (or 'key'), together with its value.
Examples of key-value stores are Riak and Berkeley DB. Some key-value stores,
such as Redis, allow each value to have a type, such as 'integer', which adds
functionality.

 Wide-column stores such as Cassandra and HBase are optimized for queries
over large datasets, and store columns of data together, instead of rows.

The Benefits of NoSQL


When compared to relational databases, NoSQL databases are more scalable and
provide superior performance, and their data model addresses several issues that the
relational model is not designed to address:

 Large volumes of rapidly changing structured, semi-structured, and unstructured


data

 Agile sprints, quick schema iteration, and frequent code pushes

 Object-oriented programming that is easy to use and flexible

 Geographically distributed scale-out architecture instead of expensive, monolithic


architecture

 NoSQL databases are built to allow the insertion of data without a predefined
schema. That makes it easy to make significant application changes in real-time,
without worrying about service interruptions – which means development is
faster, code integration is more reliable, and less database administrator time is
needed. Developers have typically had to add application-side code to enforce
data quality controls, such as mandating the presence of specific fields, data
types or permissible values. More sophisticated NoSQL databases allow
validation rules to be applied within the database, allowing users to enforce
governance across data, while maintaining the agility benefits of a dynamic
schema.

 Auto-sharding
 Because of the way they are structured, relational databases usually scale
vertically – a single server has to host the entire database to ensure acceptable
performance for cross- table joins and transactions. This gets expensive quickly,
places limits on scale, and creates a relatively small number of failure points for
database infrastructure. The solution to support rapidly growing applications is to
scale horizontally, by adding servers instead of concentrating more capacity in a
single server.

 'Sharding' a database across many server instances can be achieved with SQL
databases, but usually is accomplished through SANs and other complex
arrangements for making hardware act as a single server. Because the database
does not provide this ability natively, development teams take on the work of
deploying multiple relational databases across a number of machines. Data is
stored in each database instance autonomously. Application code is developed
to distribute the data, distribute queries, and aggregate the results of data across
all of the database instances. Additional code must be developed to handle
resource failures, to perform joins across the different databases, for data
rebalancing, replication, and other requirements. Furthermore, many benefits of
the relational database, such as transactional integrity, are compromised or
eliminated when employing manual sharding.

 NoSQL databases, on the other hand, usually support auto-sharding, meaning


that they natively and automatically spread data across an arbitrary number of
servers, without requiring the application to even be aware of the composition of
the server pool. Data and query load are automatically balanced across servers,
and when a server goes down, it can be quickly and transparently replaced with
no application disruption.

 Cloud computing makes this significantly easier, with providers such as Amazon
Web Services providing virtually unlimited capacity on demand, and taking care
of all the necessary infrastructure administration tasks. Developers no longer
need to construct complex, expensive platforms to support their applications, and
can concentrate on writing application code. Commodity servers can provide the
same processing and storage capabilities as a single high-end server for a
fraction of the price.
 Replication
 Most NoSQL databases also support automatic database replication to maintain
availability in the event of outages or planned maintenance events. More
sophisticated NoSQL databases are fully self-healing, offering automated failover
and recovery, as well as the ability to distribute the database across multiple
geographic regions to withstand regional failures and enable data localization.
Unlike relational databases, NoSQL databases generally have no requirement for
separate applications or expensive add-ons to implement replication.

 Integrated Caching
 A number of products provide a caching tier for SQL database systems. These
systems can improve read performance substantially, but they do not improve
write performance, and they add operational complexity to system deployments.
If your application is dominated by reads then a distributed cache could be
considered, but if your application has just a modest write volume, then a
distributed cache may not improve the overall experience of your end users, and
will add complexity in managing cache invalidation.

 Many NoSQL database technologies have excellent integrated caching


capabilities, keeping frequently-used data in system memory as much as
possible and removing the need for a separate caching layer. Some NoSQL
databases also offer fully managed, integrated in-memory database
management layer for workloads demanding the highest throughput and lowest
latency.

 NoSQL vs. SQL Summary


SQL Databases NoSQL Databases

Types One type (SQL database) with minor Many different types including key-value
stores, document databases, wide-column
variations stores, and graph databases

Development Developed in 1970s to deal with first Developed in late 2000s to deal with
History wave of data storage applications limitations of SQL databases, especially
scalability, multi-structured data, geo-
distribution and agile development sprints

Examples MySQL, Postgres, Microsoft SQL Server, MongoDB, Cassandra, HBase, Neo4j
Oracle Database

Data Storage Individual records (e.g., 'employees') Varies based on database type. For
Model are stored as rows in tables, with each example, key-value stores function similarly
column storing a specific piece of data to SQL databases, but have only two
about that record (e.g., 'manager,' 'date columns ('key' and 'value'), with more
hired,' etc.), much like a spreadsheet. complex information sometimes stored as
Related data is stored in separate BLOBs within the 'value' columns.
tables, and then joined together when Document databases do away with the
more complex queries are executed. table-and-row model altogether, storing all
For example, 'offices' might be stored in relevant data together in single 'document'
one table, and 'employees' in another. in JSON, XML, or another format, which can
When a user wants to find the work nest values hierarchically.
address of an employee, the database
engine joins the 'employee' and 'office'
tables together to get all the
information necessary.

Schemas Structure and data types are fixed in Typically dynamic, with some enforcing data
advance. To store information about a validation rules. Applications can add new
new data item, the entire database fields on the fly, and unlike SQL table rows,
must be altered, during which time the dissimilar data can be stored together as
necessary. For some databases (e.g., wide-
database must be taken offline. column stores), it is somewhat more
challenging to add new fields dynamically.

Scaling Vertically, meaning a single server must Horizontally, meaning that to add capacity,
be made increasingly powerful in order a database administrator can simply add
to deal with increased demand. It is more commodity servers or cloud instances.
possible to spread SQL databases over The database automatically spreads data
many servers, but significant additional across servers as necessary.
engineering is generally required, and
core relational features such as JOINs,
referential integrity and transactions
are typically lost.

Development Mix of open-source (e.g., Postgres, Open-source


Model MySQL) and closed source (e.g., Oracle
Database)

Supports Yes Mostly no. MongoDB 4.0 and beyond


multi-record support multi-document ACID
ACID transactions. Learn more
transactions

Data Specific language using Select, Insert, Through object-oriented APIs


Manipulation and Update statements, e.g. SELECT
fields FROM table WHERE…

Consistency Can be configured for strong Depends on product. Some provide strong
consistency consistency (e.g., MongoDB, with tunable
consistency for reads) whereas others offer
eventual consistency (e.g., Cassandra).

The Java collections framework (JCF) is a set of classes and interfaces that implement
commonly reusable collection data structures. Although referred to as a framework, it works in
a manner of a library. The JCF provides both interfaces that define various collections and
classes that implement them.
The Java collections framework gives the programmer access to prepackaged data structures
as well as to algorithms for manipulating them. A collection is an object that can hold
references to other objects. The collection interfaces declare the operations that can be
performed on each type of collection..
Basically the default implementation of hashCode() provided by Object is derived by mapping
the memory address to an integer value. ... However it is possible to override the hashCode
method in your implementation class. equals() This particular method is used to make equal
comparison between two objects.
1) If two Objects are equal according to equal(), then calling the hashcode method on each of
those two objects should produce same hashcode. 2) It is not required that if two objects are
unequal according to the equal(), then calling the hashcodemethod on each of the two
objects must produce distinct values.
HashMap maintains an array of buckets. Each bucket is a linkedlist of key value pairs
encapsulated as Entry objects. This array of buckets is called table. Each node of the linked list
is an instance of a private class called Entry.
There are four things we should know about before going into internals of how
HashMap works -

 HashMap works on the principal of hashing.


 Map.Entry interface - This interface gives a map entry (key-value pair).
HashMap in Java stores both key and value object, in bucket, as Entry object
which implements this nested interface Map.Entry.
 hashCode() -HashMap provides put(key, value) for storing and get(key)
method forretrieving Values from HashMap. When put() method is used to
store (Key, Value) pair, HashMap implementation calls hashcode on Key
object to calculate a hash that is used to find a bucket where Entry object will
be stored. When get() method is used to retrieve value, again key object is used
to calculate a hash which is used then to find a bucket where that particular key
is stored.
 equals() - equals() method is used to compare objects for equality. In
case of HashMap key object is used for comparison, also using equals() method
Map knows how to handle hashing collision (hashing collision means more
than one key having the same hash value, thus assigned to the same bucket. In
that case objects are stored in a linked list.
Where hashCode method helps in finding the bucket where that key is stored,
equals method helps in finding the right key as there may be more than one
key-value pair stored in a single bucket.

HashMap changes in Java 8


Though HashMap implementation provides constant time performance O(1) for get()
and put() method but that is in the ideal case when the Hash function distributes the
objects evenly among the buckets.
But the performance may worsen in the case hashCode() used is not proper and there
are lots of hash collisions. As we know now that in case of hash collision entry objects
are stored as a node in a linked-list and equals() method is used to compare keys. That
comparison to find the correct key with in a linked-list is a linear operation so in a worst
case scenario the complexity becomes O(n).
To address this issue in Java 8 hash elements use balanced trees instead of linked lists
after a certain threshold is reached. Which means HashMap starts with storing Entry
objects in linked list but after the number of items in a hash becomes larger than a
certain threshold, the hash will change from using a linked list to a balanced tree, this
will improve the worst case performance from O(n) to O(log n).
Hash Map internally implements the interface Map<K,V> where K stands for Key and V
stands for Value. The data is stored in an inner class Entry<K,V> which is a simple Key-
Value pair. And this has two extra data, a reference to another Entry so that Hash Map
can store the entries like a Linked List. And a hash value of the Key, which is stored to
avoid the computation of hash every time.

This is how Entry is implemented


1. static class Entry<K,V> implements Map.Entry<K,V> {
2. final K key;
3. V value;
4. Entry<K,V> next;
5. int hash;
6. …
7. }
HashMap stores the data into multiple singly linked lists of entries, also called buckets.
All lists are registered in an array of Entry, whose default capacity is 16 as below.

All keys with the same hash value, are put in the same bucket, as also keys with different
hash key values.
1. Map<String, String> countries=new HashMap<String,String>();
2.
3. countries.put("India", "New Delhi");
4. countries.put("US", "Washington DC");
5. countries.put("Russia", "Moscow");
6. countries.put("China", "Beijing");
7.
8. String capital=countries.get("India");
Now in the above code, when you call the put(K key, V value) or get(Object key), here
the function computes the index of the bucket where the Entry should be. And then it
iterates through the list to look for the Entry, that has the same Key using the equals()
method. In case of put(K, V), if there is already an existing entry it is replaced, else a
new Entry is created.

The index of the bucket is generated, as follows

1. Get the hashcode of the key.


2. Rehashes the hashcode, to prevent a bad hashing function.
3. Takes the rehashed hash code and bit masks it with array.length-1. This
ensures, that the index can never be greater than array size.
Auto Resize

Since the function( get, put or remove) has to keep iterating the linked List to see if there
is an associated entry, this could result in a performance issue. Imagine having to store
around a 1000 values. So this could mean each linked list would have around 63 entries(
1000/16), which makes it 63 iterations for every put, get or remove operation. To
overcome this performance bottleneck, HashMap can increase the size of it’s inner array
to accommodate linked lists.

When we create a HashMap, it’s default initial capacity is 16 and load Factor is 0.75. The
initial capacity here is size of inner array of linked lists. Now every time you add a new
value with put, the function stores 2 data, size of map which gets updated every time you
add or remove an Entry, and another one is threshold, which is capacity of inner
array*load factor, and this keeps getting refreshed for every entry. Now when a new
Entry is added, it checks size> threshold, and if yes, creates a new array with a doubled
size. So resizing here creates twice the number of existing buckets, and redistributes all
the existing entries.

Hashmap is used mainly to store key-value pairs.

The purpose of a map is to store items based on a key that can be used to
retrieve/delete the item at a later point. Similar functionality can only be achieved with
a list in the limited case where the key happens to be the position in the list.

When you add items to a HashMap, you are not guaranteed to retrieve the items in
the same order you put them in.

Basically hashmap is composed of hashmap bucket (1 hashtable ), each of the


buckets pointing to its own Linked List of entries nodes. So when one tries to insert a
new key-value Object pair into a hashmap (using put() method in java) the key-Object’s
own function hashcode() is used to calculate the correct bucket to insert such pair.

Q: Pros/Cons of Hashmap , in difference between HashTable vs HashMap ?

Hashtable is synchronized, whereas HashMap is not.


Hashtable does not allow null keys or values. HashMap allows one null key and any
number of null values.
One of HashMaps subclasses is LinkedHashMap, so in the event that you’d want
predictable iteration order (which is insertion order by default), you could easily swap
out the HashMap for a LinkedHashMap. This wouldn't be as easy if you were using
Hashtable.

hashCode() - HashMap provides put(key, value) for storing and get(key) method for
retrieving values from HashMap. When put() method is used to store (Key, Value)
pair, HashMap implementation calls hashcode on Key object to calculate a hash that is
used to find a bucket where Entry object will be stored.

he Map Interface. A Map is an object that maps keys to values. A map cannot contain
duplicate keys: Each key can map to at most one value. ... The Javaplatform contains
three general-purpose Map implementations: HashMap , TreeMap , and
LinkedHashMap .

Threads in Java. The base means for concurrency are is the java.lang.Threads class.
A Thread executes an object of type java.lang.Runnable . Runnable is an interface with
defines the run() method. This method is called by the Thread object and contains the
work which should be done..

Concurrency is the ability of a database to allow multiple users to affect multiple


transactions. This is one of the main properties that separates a database from other
forms of data storage like spreadsheets. The ability to offer concurrency is unique to
databases.

he Java programming language and the Java virtual machine (JVM) have been
designed to support concurrent programming, and all execution takes place in the
context of threads. ... The programmer must ensure read and write access to objects is
properly coordinated (or "synchronized") between threads.

Most of the executor implementations in java.util.concurrent use thread pools, which


consist of worker threads. This kind of thread exists separately from the Runnable and
Callable tasks it executes and is often used to execute multiple tasks. ... One common
type of thread pool is the fixed thread pool.

The Executor framework is an abstraction layer over the actual implementation of java
multithreading. It is the first concurrent utility framework in java and used for
standardizing invocation, scheduling, execution and control of asynchronous tasks in
parallel threads.

The Callable interface is similar to Runnable , in that both are designed for classes
whose instances are potentially executed by another thread. A Runnable , however,
does not return a result and cannot throw a checked exception.

If you just invoke run() directly, it's executed on the calling thread, just like any
othermethod call. Thread.start() is required to actually create a new thread so that the
runnable's run method is executed in parallel. The difference is that Thread.start()
starts a thread, while Runnable.run() just calls a method.
java.lang.Thread class provides the join() method which allows one thread to waituntil
another thread completes its execution. If t is a Thread object whose thread is currently
executing, then t.join(); it causes the current thread to pause its execution until thread it
join completes its execution.

Java - Thread Synchronization. ... So there is a need to synchronize the action of


multiple threads and make sure that only one thread can access the resource at a given
point in time. This is implemented using a concept called monitors. Each object in Java
is associated with a monitor, which a thread can lock or unlock.

To protect your code against this, create a private "lock" object, instance or static,
and synchronize on that object instead. At run time every class has an instance of a
Class object. That is the object that is locked on by static synchronized methods.
(Any synchronized method or block has to lock on some object.)

However, since the synchronization is at the object level, 2 threads running different
instances of the object will not be synchronized. If we have a static variable in
a Java class that is called by the method, we would like it to besynchronized across
instances of the class.

Static variables are indeed shared between threads, but the changes made in
one thread may not be visible to another thread immediately, making it seem like there
are two copies of the variable. ... Memory writes that happen in one threadcan "leak
through" and be seen by another thread, but this is by no means guaranteed.

1. What is the difference between Process and


Thread?
A process is a self contained execution environment and it can be seen as a
program or application whereas Thread is a single task of execution within the
process. Java runtime environment runs as a single process which contains
different classes and programs as processes. Thread can be called lightweight
process. Thread requires less resources to create and exists in the process,
thread shares the process resources.

2. What are the benefits of multi-threaded


programming?
In Multi-Threaded programming, multiple threads are executing concurrently that
improves the performance because CPU is not idle incase some thread is waiting
to get some resources. Multiple threads share the heap memory, so it’s good to
create multiple threads to execute some task rather than creating multiple
processes. For example, Servlets are better in performance than CGI because
Servlet support multi-threading but CGI doesn’t.
3. What is difference between user Thread and
daemon Thread?
When we create a Thread in java program, it’s known as user thread. A daemon
thread runs in background and doesn’t prevent JVM from terminating. When there
are no user threads running, JVM shutdown the program and quits. A child thread
created from daemon thread is also a daemon thread.

4. How can we create a Thread in Java?


There are two ways to create Thread in Java – first by implementing Runnable
interface and then creating a Thread object from it and second is to extend the
Thread Class. Read this post to learn more about creating threads in java.

5. What are different states in lifecycle of Thread?


When we create a Thread in java program, its state is New. Then we start the
thread that change it’s state to Runnable. Thread Scheduler is responsible to
allocate CPU to threads in Runnable thread pool and change their state to
Running. Other Thread states are Waiting, Blocked and Dead. Read this post to
learn more about life cycle of thread.

6. Can we call run() method of a Thread class?


Yes, we can call run() method of a Thread class but then it will behave like a
normal method. To actually execute it in a Thread, we need to start it
using Thread.start() method.

7. How can we pause the execution of a Thread for


specific time?
We can use Thread class sleep() method to pause the execution of Thread for
certain time. Note that this will not stop the processing of thread for specific time,
once the thread awake from sleep, it’s state gets changed to runnable and based
on thread scheduling, it gets executed.

8. What do you understand about Thread Priority?


Every thread has a priority, usually higher priority thread gets precedence in
execution but it depends on Thread Scheduler implementation that is OS
dependent. We can specify the priority of thread but it doesn’t guarantee that
higher priority thread will get executed before lower priority thread. Thread priority
is an int whose value varies from 1 to 10 where 1 is the lowest priority thread and
10 is the highest priority thread.

9. What is Thread Scheduler and Time Slicing?


Thread Scheduler is the Operating System service that allocates the CPU time to
the available runnable threads. Once we create and start a thread, it’s execution
depends on the implementation of Thread Scheduler. Time Slicing is the process
to divide the available CPU time to the available runnable threads. Allocation of
CPU time to threads can be based on thread priority or the thread waiting for
longer time will get more priority in getting CPU time. Thread scheduling can’t be
controlled by java, so it’s always better to control it from application itself.

10. What is context-switching in multi-threading?


Context Switching is the process of storing and restoring of CPU state so that
Thread execution can be resumed from the same point at a later point of time.
Context Switching is the essential feature for multitasking operating system and
support for multi-threaded environment.

11. How can we make sure main() is the last


thread to finish in Java Program?
We can use Thread join() method to make sure all the threads created by the
program is dead before finishing the main function. Here is an article about Thread
join method.

12. How does thread communicate with each


other?
When threads share resources, communication between Threads is important to
coordinate their efforts. Object class wait(), notify() and notifyAll() methods allows
threads to communicate about the lock status of a resource. Check this post to
learn more about thread wait, notify and notifyAll.

13. Why thread communication methods wait(),


notify() and notifyAll() are in Object class?
In Java every Object has a monitor and wait, notify methods are used to wait for
the Object monitor or to notify other threads that Object monitor is free now. There
is no monitor on threads in java and synchronization can be used with any Object,
that’s why it’s part of Object class so that every class in java has these essential
methods for inter thread communication.

14. Why wait(), notify() and notifyAll() methods


have to be called from synchronized method or
block?
When a Thread calls wait() on any Object, it must have the monitor on the Object
that it will leave and goes in wait state until any other thread call notify() on this
Object. Similarly when a thread calls notify() on any Object, it leaves the monitor
on the Object and other waiting threads can get the monitor on the Object. Since
all these methods require Thread to have the Object monitor, that can be achieved
only by synchronization, they need to be called from synchronized method or
block.

15. Why Thread sleep() and yield() methods are


static?
Thread sleep() and yield() methods work on the currently executing thread. So
there is no point in invoking these methods on some other threads that are in wait
state. That’s why these methods are made static so that when this method is
called statically, it works on the current executing thread and avoid confusion to
the programmers who might think that they can invoke these methods on some
non-running threads.

16. How can we achieve thread safety in Java?


There are several ways to achieve thread safety in java – synchronization, atomic
concurrent classes, implementing concurrent Lock interface, using volatile
keyword, using immutable classes and Thread safe classes. Learn more at thread
safety tutorial.

17. What is volatile keyword in Java


When we use volatile keyword with a variable, all the threads read it’s value
directly from the memory and don’t cache it. This makes sure that the value read
is the same as in the memory.
18. Which is more preferred – Synchronized
method or Synchronized block?
Synchronized block is more preferred way because it doesn’t lock the Object,
synchronized methods lock the Object and if there are multiple synchronization
blocks in the class, even though they are not related, it will stop them from
execution and put them in wait state to get the lock on Object.

19. How to create daemon thread in Java?


Thread class setDaemon(true) can be used to create daemon thread in java. We
need to call this method before calling start() method else it will throw
IllegalThreadStateException.

20. What is ThreadLocal?


Java ThreadLocal is used to create thread-local variables. We know that all
threads of an Object share it’s variables, so if the variable is not thread safe, we
can use synchronization but if we want to avoid synchronization, we can use
ThreadLocal variables.
Every thread has it’s own ThreadLocal variable and they can use it’s get() and
set() methods to get the default value or change it’s value local to Thread.
ThreadLocal instances are typically private static fields in classes that wish to
associate state with a thread. Check this post for small example program
showing ThreadLocal Example.

21. What is Thread Group? Why it’s advised not


to use it?
ThreadGroup is a class which was intended to provide information about a thread
group. ThreadGroup API is weak and it doesn’t have any functionality that is not
provided by Thread. Two of the major feature it had are to get the list of active
threads in a thread group and to set the uncaught exception handler for the
thread. But Java 1.5 has
added setUncaughtExceptionHandler(UncaughtExceptionHandler eh) method
using which we can add uncaught exception handler to the thread. So
ThreadGroup is obsolete and hence not advised to use anymore.

t1.setUncaughtExceptionHandler(new
UncaughtExceptionHandler(){

@Override
public void uncaughtException(Thread t, Throwable e) {
System.out.println("exception occured:"+e.getMessage());
}

});
22. What is Java Thread Dump, How can we get
Java Thread dump of a Program?
Thread dump is list of all the threads active in the JVM, thread dumps are very
helpful in analyzing bottlenecks in the application and analyzing deadlock
situations. There are many ways using which we can generate Thread dump –
Using Profiler, Kill -3 command, jstack tool etc. I prefer jstack tool to generate
thread dump of a program because it’s easy to use and comes with JDK
installation. Since it’s a terminal based tool, we can create script to generate
thread dump at regular intervals to analyze it later on. Read this post to know
more about generating thread dump in java.

23. What is Deadlock? How to analyze and avoid


deadlock situation?
Deadlock is a programming situation where two or more threads are blocked
forever, this situation arises with at least two threads and two or more resources.

To analyze a deadlock, we need to look at the java thread dump of the application,
we need to look out for the threads with state as BLOCKED and then the
resources it’s waiting to lock, every resource has a unique ID using which we can
find which thread is already holding the lock on the object.

Avoid Nested Locks, Lock Only What is Required and Avoid waiting indefinitely
are common ways to avoid deadlock situation, read this post to learn how
to analyze deadlock in java with sample program.

24. What is Java Timer Class? How to schedule a


task to run after specific interval?
java.util.Timer is a utility class that can be used to schedule a thread to be
executed at certain time in future. Java Timer class can be used to schedule a
task to be run one-time or to be run at regular intervals.

java.util.TimerTask is an abstract class that implements Runnable interface and


we need to extend this class to create our own TimerTask that can be scheduled
using java Timer class.
Check this post for java Timer example.

25. What is Thread Pool? How can we create


Thread Pool in Java?
A thread pool manages the pool of worker threads, it contains a queue that keeps
tasks waiting to get executed.

A thread pool manages the collection of Runnable threads and worker threads
execute Runnable from the queue.

java.util.concurrent.Executors provide implementation of


java.util.concurrent.Executor interface to create the thread pool in java. Thread
Pool Example program shows how to create and use Thread Pool in java. Or
read ScheduledThreadPoolExecutor Example to know how to schedule tasks after
certain delay.

26. What will happen if we don’t override Thread


class run() method?
Thread class run() method code is as shown below.

public void run() {


if (target != null) {
target.run();
}
}
Above target set in the init() method of Thread class and if we create an instance
of Thread class as new TestThread(), it’s set to null. So nothing will happen if
we don’t override the run() method. Below is a simple example demonstrating this.

public class TestThread extends Thread {

//not overriding Thread.run() method

//main method, can be in other class too


public static void main(String args[]){
Thread t = new TestThread();
System.out.println("Before starting thread");
t.start();
System.out.println("After starting thread");
}
}
It will print only below output and terminate.

Before starting thread


After starting thread
What are some of the improvements in Concurrency
API in Java 8?
Some important concurrent API enhancements are:

 ConcurrentHashMap compute(), forEach(), forEachEntry(), forEachKey(), forEachValue(),


merge(), reduce() and search() methods.
 CompletableFuture that may be explicitly completed (setting its value and status).
 Executors newWorkStealingPool() method to create a work-stealing thread pool using all
available processors as its target parallelism level.

1. What are Collection related features in Java 8?


Java 8 has brought major changes in the Collection API. Some of the changes
are:

1. Java Stream API for collection classes for supporting sequential as well as parallel
processing
2. Iterable interface is extended with forEach() default method that we can use to
iterate over a collection. It is very helpful when used with lambda
expressions because it’s argument Consumer is a function interface.
3. Miscellaneous Collection API improvements such
as forEachRemaining(Consumer action)method
in Iterator interface, Map replaceAll(), compute(), merge() methods.
2. What is Java Collections Framework? List out
some benefits of Collections framework?
Collections are used in every programming language and initial java release
contained few classes for collections: Vector, Stack, Hashtable, Array. But
looking at the larger scope and usage, Java 1.2 came up with Collections
Framework that group all the collections interfaces, implementations and
algorithms.
Java Collections have come through a long way with usage of Generics and
Concurrent Collection classes for thread-safe operations. It also includes blocking
interfaces and their implementations in java concurrent package.
Some of the benefits of collections framework are;
 Reduced development effort by using core collection classes rather than
implementing our own collection classes.
 Code quality is enhanced with the use of well tested collections framework classes.
 Reduced effort for code maintenance by using collection classes shipped with JDK.
 Reusability and Interoperability
What is the benefit of Generics in Collections
Framework?
Java 1.5 came with Generics and all collection interfaces and implementations
use it heavily. Generics allow us to provide the type of Object that a collection can
contain, so if you try to add any element of other type it throws compile time error.
This avoids ClassCastException at Runtime because you will get the error at
compilation. Also Generics make code clean since we don’t need to use casting
and instanceof operator. I would highly recommend to go through Java Generic
Tutorial to understand generics in a better way.

What are the basic interfaces of Java Collections


Framework?
Collection is the root of the collection hierarchy. A collection represents a group of
objects known as its elements. The Java platform doesn’t provide any direct
implementations of this interface.

Set is a collection that cannot contain duplicate elements. This interface models
the mathematical set abstraction and is used to represent sets, such as the deck
of cards.

List is an ordered collection and can contain duplicate elements. You can access
any element from it’s index. List is more like array with dynamic length.

A Map is an object that maps keys to values. A map cannot contain duplicate
keys: Each key can map to at most one value.

Some other interfaces


are Queue, Dequeue, Iterator, SortedSet, SortedMap and ListIterator.

Why Collection doesn’t extend Cloneable and


Serializable interfaces?
Collection interface specifies group of Objects known as elements. How the
elements are maintained is left up to the concrete implementations of Collection.
For example, some Collection implementations like List allow duplicate elements
whereas other implementations like Set don’t.
A lot of the Collection implementations have a public clone method. However, it
does’t really make sense to include it in all implementations of Collection. This is
because Collection is an abstract representation. What matters is the
implementation.
The semantics and the implications of either cloning or serializing come into play
when dealing with the actual implementation; so concrete implementation should
decide how it should be cloned or serialized, or even if it can be cloned or
serialized.
So mandating cloning and serialization in all implementations is actually less
flexible and more restrictive. The specific implementation should make the
decision as to whether it can be cloned or serialized.

Why Map interface doesn’t extend Collection


interface?
Although Map interface and it’s implementations are part of Collections
Framework, Map are not collections and collections are not Map. Hence it doesn’t
make sense for Map to extend Collection or vice versa.
If Map extends Collection interface, then where are the elements? Map contains
key-value pairs and it provides methods to retrieve list of Keys or values as
Collection but it doesn’t fit into the “group of elements” paradigm.

What is an Iterator?
Iterator interface provides methods to iterate over any Collection. We can get
iterator instance from a Collection using iterator() method. Iterator takes the place
of Enumeration in the Java Collections Framework. Iterators allow the caller to
remove elements from the underlying collection during the iteration. Java
Collection iterator provides a generic way for traversal through the elements of a
collection and implements Iterator Design Pattern.

What is difference between Enumeration and


Iterator interface?
Enumeration is twice as fast as Iterator and uses very less memory. Enumeration
is very basic and fits to basic needs. But Iterator is much safer as compared to
Enumeration because it always denies other threads to modify the collection
object which is being iterated by it.
Iterator takes the place of Enumeration in the Java Collections Framework.
Iterators allow the caller to remove elements from the underlying collection that is
not possible with Enumeration. Iterator method names have been improved to
make it’s functionality clear.
Why there is not method like Iterator.add() to add
elements to the collection?
The semantics are unclear, given that the contract for Iterator makes no
guarantees about the order of iteration. Note, however, that ListIterator does
provide an add operation, as it does guarantee the order of the iteration.

Why Iterator don’t have a method to get next


element directly without moving the cursor?
It can be implemented on top of current Iterator interface but since it’s use will be
rare, it doesn’t make sense to include it in the interface that everyone has to
implement.

What is different between Iterator and ListIterator?


 We can use Iterator to traverse Set and List collections whereas ListIterator can be
used with Lists only.
 Iterator can traverse in forward direction only whereas ListIterator can be used to
traverse in both the directions.
 ListIterator inherits from Iterator interface and comes with extra functionalities like
adding an element, replacing an element, getting index position for previous and
next elements.
What are different ways to iterate over a list?
We can iterate over a list in two different ways – using iterator and using for-each
loop.

List<String> strList = new ArrayList<>();

//using for-each loop


for(String obj : strList){
System.out.println(obj);
}

//using iterator
Iterator<String> it = strList.iterator();
while(it.hasNext()){
String obj = it.next();
System.out.println(obj);
}
Using iterator is more thread-safe because it makes sure that if underlying list
elements are modified, it will throw ConcurrentModificationException.
What do you understand by iterator fail-fast
property?
Iterator fail-fast property checks for any modification in the structure of the
underlying collection everytime we try to get the next element. If there are any
modifications found, it throws ConcurrentModificationException. All the
implementations of Iterator in Collection classes are fail-fast by design except the
concurrent collection classes like ConcurrentHashMap and
CopyOnWriteArrayList.

What is difference between fail-fast and fail-safe?


Iterator fail-safe property work with the clone of underlying collection, hence it’s
not affected by any modification in the collection. By design, all the collection
classes in java.util package are fail-fast whereas collection classes
in java.util.concurrent are fail-safe.
Fail-fast iterators throw ConcurrentModificationException whereas fail-safe iterator
never throws ConcurrentModificationException.
Check this post for CopyOnWriteArrayList Example.

How to avoid ConcurrentModificationException


while iterating a collection?
We can use concurrent collection classes to
avoid ConcurrentModificationException while iterating over a collection,
for example CopyOnWriteArrayList instead of ArrayList.
Check this post for ConcurrentHashMap Example.

Why there are no concrete implementations of


Iterator interface?
Iterator interface declare methods for iterating a collection but it’s implementation
is responsibility of the Collection implementation classes. Every collection class
that returns an iterator for traversing has it’s own Iterator implementation nested
class.
This allows collection classes to chose whether iterator is fail-fast or fail-safe. For
example ArrayList iterator is fail-fast whereas CopyOnWriteArrayList iterator is fail-
safe.

What is UnsupportedOperationException?
UnsupportedOperationException is the exception used to indicate that the
operation is not supported. It’s used extensively in JDK classes, in collections
framework java.util.Collections.UnmodifiableCollection throws this
exception for all add and removeoperations.

How HashMap works in Java?


HashMap stores key-value pair in Map.Entry static nested class implementation.
HashMap works on hashing algorithm and uses hashCode() and equals() method
in put and get methods.

When we call put method by passing key-value pair, HashMap uses Key
hashCode() with hashing to find out the index to store the key-value pair. The
Entry is stored in the LinkedList, so if there are already existing entry, it uses
equals() method to check if the passed key already exists, if yes it overwrites the
value else it creates a new entry and store this key-value Entry.

When we call get method by passing Key, again it uses the hashCode() to find
the index in the array and then use equals() method to find the correct Entry and
return it’s value. Below image will explain these detail clearly.

The other important things to know about HashMap are capacity, load factor,
threshold resizing. HashMap initial default capacity is 16 and load factor is 0.75.
Threshold is capacity multiplied by load factor and whenever we try to add an
entry, if map size is greater than threshold, HashMap rehashes the contents of
map into a new array with a larger capacity. The capacity is always power of 2, so
if you know that you need to store a large number of key-value pairs, for example
in caching data from database, it’s good idea to initialize the HashMap with correct
capacity and load factor.
What is the importance of hashCode() and equals()
methods?
HashMap uses Key object hashCode() and equals() method to determine the
index to put the key-value pair. These methods are also used when we try to get
value from HashMap. If these methods are not implemented correctly, two
different Key’s might produce same hashCode() and equals() output and in that
case rather than storing it at different location, HashMap will consider them same
and overwrite them.

Similarly all the collection classes that doesn’t store duplicate data use
hashCode() and equals() to find duplicates, so it’s very important to implement
them correctly. The implementation of equals() and hashCode() should follow
these rules.

 If o1.equals(o2), then o1.hashCode() == o2.hashCode()should


always be true.
 If o1.hashCode() == o2.hashCode is true, it doesn’t mean
that o1.equals(o2) will be true.
Can we use any class as Map key?
We can use any class as Map Key, however following points should be
considered before using them.

 If the class overrides equals() method, it should also override hashCode() method.
 The class should follow the rules associated with equals() and hashCode() for all
instances. Please refer earlier question for these rules.
 If a class field is not used in equals(), you should not use it in hashCode() method.
 Best practice for user defined key class is to make it immutable, so that hashCode()
value can be cached for fast performance. Also immutable classes make sure that
hashCode() and equals() will not change in future that will solve any issue with
mutability.
For example, let’s say I have a class MyKey that I am using for HashMap key.
 //MyKey name argument passed is used for equals() and
hashCode()
 MyKey key = new MyKey("Pankaj"); //assume hashCode=1234
 myHashMap.put(key, "Value");

 // Below code will change the key hashCode() and
equals()
 // but it's location is not changed.
 key.setName("Amit"); //assume new hashCode=7890

 //below will return null, because HashMap will try to
look for key
 //in the same index as it was stored but since key is
mutated,
 //there will be no match and it will return null.
 myHashMap.get(new MyKey("Pankaj"));
This is the reason why String and Integer are mostly used as HashMap
keys.

What are different Collection views provided by


Map interface?
Map interface provides three collection views:

0. Set<K> keySet(): Returns a Set view of the keys contained in this map. The set is
backed by the map, so changes to the map are reflected in the set, and vice-versa.
If the map is modified while an iteration over the set is in progress (except through
the iterator’s own remove operation), the results of the iteration are undefined. The
set supports element removal, which removes the corresponding mapping from the
map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear
operations. It does not support the add or addAll operations.
1. Collection<V> values(): Returns a Collection view of the values contained in this
map. The collection is backed by the map, so changes to the map are reflected in
the collection, and vice-versa. If the map is modified while an iteration over the
collection is in progress (except through the iterator’s own remove operation), the
results of the iteration are undefined. The collection supports element removal,
which removes the corresponding mapping from the map, via the Iterator.remove,
Collection.remove, removeAll, retainAll and clear operations. It does not support the
add or addAll operations.
2. Set<Map.Entry<K, V>> entrySet(): Returns a Set view of the mappings contained
in this map. The set is backed by the map, so changes to the map are reflected in
the set, and vice-versa. If the map is modified while an iteration over the set is in
progress (except through the iterator’s own remove operation, or through the
setValue operation on a map entry returned by the iterator) the results of the
iteration are undefined. The set supports element removal, which removes the
corresponding mapping from the map, via the Iterator.remove, Set.remove,
removeAll, retainAll and clear operations. It does not support the add or addAll
operations.
What is difference between HashMap and
Hashtable?
HashMap and Hashtable both implements Map interface and looks similar,
however there are following difference between HashMap and Hashtable.

0. HashMap allows null key and values whereas Hashtable doesn’t allow null key and
values.
1. Hashtable is synchronized but HashMap is not synchronized. So HashMap is better
for single threaded environment, Hashtable is suitable for multi-threaded
environment.
2. LinkedHashMap was introduced in Java 1.4 as a subclass of HashMap, so
incase you want iteration order, you can easily switch from HashMap to
LinkedHashMap but that is not the case with Hashtable whose iteration order is
unpredictable.
3. HashMap provides Set of keys to iterate and hence it’s fail-fast but Hashtable
provides Enumeration of keys that doesn’t support this feature.
4. Hashtable is considered to be legacy class and if you are looking for modifications
of Map while iterating, you should use ConcurrentHashMap.
How to decide between HashMap and TreeMap?
For inserting, deleting, and locating elements in a Map, the HashMap offers the
best alternative. If, however, you need to traverse the keys in a sorted order, then
TreeMap is your better alternative. Depending upon the size of your collection, it
may be faster to add elements to a HashMap, then convert the map to a TreeMap
for sorted key traversal.

What are similarities and difference between


ArrayList and Vector?
ArrayList and Vector are similar classes in many ways.

0. Both are index based and backed up by an array internally.


1. Both maintains the order of insertion and we can get the elements in the order of
insertion.
2. The iterator implementations of ArrayList and Vector both are fail-fast by design.
3. ArrayList and Vector both allows null values and random access to element using
index number.

These are the differences between ArrayList and Vector.

4. Vector is synchronized whereas ArrayList is not synchronized. However if you are


looking for modification of list while iterating, you should use CopyOnWriteArrayList.
5. ArrayList is faster than Vector because it doesn’t have any overhead because of
synchronization.
6. ArrayList is more versatile because we can get synchronized list or read-only list
from it easily using Collections utility class.
What is difference between Array and ArrayList?
When will you use Array over ArrayList?
Arrays can contain primitive or Objects whereas ArrayList can contain only
Objects.
Arrays are fixed size whereas ArrayList size is dynamic.
Arrays doesn’t provide a lot of features like ArrayList, such as addAll, removeAll,
iterator etc.

Although ArrayList is the obvious choice when we work on list, there are few times
when array are good to use.

 If the size of list is fixed and mostly used to store and traverse them.
 For list of primitive data types, although Collections use autoboxing to reduce the
coding effort but still it makes them slow when working on fixed size primitive data
types.
 If you are working on fixed multi-dimensional situation, using [][] is far more easier
than List<List<>>
What is difference between ArrayList and
LinkedList?
ArrayList and LinkedList both implement List interface but there are some
differences between them.

0. ArrayList is an index based data structure backed by Array, so it provides random


access to it’s elements with performance as O(1) but LinkedList stores data as list
of nodes where every node is linked to it’s previous and next node. So even though
there is a method to get the element using index, internally it traverse from start to
reach at the index node and then return the element, so performance is O(n) that is
slower than ArrayList.
1. Insertion, addition or removal of an element is faster in LinkedList compared to
ArrayList because there is no concept of resizing array or updating index when
element is added in middle.
2. LinkedList consumes more memory than ArrayList because every node in
LinkedList stores reference of previous and next elements.
Which collection classes provide random access
of it’s elements?
ArrayList, HashMap, TreeMap, Hashtable classes provide random access to it’s
elements. Download java collections pdf for more information.

What is EnumSet?
java.util.EnumSet is Set implementation to use with enum types. All of the
elements in an enum set must come from a single enum type that is specified,
explicitly or implicitly, when the set is created. EnumSet is not synchronized and
null elements are not allowed. It also provides some useful methods like
copyOf(Collection c), of(E first, E… rest) and complementOf(EnumSet s).

Check this post for java enum tutorial.


Which collection classes are thread-safe?
Vector, Hashtable, Properties and Stack are synchronized classes, so they are
thread-safe and can be used in multi-threaded environment. Java 1.5 Concurrent
API included some collection classes that allows modification of collection while
iteration because they work on the clone of the collection, so they are safe to use
in multi-threaded environment.

What are concurrent Collection Classes?


Java 1.5 Concurrent package (java.util.concurrent) contains thread-safe
collection classes that allow collections to be modified while iterating. By design
Iterator implementation in java.utilpackages are fail-fast and throws
ConcurrentModificationException. But Iterator implementation
in java.util.concurrent packages are fail-safe and we can modify the
collection while iterating. Some of these classes
are CopyOnWriteArrayList, ConcurrentHashMap, CopyOnWriteArraySet
.

Read these posts to learn about them in more detail.

 Avoid ConcurrentModificationException
 CopyOnWriteArrayList Example
 HashMap vs ConcurrentHashMap
What is BlockingQueue?
java.util.concurrent.BlockingQueue is a Queue that supports
operations that wait for the queue to become non-empty when retrieving and
removing an element, and wait for space to become available in the queue when
adding an element.

BlockingQueue interface is part of java collections framework and it’s primarily


used for implementing producer consumer problem. We don’t need to worry about
waiting for the space to be available for producer or object to be available for
consumer in BlockingQueue as it’s handled by implementation classes of
BlockingQueue.

Java provides several BlockingQueue implementations such as


ArrayBlockingQueue, LinkedBlockingQueue, PriorityBlockingQueue,
SynchronousQueue etc.
Check this post for use of BlockingQueue for producer-consumer problem.
What is Queue and Stack, list their differences?
Both Queue and Stack are used to store data before processing
them. java.util.Queue is an interface whose implementation classes are
present in java concurrent package. Queue allows retrieval of element in First-In-
First-Out (FIFO) order but it’s not always the case. There is also Deque interface
that allows elements to be retrieved from both end of the queue.
Stack is similar to queue except that it allows elements to be retrieved in Last-In-
First-Out (LIFO) order.
Stack is a class that extends Vector whereas Queue is an interface.

What is Collections Class?


java.util.Collections is a utility class consists exclusively of static methods
that operate on or return collections. It contains polymorphic algorithms that
operate on collections, “wrappers”, which return a new collection backed by a
specified collection, and a few other odds and ends.

This class contains methods for collection framework algorithms, such as binary
search, sorting, shuffling, reverse etc.

What is Comparable and Comparator interface?


Java provides Comparable interface which should be implemented by any custom
class if we want to use Arrays or Collections sorting methods. Comparable
interface has compareTo(T obj) method which is used by sorting methods. We
should override this method in such a way that it returns a negative integer, zero,
or a positive integer if “this” object is less than, equal to, or greater than the object
passed as argument.

But, in most real life scenarios, we want sorting based on different parameters.
For example, as a CEO, I would like to sort the employees based on Salary, an
HR would like to sort them based on the age. This is the situation where we need
to use Comparator interface because Comparable.compareTo(Object
o) method implementation can sort based on one field only and we can’t chose
the field on which we want to sort the Object.

Comparator interface compare(Object o1, Object o2) method need to be


implemented that takes two Object argument, it should be implemented in such a
way that it returns negative int if first argument is less than the second one and
returns zero if they are equal and positive int if first argument is greater than
second one.
Check this post for use of Comparable and Comparator interface to sort objects.

What is difference between Comparable and


Comparator interface?
Comparable and Comparator interfaces are used to sort collection or array of
objects.

Comparable interface is used to provide the natural sorting of objects and we can
use it to provide sorting based on single logic.
Comparator interface is used to provide different algorithms for sorting and we can
chose the comparator we want to use to sort the given collection of objects.

How can we sort a list of Objects?


If we need to sort an array of Objects, we can use Arrays.sort(). If we need to
sort a list of objects, we can use Collections.sort(). Both these classes
have overloaded sort() methods for natural sorting (using Comparable) or sorting
based on criteria (using Comparator).
Collections internally uses Arrays sorting method, so both of them have same
performance except that Collections take sometime to convert list to array.

While passing a Collection as argument to a


function, how can we make sure the function will
not be able to modify it?
We can create a read-only collection
using Collections.unmodifiableCollection(Collection c)method
before passing it as argument, this will make sure that any operation to change
the collection will throw UnsupportedOperationException.

How can we create a synchronized collection from


given collection?
We can use Collections.synchronizedCollection(Collection c) to
get a synchronized (thread-safe) collection backed by the specified collection.

What are common algorithms implemented in


Collections Framework?
Java Collections Framework provides algorithm implementations that are
commonly used such as sorting and searching. Collections class contain these
method implementations. Most of these algorithms work on List but some of them
are applicable for all kinds of collections.
Some of them are sorting, searching, shuffling, min-max values.

What is Big-O notation? Give some examples?


The Big-O notation describes the performance of an algorithm in terms of number
of elements in a data structure. Since Collection classes are actually data
structures, we usually tend to use Big-O notation to chose the collection
implementation to use based on time, memory and performance.

Example 1: ArrayList get(index i) is a constant-time operation and doesn’t


depend on the number of elements in the list. So it’s performance in Big-O
notation is O(1).
Example 2: A linear search on array or list performance is O(n) because we need
to search through entire list of elements to find the element.

What are best practices related to Java Collections


Framework?
 Chosing the right type of collection based on the need, for example if size is fixed,
we might want to use Array over ArrayList. If we have to iterate over the Map in
order of insertion, we need to use TreeMap. If we don’t want duplicates, we should
use Set.
 Some collection classes allows to specify the initial capacity, so if we have an
estimate of number of elements we will store, we can use it to avoid rehashing or
resizing.
 Write program in terms of interfaces not implementations, it allows us to change the
implementation easily at later point of time.
 Always use Generics for type-safety and avoid ClassCastException at runtime.
 Use immutable classes provided by JDK as key in Map to avoid implementation of
hashCode() and equals() for our custom class.
 Use Collections utility class as much as possible for algorithms or to get read-only,
synchronized or empty collections rather than writing own implementation. It will
enhance code-reuse with greater stability and low maintainability.
What is Java Priority Queue?
PriorityQueue is an unbounded queue based on a priority heap and the elements
are ordered in their natural order or we can provide Comparator for ordering at the
time of creation. PriorityQueue doesn’t allow null values and we can’t add any
object that doesn’t provide natural ordering or we don’t have any comparator for
them for ordering. Java PriorityQueue is not thread-safe and provided O(log(n))
time for enqueing and dequeing operations. Check this post for java priority queue
example.

Why can’t we write code as List<Number>


numbers = new ArrayList<Integer>();?
Generics doesn’t support sub-typing because it will cause issues in achieving type
safety. That’s why List<T> is not considered as a subtype of List<S> where S is
the super-type of T. To understanding why it’s not allowed, let’s see what could
have happened if it has been supported.

List<Long> listLong = new ArrayList<Long>();


listLong.add(Long.valueOf(10));
List<Number> listNumbers = listLong; // compiler error
listNumbers.add(Double.valueOf(1.23));
As you can see from above code that IF generics would have been supporting
sub-typing, we could have easily add a Double to the list of Long that would have
caused ClassCastException at runtime while traversing the list of Long.

Why can’t we create generic array? or write code


as List<Integer>[] array = new
ArrayList<Integer>[10];
We are not allowed to create generic arrays because array carry type information
of it’s elements at runtime. This information is used at runtime to
throw ArrayStoreException if elements type doesn’t match to the defined
type. Since generics type information gets erased at compile time by Type
Erasure, the array store check would have been passed where it should have
failed. Let’s understand this with a simple example code.

List<Integer>[] intList = new List<Integer>[5]; // compile


error
Object[] objArray = intList;
List<Double> doubleList = new ArrayList<Double>();
doubleList.add(Double.valueOf(1.23));
objArray[0] = doubleList; // this should fail but it would
pass because at runtime intList and doubleList both are just
List
Arrays are covariant by nature i.e S[] is a subtype of T[] whenever S is a subtype
of T but generics doesn’t support covariance or sub-typing as we saw in last
question. So if we would have been allowed to create generic arrays, because of
type erasure we would not get array store exception even though both types are
not related.

Creational Design Patterns


Creational design patterns provide solution to instantiate a object in the best possible
way for specific situations.

1. Singleton Pattern
Singleton pattern restricts the instantiation of a class and ensures that only one
instance of the class exists in the java virtual machine. It seems to be a very
simple design pattern but when it comes to implementation, it comes with a lot of
implementation concerns. The implementation of Singleton pattern has always
been a controversial topic among developers. Check out Singleton Design
Patternto learn about different ways to implement Singleton pattern and pros and
cons of each of the method. This is one of the most discussed java design
patterns.

2. Factory Pattern
Factory design pattern is used when we have a super class with multiple sub-
classes and based on input, we need to return one of the sub-class. This pattern
take out the responsibility of instantiation of a class from client program to the
factory class. We can apply Singleton pattern on Factory class or make the factory
method static. Check out Factory Design Pattern for example program
and factory pattern benefits. This is one of the most widely used java design
pattern.

3. Abstract Factory Pattern


Abstract Factory pattern is similar to Factory pattern and it’s factory of factories. If
you are familiar with factory design pattern in java, you will notice that we have a
single Factory class that returns the different sub-classes based on the input
provided and factory class uses if-else or switch statement to achieve this.

In Abstract Factory pattern, we get rid of if-else block and have a factory class for
each sub-class and then an Abstract Factory class that will return the sub-class
based on the input factory class. Check out Abstract Factory Pattern to know
how to implement this pattern with example program.

4. Builder Pattern
This pattern was introduced to solve some of the problems with Factory and
Abstract Factory design patterns when the Object contains a lot of attributes.
Builder pattern solves the issue with large number of optional parameters and
inconsistent state by providing a way to build the object step-by-step and provide
a method that will actually return the final Object. Check out Builder Pattern for
example program and classes used in JDK.

5. Prototype Pattern
Prototype pattern is used when the Object creation is a costly affair and requires a
lot of time and resources and you have a similar object already existing. So this
pattern provides a mechanism to copy the original object to a new object and then
modify it according to our needs. This pattern uses java cloning to copy the object.

Prototype design pattern mandates that the Object which you are copying should
provide the copying feature. It should not be done by any other class. However
whether to use shallow or deep copy of the Object properties depends on the
requirements and it’s a design decision. Check out Prototype Pattern for sample
program.

Structural Design Patterns


Structural patterns provide different ways to create a class structure, for example using
inheritance and composition to create a large object from small objects.

1. Adapter Pattern
Adapter design pattern is one of the structural design pattern and it’s used so that
two unrelated interfaces can work together. The object that joins these unrelated
interface is called an Adapter. As a real life example, we can think of a mobile
charger as an adapter because mobile battery needs 3 volts to charge but the
normal socket produces either 120V (US) or 240V (India). So the mobile charger
works as an adapter between mobile charging socket and the wall socket. Check
out Adapter Patternfor example program and it’s usage in Java.

2. Composite Pattern
Composite pattern is one of the Structural design pattern and is used when we
have to represent a part-whole hierarchy. When we need to create a structure in a
way that the objects in the structure has to be treated the same way, we can apply
composite design pattern.
Lets understand it with a real life example – A diagram is a structure that consists
of Objects such as Circle, Lines, Triangle etc and when we fill the drawing with
color (say Red), the same color also gets applied to the Objects in the drawing.
Here drawing is made up of different parts and they all have same operations.
Check out Composite Pattern article for different component of composite
pattern and example program.

3. Proxy Pattern
Proxy pattern intent is to “Provide a surrogate or placeholder for another object to
control access to it”. The definition itself is very clear and proxy pattern is used
when we want to provide controlled access of a functionality.

Let’s say we have a class that can run some command on the system. Now if we
are using it, it’s fine but if we want to give this program to a client application, it
can have severe issues because client program can issue command to delete
some system files or change some settings that you don’t want. Check out Proxy
Pattern post for the example program with implementation details.

4. Flyweight Pattern
Flyweight design pattern is used when we need to create a lot of Objects of a
class. Since every object consumes memory space that can be crucial for low
memory devices, such as mobile devices or embedded systems, flyweight design
pattern can be applied to reduce the load on memory by sharing objects. String
Pool implementation in java is one of the best example of Flyweight pattern
implementation. Check out Flyweight Pattern article for sample program and
implementation process.

5. Facade Pattern
Facade Pattern is used to help client applications to easily interact with the
system. Suppose we have an application with set of interfaces to use
MySql/Oracle database and to generate different types of reports, such as HTML
report, PDF report etc. So we will have different set of interfaces to work with
different types of database. Now a client application can use these interfaces to
get the required database connection and generate reports. But when the
complexity increases or the interface behavior names are confusing, client
application will find it difficult to manage it. So we can apply Facade pattern here
and provide a wrapper interface on top of the existing interface to help client
application. Check out Facade Pattern post for implementation details and
sample program.
6. Bridge Pattern
When we have interface hierarchies in both interfaces as well as implementations,
then bridge design pattern is used to decouple the interfaces from implementation
and hiding the implementation details from the client programs. Like Adapter
pattern, it’s one of the Structural design pattern.

The implementation of bridge design pattern follows the notion to prefer


Composition over inheritance. Check out Bridge Pattern post for implementation
details and sample program.

7. Decorator Pattern
Decorator design pattern is used to modify the functionality of an object at runtime.
At the same time other instances of the same class will not be affected by this, so
individual object gets the modified behavior. Decorator design pattern is one of the
structural design pattern (such as Adapter Pattern, Bridge Pattern, Composite
Pattern) and uses abstract classes or interface with composition to implement.

We use inheritance or composition to extend the behavior of an object but this is


done at compile time and it’s applicable to all the instances of the class. We can’t
add any new functionality of remove any existing behavior at runtime – this is
when Decorator pattern comes into picture. Check out Decorator Pattern post for
sample program and implementation details.

Behavioral Design Patterns


Behavioral patterns provide solution for the better interaction between objects and how
to provide lose coupling and flexibility to extend easily.

1. Template Method Pattern


Template Method is a behavioral design pattern and it’s used to create a method
stub and deferring some of the steps of implementation to the subclasses.
Template method defines the steps to execute an algorithm and it can provide
default implementation that might be common for all or some of the subclasses.

Suppose we want to provide an algorithm to build a house. The steps need to be


performed to build a house are – building foundation, building pillars, building
walls and windows. The important point is that the we can’t change the order of
execution because we can’t build windows before building the foundation. So in
this case we can create a template method that will use different methods to build
the house. Check out Template Method Pattern post for implementation details
with example program.

2. Mediator Pattern
Mediator design pattern is used to provide a centralized communication medium
between different objects in a system. Mediator design pattern is very helpful in an
enterprise application where multiple objects are interacting with each other. If the
objects interact with each other directly, the system components are tightly-
coupled with each other that makes maintainability cost higher and not flexible to
extend easily. Mediator pattern focuses on provide a mediator between objects for
communication and help in implementing lose-coupling between objects.

Air traffic controller is a great example of mediator pattern where the airport
control room works as a mediator for communication between different flights.
Mediator works as a router between objects and it can have it’s own logic to
provide way of communication. Check out Mediator Pattern post for
implementation details with example program.

3. Chain of Responsibility Pattern


Chain of responsibility pattern is used to achieve lose coupling in software design
where a request from client is passed to a chain of objects to process them. Then
the object in the chain will decide themselves who will be processing the request
and whether the request is required to be sent to the next object in the chain or
not.

We know that we can have multiple catch blocks in a try-catch block code. Here
every catch block is kind of a processor to process that particular exception. So
when any exception occurs in the try block, it’s sent to the first catch block to
process. If the catch block is not able to process it, it forwards the request to next
object in chain i.e next catch block. If even the last catch block is not able to
process it, the exception is thrown outside of the chain to the calling program.

ATM dispense machine logic can be implemented using Chain of Responsibility


Pattern, check out the linked post.

4. Observer Pattern
Observer design pattern is useful when you are interested in the state of an object
and want to get notified whenever there is any change. In observer pattern, the
object that watch on the state of another object are called Observer and the
object that is being watched is called Subject.
Java provides inbuilt platform for implementing Observer pattern through
java.util.Observable class and java.util.Observer interface. However it’s not widely
used because the implementation is really simple and most of the times we don’t
want to end up extending a class just for implementing Observer pattern as java
doesn’t provide multiple inheritance in classes.

Java Message Service (JMS) uses Observer pattern along with Mediator pattern
to allow applications to subscribe and publish data to other applications. Check
out Observer Pattern post for implementation details and example program.

5. Strategy Pattern
Strategy pattern is used when we have multiple algorithm for a specific task and
client decides the actual implementation to be used at runtime.

Strategy pattern is also known as Policy Pattern. We defines multiple algorithms


and let client application pass the algorithm to be used as a parameter. One of the
best example of this pattern is Collections.sort() method that takes Comparator
parameter. Based on the different implementations of Comparator interfaces, the
Objects are getting sorted in different ways.

Check out Strategy Pattern post for implementation details and example
program.

6. Command Pattern
Command Pattern is used to implement lose coupling in a request-response
model. In command pattern, the request is send to the invoker and invoker pass it
to the encapsulated command object. Command object passes the request to the
appropriate method of Receiver to perform the specific action.

Let’s say we want to provide a File System utility with methods to open, write and
close file and it should support multiple operating systems such as Windows and
Unix.

To implement our File System utility, first of all we need to create the receiver
classes that will actually do all the work. Since we code in terms of java interfaces,
we can have FileSystemReceiver interface and it’s implementation classes for
different operating system flavors such as Windows, Unix, Solaris etc. Check
out Command Pattern post for the implementation details with example program.

7. State Pattern
State design pattern is used when an Object change it’s behavior based on it’s
internal state.

If we have to change the behavior of an object based on it’s state, we can have a
state variable in the Object and use if-else condition block to perform different
actions based on the state. State pattern is used to provide a systematic and lose-
coupled way to achieve this through Context and State implementations.

Check out State Pattern post for implementation details with example program.

8. Visitor Pattern
Visitor pattern is used when we have to perform an operation on a group of similar
kind of Objects. With the help of visitor pattern, we can move the operational logic
from the objects to another class.

For example, think of a Shopping cart where we can add different type of items
(Elements), when we click on checkout button, it calculates the total amount to be
paid. Now we can have the calculation logic in item classes or we can move out
this logic to another class using visitor pattern. Let’s implement this in our example
of visitor pattern. Check out Visitor Pattern post for implementation details.

9. Interpreter Pattern
is used to defines a grammatical representation for a language and provides an
interpreter to deal with this grammar.

The best example of this pattern is java compiler that interprets the java source
code into byte code that is understandable by JVM. Google Translator is also an
example of interpreter pattern where the input can be in any language and we can
get the output interpreted in another language.

Check out Interpreter Pattern post for example program.

10. Iterator Pattern


Iterator pattern in one of the behavioral pattern and it’s used to provide a standard
way to traverse through a group of Objects. Iterator pattern is widely used in Java
Collection Framework where Iterator interface provides methods for traversing
through a collection.
Iterator pattern is not only about traversing through a collection, we can provide
different kind of iterators based on our requirements. Iterator pattern hides the
actual implementation of traversal through the collection and client programs just
use iterator methods. Check out Iterator Pattern post for example program and
implementation details.

11. Memento Pattern


Memento design pattern is used when we want to save the state of an object so
that we can restore later on. Memento pattern is used to implement this in such a
way that the saved state data of the object is not accessible outside of the object,
this protects the integrity of saved state data.

Memento pattern is implemented with two objects – Originator and Caretaker.


Originator is the object whose state needs to be saved and restored and it uses an
inner class to save the state of Object. The inner class is called Memento and it’s
private, so that it can’t be accessed from other objects.

Spring framework is a Injection dependency framework at first (it's still as it is


today) targeting managing life-cycle of Java components (what so-called beans).
Today, Spring framework is pretty bloated with tons facilities/helpers on top of it; but if
you look at the big picture, it's still a framework that glue things together, a middle man
to MVC frameworks (Struts 1,2, JSF etc), ORM frameworks (Hibernate, iBatis, JOOQ
etc) and other necessary facilities (Quartz, Email, you can tell, whatever you need, most
likely, there's a Spring support). Back to our assumed flow, it takes quite a lengthy
tutorial to set Spring framework up and running because Spring framework nature is to
provide flexibility of choices to you.

Spring boot on the other hand is built on a totally different mantra. It's basically a
suite, pre-configured, pre-sugared set of frameworks/technologies to reduce boiler plate
configuration providing you the shortest way to have a Spring web application up and
running with smallest line of code/configuration out-of-the-box. As you can see from
there Spring Boot page, it took less than 20 LOC to have a simple RESTful application
up and running with almost zero configuration. It definitely has a ton of way to
configure application to match your need, this is the Spring Boot Reference Guide for
your reference

 Spring is a light weight and open source framework created by Rod Johnson in
2003. Spring is a complete and a modular framework, i mean spring
framework can be used for all layer implementations for a real time application
or spring can be used for the development of particular layer of a real time
application unlike struts [ only for front end related ] and hibernate [ only for
database related ], but with spring we can develop all layers
 Spring framework is said to be a non-invasive means it doesn’t force a
programmer to extend or implement their class from any predefined class or
interface given by Spring API, in struts we used to extend Action Class right
that’s why struts is said to be invasive
 In case of struts framework, it will forces the programmer that, the
programmer class must extend from the base class provided by struts API
 Spring is light weight framework because of its POJO model
 Spring Framework made J2EE application development little easier, by
introducing POJO model
Spring having this much of demand because of the following 3 reasons….

 Simplicity
 Testability
 Loose Coupling
spring boot:

first of all Spring Boot is not a framework, it is a way to ease to create stand-alone
application with minimal or zero configurations. It is approach to develop spring based
application with very less configuration. It provides defaults for code and annotation
configuration to quick start new spring projects within no time. Spring Boot leverages
existing spring projects as well as Third party projects to develop production ready
applications. It provides a set of Starter Pom’s or gradle build files which one
can use to add required dependencies and also facilitate auto configuration.

Spring Boot automatically configures required classes depending on the libraries on its
classpath. Suppose your application want to interact with DB, if there are Spring Data
libraries on class path then it automatically sets up connection to DB along with the
Data Source class.

 It is very easy to develop Spring Based applications with Java or Groovy.


 Spring Boot reduces lots of development time and increases productivity.
 It avoids writing lots of boilerplate Code, Annotations and XML Configuration.
 It is very easy to integrate Spring Boot Application with its Spring Ecosystem
like Spring JDBC, Spring ORM, Spring Data, Spring Security etc.
 Spring Boot follows “Opinionated Defaults Configuration” Approach to reduce
Developer effort
 It provides Embedded HTTP servers like Tomcat, Jetty etc. to develop and test
our web applications very easily.
 It provides CLI (Command Line Interface) tool to develop and test Spring Boot
(Java or Groovy) Applications from command prompt very easily and quickly.
 Spring Boot provides lots of plugins to develop and test Spring Boot
Applications very easily using Build Tools like Maven and Gradle
 It provides lots of plugins to work with embedded and in-memory Databases
very easily.
 Both Spring Framework & Spring Boot are used to create Java Enterprise
applications.
 One could do everything using Spring Framework that can be achieved by
Spring Boot.
Then why Spring Boot?
To understand this, one need to understand the design philosophy behind the creation
of Spring Boot. If you understand the design philosophy/objective, then you would
automatically know the difference between those.

I will give some highlights of those design objectives:

1. Convention over Configuration


It’s a software design paradigm used by many software frameworks/systems
that provides sensible defaults to its user obviously by following the best
practices and without losing flexibility.

The impact of this design principle are profound and these includes; good
architecture, maintainability, uniform & standard product creation, lesser
number of decisions for the user, increase in the overall productivity, faster
development etc just to mention a few.

The idea is that, system/framework would provide sensible defaults for their
users [by convention] and if one deviates/departs from the these defaults then
only one needs to make any configuration changes. Let’s take
some Examples:
Example 1: (Deployment Simplified)
Suppose user is creating a web application following Spring MVC then it’s
obvious that the user will be needing a container like Tomcat to deploy this
application. If your framework can provide embedded Tomcat then user don’t
have to waste their time & effort in installing, configuring their Tomcat
instance. If one doesn’t want this default behavior then framework should have
flexibility for that also.
Work For You : Look out for the dependent jars of spring-boot-starter-
web artifactId
<dependency><groupId>org.springframework.boot</groupId><artifactId>
spring-boot-starter-web</artifactId></dependency>
Let me know, what have you found? :-)

Example 2: (Dependency Management Simplified)


If you have developed your enterprise application using Spring Framework
(traditional way) then you surely know the headache of finding of right jars,
right versions of jars, upgrading the version of jars and many more.
What if, user can get all the dependent jars along with their transitive
dependencies out of box by simply pointing out that they need jars related to
web or security or jpa etc.
Work For You: Check out Spring Boot Starter Packs like spring-boot-
starter-web, spring-boot-starter-actuator etc
2. Rapid Application Development
One sentence, maximizing the code that actually adds value or related to your
domain & reducing the boilerplate code. Take an example: code in your
application that marshals XML or JSON has no customer value nor does it
have a developer benefit
Now we have discussed the design philosophy behind the creation of Spring Boot. What
it actually does? How does it help?

 Accelerate the development


 Developers invest their time in creating solutions that actually matters and
adds values rather than wasting hour [both effort & time] in setting up their
development environment, projects, making configuration changes and writing
boilerplate codes
Hoping that, I am able to explain the difference between Spring framework & Spring
Boot from design perspective.

Spring Boot enables building production-ready applications quickly and provides non-
functional features:

 Embedded servers which are easy to deploy with the containers


 It helps in monitoring the multiples components
 It helps in configuring the components externally
Challenges With Microservice Architectures

While developing a number of smaller microservices might look easy, but there are
number of inherent complexities that are associated with microservices architectures.
Let’s look at some of the challenges:

 Automating the Components: It becomes difficult to automate everything


because there are a number of smaller components instead of a monolith, i.e.
Builds, Deployment, Monitoring, etc.
 Perceptibility: There are number of small components to deploy and
maintain which sometimes becomes difficult to monitor and identify problems.
It requires great perceptibility around all the components.
 Configuration Management: There is a great need to maintain the
configurations for the components across the various environments.
 Debugging: It becomes difficult to probe each and every service for an error.
Centralized Logging and Dashboards are essential to make it easy to debug
problems.
 Consistency: You cannot have a wide range of tools solving the same
problem. While it is important to foster innovation, it is also important to have
some decentralized governance around the languages, platforms, technology
and tools used for implementing/deploying/monitoring microservices.
Spring boot has been built on top of existing spring framework. Using spring boot we
avoid all the boilerplate code and configurations that we had to do previously. Spring
boot thus helps us use the existing Spring functionalities more robustly and with
minimum efforts.

Features of Spring boot-

 Auto-Configuration - No need to manually configure dispatcher servlet,


static resource mappings, property source loader, message converters etc.
 Dependency Management - The different versions of commonly used
libraries are pre-selected and grouped in different starter POMs that we can
include in your project. By selecting one Spring Boot version we are implicitly
selecting dozens of dependencies that we would have to otherwise select and
harmonize ourself. Example-
 Advanced Externalized Configuration - There is a large list of bean
properties that can be configured through application.properties file without
touching java or xml config.
 Production support- We get health checking, application and jvm metrics,
jmx via http and a few more things for free.
 Runnable Jars - We can package your application as a runnable jar with
embedded tomcat included so it presents a self-contained deployment unit
 The Spring Framework is an application framework and inversion of control
container for the Java platform.

 Spring Boot is not a Framework, it is Spring's convention-over-


configurationsolution for creating stand-alone, production-grade Spring-based
Applications.

1. Easy dependency Management

 First thing to observe is we are using some dependencies named like spring-boot-
starter-*. Remember I said “95% of the times I use the same configuration. So when
you add springboot-starter-web dependency by default it will pull all the
commonly used libraries while developing Spring MVC applications such as spring-
webmvc, jackson-json, validation-api and tomcat.
 We have added spring-boot-starter-data-jpa dependency. This pulls all
the spring-data-jpa dependencies and also adds Hibernate libraries because the
majority of the applications use Hibernate as JPA implementation.
2. Auto Configuration

 Not only the spring-boot-starter-web adds all these libraries but also configures
the commonly registered beans like DispatcherServlet, ResourceHandlers,
MessageSource etc beans with sensible defaults.
 We also added spring-boot-starter-Thymeleaf which not only adds the Thymeleaf
library dependencies but also configures ThymeleafViewResolver beans as well
automatically.
 We haven’t defined any of the DataSource, EntityManagerFactory,
TransactionManageretc beans but they are automatically gets created. How? If we
have any in-memory database drivers like H2 or HSQL in our classpath then
SpringBoot will automatically create an in-memory DataSource and then
registers EntityManagerFactory, TransactionManager beans automatically
with sensible defaults. But we are using MySQL, so we need to explicitly provide
MySQL connection details. We have configured those MySQL connection details
in application.properties file and SpringBoot creates a DataSource using these
properties.
3. Embedded Servlet Container Support

The most important and surprising thing is we have created a simple Java class
annotated with some magical annotation @SpringApplication having a main method
and by running that main we are able to run the application and access it
at http://localhost:8080/.

What is the core problem that Spring Framework solves? Think long and
hard. What’s the problem Spring Framework solves?

Most important feature of Spring Framework is Dependency Injection. At the core of all
Spring Modules is Dependency Injection or IOC Inversion of Control.

Why is this important?

Because, when DI or IOC is used properly, we can develop loosely coupled applications.
And loosely coupled applications can be easily unit tested.

What is the core problem that Spring MVC Framework solves?

Spring MVC Framework provides decoupled way of developing web applications. With
simple concepts like Dispatcher Servlet, ModelAndView and View Resolver, it makes it
easy to develop web applications.

Why do we need Spring Boot?

Spring based applications have a lot of configuration. For example, when we use Spring
MVC, we need to configure component scan, dispatcher servlet, a view resolver, web
jars(for delivering static content) among other things.
1. <bean
2.
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
3. <property name="prefix">
4. <value>/WEB-INF/views/</value>
5. </property>
6. <property name="suffix">
7. <value>.jsp</value>
8. </property>
9. </bean>
10.
11. <mvc:resources mapping="/webjars/**" location="/webjars/"/>
Below code snippet shows typical configuration of a dispatcher servlet in a web
application.

<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/todo-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
Spring Boot brings in new thought process around this.

Can we bring more intelligence into this? When a spring mvc jar is added into an
application, can we auto configure some beans automatically?

 How about auto configuring a Data Source if Hibernate jar is on the classpath?
 How about auto configuring a Dispatcher Servlet if Spring MVC jar is on the
classpath?
Spring Boot looks at a) Frameworks available on the CLASSPATH b) Existing
configuration for the application. Based on these, Spring Boot provides basic
configuration needed to configure the application with these frameworks. This is called
Auto Configuration.

 Spring MVC is associated with controller operations, i.e., serving the request and
respone in the Spring Framework. It eases and reduces the development effort
required on the frontend. It provides a tag library for displaying the content on
the UI. You can also customize the tags. You can define mutiple content
negotiation handlers for the same request controller. For example same
controller can return a JSP or a json. And the list goes on. You can check the
documentation for further details.

Spring Boot lets you create the whole spring framework based web apps quickly.
It is all java classes configuration based. You can add different modules of spring
as per your needs.

 Spring Boot “bundles” and configures common Spring features in


one place.
 Spring MVC is a web framework, one of Spring’s core features.
Spring Boot includes Spring MVC.
 Spring MVC is a complete HTTP oriented MVC framework managed by the Spring
Framework and based in Servlets. It would be equivalent to JSF in the JavaEE
stack. The most popular elements in it are classes annotated with @Controller,
where you implement methods you can access using different HTTP requests. It has
an equivalent @RestController to implement REST based APIs.
 Spring boot is a utility for setting up applications quickly, offering an out of the
box configuration in order to build Spring powered applications. As you may know,
Spring integrates a wide range of different modules in its umbrella, as spring-
core, spring-data,spring-web (which includes Spring MVC, by the way) and so on.
With this tool you can tell Spring how many of them to use and you'll get a fast
setup for them (you are allowed to change it by yourself later on).
So, Spring MVC is a framework to be used in web applications and Spring boot is a
Spring based production-ready project initializer.
Project Manager Duties - Planning

 identify project stakeholders


 determine stakeholders needs and expectations
 prioritize demands
 establish clear set of project goals
 sequence activities to meet delivery dates
 produce detailed project schedule
 determine type, quantity and quality of resources required
 allocate resources and establish resource schedule
 determine budget and create financial plan
 define quality expectations and targets
 identify techniques for quality control and develop quality plan
 map risks, identify contingency actions and develop risk plan
 clarify completion criteria for each deliverable and develop acceptance plan
 develop communication strategy with stakeholders and establish communication plan
 identify external supplies required and develop procurement plan
 assemble project team

Project Manager Skills for Planning Phase

 long term vision


 goal setting
 attention to detail
 scope, time, quality, resource, risk and cost management skills
 interactive communication skills
 expectation management
 persuasive techniques

Project Execution

 implement project plans to build deliverables


 monitor and control project deliverables
 manage timelines
 manage costs
 identify and manage risks
 assure and control quality
 suggest and implement modifications to project scope, deliverables, timelines and
resources
 track and monitor procurement
 prepare and present project status reports to stakeholders
 support and direct project team

Project Manager Skills for Execution Phase

 organizational effectiveness
 team building
 performance management
 motivation skills
 conflict resolution
 diversity appreciation
 staff development
 problem solving

 adaptability
 change management
 consultative skills
 sense of urgency
 judgment
 decision making
 customer relations management
 negotiation skills

Project Closure

 ensure project completion criteria have been met


 obtain stakeholder approval for final deliverables
 present final project report
 handover project documentation
 release project resources
 conduct project review
 evaluate performance against defined project goals
Project Manager Skills for Closure Phase

 presentation skills
 data management
 evaluation skills
 efficiently synthesize project information and accurately establish project scope
 set project costs and productivity benchmarks
 successfully manage and control budgets up to $X
 develop good working relationships with stakeholders at all levels to build consensus
 effectively lead and coordinate project teams of up to X members
 solve critical issues in a time-sensitive environment
 proven quality assurance, risk management and change management expertise

Thorough knowledge of:

 cross-functional project management concepts, methods and practices


 information technology applications, processes, software and equipment
 business systems design and business process management
 testing techniques and methodologies

A results-driven professional with strong client-centric skills and an agile approach to


project management.

 define project scope, objectives, staffing, resources and deliverables


 develop project plans that identify key issues, approaches and performance metrics
 plan and schedule project timelines and milestones
 formulate risk management plans
 assemble and coordinate multi-disciplinary project teams
 lead and mentor up to X project staff
 manage vendor relationships including negotiating and controlling contracts
 track project deliverables
 monitor quality assurance measures
 control project variances through root cause analysis and correction
 implement and manage project changes and interventions
 manage and control project budgets
 develop and present reports on project progress
 maintain communication with project stakeholders and manage expectations
 evaluate projects and assess results
Core Competencies

 organizational and planning skills


 oral and written communication skills
 data collection, analysis and management
 problem assessment and analysis
 critical thinking
 decision-making
 delegation
 teamwork
 negotiation
 conflict management
 adaptability

Elasticsearch is a highly scalable open-source full-text search and analytics engine. It allows you
to store, search, and analyze big volumes of data quickly and in near real time. It is generally
used as the underlying engine/technology that powers applications that have complex search
features and requirements.
Here are a few sample use-cases that Elasticsearch could be used for:
 You run an online web store where you allow your customers to search for products that you sell.
In this case, you can use Elasticsearch to store your entire product catalog and inventory and
provide search and autocomplete suggestions for them.
 You want to collect log or transaction data and you want to analyze and mine this data to look
for trends, statistics, summarizations, or anomalies. In this case, you can use Logstash (part of
the Elasticsearch/Logstash/Kibana stack) to collect, aggregate, and parse your data, and then
have Logstash feed this data into Elasticsearch. Once the data is in Elasticsearch, you can run
searches and aggregations to mine any information that is of interest to you.
 You run a price alerting platform which allows price-savvy customers to specify a rule like "I am
interested in buying a specific electronic gadget and I want to be notified if the price of gadget
falls below $X from any vendor within the next month". In this case you can scrape vendor
prices, push them into Elasticsearch and use its reverse-search (Percolator) capability to match
price movements against customer queries and eventually push the alerts out to the customer
once matches are found.
 You have analytics/business-intelligence needs and want to quickly investigate, analyze,
visualize, and ask ad-hoc questions on a lot of data (think millions or billions of records). In this
case, you can use Elasticsearch to store your data and then use Kibana (part of the
Elasticsearch/Logstash/Kibana stack) to build custom dashboards that can visualize aspects of
your data that are important to you. Additionally, you can use the Elasticsearch aggregations
functionality to perform complex business intelligence queries against your data.
For the rest of this tutorial, you will be guided through the process of getting Elasticsearch up
and running, taking a peek inside it, and performing basic operations like indexing, searching,
and modifying your data. At the end of this tutorial, you should have a good idea of what
Elasticsearch is, how it works, and hopefully be inspired to see how you can use it to either build
sophisticated search applications or to mine intelligence from your data.

Basic Concepts
There are a few concepts that are core to Elasticsearch. Understanding these concepts from the
outset will tremendously help ease the learning process.

Near Realtime (NRT)edit


Elasticsearch is a near real time search platform. What this means is there is a slight latency
(normally one second) from the time you index a document until the time it becomes searchable.

Clusteredit
A cluster is a collection of one or more nodes (servers) that together holds your entire data and
provides federated indexing and search capabilities across all nodes. A cluster is identified by a
unique name which by default is "elasticsearch". This name is important because a node can only
be part of a cluster if the node is set up to join the cluster by its name.
Make sure that you don’t reuse the same cluster names in different environments, otherwise you
might end up with nodes joining the wrong cluster. For instance you could use logging-
dev, logging-stage, and logging-prod for the development, staging, and production clusters.
Note that it is valid and perfectly fine to have a cluster with only a single node in it. Furthermore,
you may also have multiple independent clusters each with its own unique cluster name.

Nodeedit
A node is a single server that is part of your cluster, stores your data, and participates in the
cluster’s indexing and search capabilities. Just like a cluster, a node is identified by a name
which by default is a random Universally Unique IDentifier (UUID) that is assigned to the node
at startup. You can define any node name you want if you do not want the default. This name is
important for administration purposes where you want to identify which servers in your network
correspond to which nodes in your Elasticsearch cluster.
A node can be configured to join a specific cluster by the cluster name. By default, each node is
set up to join a cluster named elasticsearch which means that if you start up a number of
nodes on your network and—assuming they can discover each other—they will all automatically
form and join a single cluster named elasticsearch.
In a single cluster, you can have as many nodes as you want. Furthermore, if there are no other
Elasticsearch nodes currently running on your network, starting a single node will by default
form a new single-node cluster named elasticsearch.

Indexedit
An index is a collection of documents that have somewhat similar characteristics. For example,
you can have an index for customer data, another index for a product catalog, and yet another
index for order data. An index is identified by a name (that must be all lowercase) and this name
is used to refer to the index when performing indexing, search, update, and delete operations
against the documents in it.
In a single cluster, you can define as many indexes as you want.

A type used to be a logical category/partition of your index to allow you to store different types of
documents in the same index, eg one type for users, another type for blog posts. It is no longer possible to
create multiple types in an index, and the whole concept of types will be removed in a later version.
See Removal of mapping types for more.

Documentedit
A document is a basic unit of information that can be indexed. For example, you can have a
document for a single customer, another document for a single product, and yet another for a
single order. This document is expressed in JSON (JavaScript Object Notation) which is a
ubiquitous internet data interchange format.
Within an index/type, you can store as many documents as you want. Note that although a
document physically resides in an index, a document actually must be indexed/assigned to a type
inside an index.

Shards & Replicasedit


An index can potentially store a large amount of data that can exceed the hardware limits of a
single node. For example, a single index of a billion documents taking up 1TB of disk space may
not fit on the disk of a single node or may be too slow to serve search requests from a single
node alone.
To solve this problem, Elasticsearch provides the ability to subdivide your index into multiple
pieces called shards. When you create an index, you can simply define the number of shards that
you want. Each shard is in itself a fully-functional and independent "index" that can be hosted on
any node in the cluster.
Sharding is important for two primary reasons:
 It allows you to horizontally split/scale your content volume
 It allows you to distribute and parallelize operations across shards (potentially on multiple nodes) thus
increasing performance/throughput
The mechanics of how a shard is distributed and also how its documents are aggregated back into
search requests are completely managed by Elasticsearch and is transparent to you as the user.
In a network/cloud environment where failures can be expected anytime, it is very useful and
highly recommended to have a failover mechanism in case a shard/node somehow goes offline or
disappears for whatever reason. To this end, Elasticsearch allows you to make one or more
copies of your index’s shards into what are called replica shards, or replicas for short.
Replication is important for two primary reasons:
 It provides high availability in case a shard/node fails. For this reason, it is important to note that a replica
shard is never allocated on the same node as the original/primary shard that it was copied from.
 It allows you to scale out your search volume/throughput since searches can be executed on all replicas in
parallel.
To summarize, each index can be split into multiple shards. An index can also be replicated zero
(meaning no replicas) or more times. Once replicated, each index will have primary shards (the
original shards that were replicated from) and replica shards (the copies of the primary shards).
The number of shards and replicas can be defined per index at the time the index is created. After
the index is created, you may change the number of replicas dynamically anytime but you cannot
change the number of shards after-the-fact.
By default, each index in Elasticsearch is allocated 5 primary shards and 1 replica which means
that if you have at least two nodes in your cluster, your index will have 5 primary shards and
another 5 replica shards (1 complete replica) for a total of 10 shards per index.

Installation example with MSI Windows Installeredit


For Windows users, we recommend using the MSI Installer package. The package contains a
graphical user interface (GUI) that guides you through the installation process.
First, download the Elasticsearch 6.3.0 MSI
fromhttps://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.0.msi.
Then double-click the downloaded file to launch the GUI. Within the first screen, select the
deployment directories:
By default, Elasticsearch will be installed at %PROGRAMFILES%\Elastic\Elasticsearch.
Navigate here and go into the bin directory as follows:
with Command Prompt:

cd %PROGRAMFILES%\Elastic\Elasticsearch\bin
with PowerShell:

cd $env:PROGRAMFILES\Elastic\Elasticsearch\bin
And now we are ready to start our node and single cluster:

.\elasticsearch.exe

Successfully running nodeedit


If everything goes well with installation, you should see a bunch of messages that look like
below:

[2016-09-16T14:17:51,251][INFO ][o.e.n.Node ] []
initializing ...
[2016-09-16T14:17:51,329][INFO ][o.e.e.NodeEnvironment ] [6-bjhwl]
using [1] data paths, mounts [[/ (/dev/sda1)]], net usable_space
[317.7gb], net total_space [453.6gb], spins? [no], types [ext4]
[2016-09-16T14:17:51,330][INFO ][o.e.e.NodeEnvironment ] [6-bjhwl]
heap size [1.9gb], compressed ordinary object pointers [true]
[2016-09-16T14:17:51,333][INFO ][o.e.n.Node ] [6-bjhwl]
node name [6-bjhwl] derived from node ID; set [node.name] to override
[2016-09-16T14:17:51,334][INFO ][o.e.n.Node ] [6-bjhwl]
version[6.3.0], pid[21261], build[f5daa16/2016-09-16T09:12:24.346Z],
OS[Linux/4.4.0-36-generic/amd64], JVM[Oracle Corporation/Java
HotSpot(TM) 64-Bit Server VM/1.8.0_60/25.60-b23]
[2016-09-16T14:17:51,967][INFO ][o.e.p.PluginsService ] [6-bjhwl]
loaded module [aggs-matrix-stats]
[2016-09-16T14:17:51,967][INFO ][o.e.p.PluginsService ] [6-bjhwl]
loaded module [ingest-common]
[2016-09-16T14:17:51,967][INFO ][o.e.p.PluginsService ] [6-bjhwl]
loaded module [lang-expression]
[2016-09-16T14:17:51,967][INFO ][o.e.p.PluginsService ] [6-bjhwl]
loaded module [lang-mustache]
[2016-09-16T14:17:51,967][INFO ][o.e.p.PluginsService ] [6-bjhwl]
loaded module [lang-painless]
[2016-09-16T14:17:51,967][INFO ][o.e.p.PluginsService ] [6-bjhwl]
loaded module [percolator]
[2016-09-16T14:17:51,968][INFO ][o.e.p.PluginsService ] [6-bjhwl]
loaded module [reindex]
[2016-09-16T14:17:51,968][INFO ][o.e.p.PluginsService ] [6-bjhwl]
loaded module [transport-netty3]
[2016-09-16T14:17:51,968][INFO ][o.e.p.PluginsService ] [6-bjhwl]
loaded module [transport-netty4]
[2016-09-16T14:17:51,968][INFO ][o.e.p.PluginsService ] [6-bjhwl]
loaded plugin [mapper-murmur3]
[2016-09-16T14:17:53,521][INFO ][o.e.n.Node ] [6-bjhwl]
initialized
[2016-09-16T14:17:53,521][INFO ][o.e.n.Node ] [6-bjhwl]
starting ...
[2016-09-16T14:17:53,671][INFO ][o.e.t.TransportService ] [6-bjhwl]
publish_address {192.168.8.112:9300}, bound_addresses
{{192.168.8.112:9300}
[2016-09-16T14:17:53,676][WARN ][o.e.b.BootstrapCheck ] [6-bjhwl]
max virtual memory areas vm.max_map_count [65530] likely too low,
increase to at least [262144]
[2016-09-16T14:17:56,731][INFO ][o.e.h.HttpServer ] [6-bjhwl]
publish_address {192.168.8.112:9200}, bound_addresses {[::1]:9200},
{192.168.8.112:9200}
[2016-09-16T14:17:56,732][INFO ][o.e.g.GatewayService ] [6-bjhwl]
recovered [0] indices into cluster_state
[2016-09-16T14:17:56,748][INFO ][o.e.n.Node ] [6-bjhwl]
started
Without going too much into detail, we can see that our node named "6-bjhwl" (which will be a
different set of characters in your case) has started and elected itself as a master in a single
cluster. Don’t worry yet at the moment what master means. The main thing that is important here
is that we have started one node within one cluster.
As mentioned previously, we can override either the cluster or node name. This can be done
from the command line when starting Elasticsearch as follows:

./elasticsearch -Ecluster.name=my_cluster_name -
Enode.name=my_node_name
Also note the line marked http with information about the HTTP address (192.168.8.112) and
port (9200) that our node is reachable from. By default, Elasticsearch uses port 9200 to provide
access to its REST API. This port is configurable if necessary.

The REST APIedit


Now that we have our node (and cluster) up and running, the next step is to understand how to
communicate with it. Fortunately, Elasticsearch provides a very comprehensive and powerful
REST API that you can use to interact with your cluster. Among the few things that can be done
with the API are as follows:
 Check your cluster, node, and index health, status, and statistics
 Administer your cluster, node, and index data and metadata
 Perform CRUD (Create, Read, Update, and Delete) and search operations against your indexes
 Execute advanced search operations such as paging, sorting, filtering, scripting, aggregations, and many
others

Basic Elasticsearch Concepts


In this document, we'll cover the basics of what you need to know about
Elasticsearch in order to use it.
Indexing
Elasticsearch is able to achieve fast search responses because, instead of
searching the text directly, it searches an index instead.

This is like retrieving pages in a book related to a keyword by scanning the


index at the back of a book, as opposed to searching every word of every
page of the book.

This type of index is called an inverted index, because it inverts a page-


centric data structure (page->words) to a keyword-centric data structure
(word->pages).

Elasticsearch uses Apache Lucene to create and manage this inverted index.

How Elasticsearch represents data


In Elasticsearch, a Document is the unit of search and index.

An index consists of one or more Documents, and a Document


consists of one or more Fields.

In database terminology, a Document corresponds to a table row, and a Field


corresponds to a table column.

Schema

Unlike Solr, Elasticsearch is schema-free. Well, kinda.

Whilst you are not required to specify a schema before indexing documents,
it is necessary to add mapping declarations if you require anything but the
most basic fields and operations.

This is no different from specifying a schema!

The schema declares:

 what fields there are


 which field should be used as the unique/primary key
 which fields are required
 how to index and search each field

In Elasticsearch, an index may store documents of different "mapping


types". You can associate multiple mapping definitions for each mapping
type. A mapping type is a way of separating the documents in an index
into logical groups.
To create a mapping, you will need the Put Mapping API, or you can add
multiple mappings when you create an index.

Query DSL
The Query DSL is Elasticsearch's way of making Lucene's query syntax
accessible to users, allowing complex queries to be composed using a JSON
syntax.

Like Lucene, there are basic queries such as term or prefix queries and also
compound queries like the bool query.

The main structure of a query is roughly:


curl -X POST "http://localhost:9200/blog/_search?pretty=true" -d ‘
{"from": 0,
"size": 10,
"query" : QUERY_JSON,
FILTER_JSON,
FACET_JSON,
SORT_JSON
}’

What about Lucene, by the way?


Elasticsearch is powered by Lucene, a powerful open-source full-text search
library, under the hood.

The relationship between Elasticsearch and Lucene, is like that of the


relationship between a car and its engine.

For the purpose of this introduction, we haven't differentiated between the


two, just as to most people, the distinction between a car and its engine is
not terribly important when learning how to drive a car.

However, to a mechanic, the distinction is a very important one. Similarly,


when we dive deeper under the bonnet of Elasticsearch, we'll explore the
distinctions between Lucene and ElasticSearch in detail.
**********************************
Yet choosing the right cloud service can be rather challenging. Many people

have no idea what SaaS, IaaS, and PaaS mean or which of these cloud solutions

they need for their projects.

We’ve written this article to explain what cloud services are available and help

you choose the one that suits your business goals.

What do IaaS, PaaS, and SaaS


mean?
There are three major types of cloud services: IaaS, PaaS, and SaaS. You’ve

probably seen these abbreviations on the websites of cloud providers. Before

going into details, let’s compare IaaS, PaaS, and SaaS to transportation:

 On-premises IT infrastructure is like owning a car. When you buy a

car, you’re responsible for its maintenance, and upgrading means buying a

new car.

 IaaS is like leasing a car. When you lease a car, you choose the car you

want and drive it wherever you wish, but the car isn’t yours. Want an

upgrade? Just lease a different car!

 PaaS is like taking a taxi. You don’t drive a taxi yourself, but simply tell

the driver where you need to go and relax in the back seat.
 SaaS is like going by bus. Buses have assigned routes, and you share

the ride with other passengers.

These analogies will help you better understand our more detailed explanations.

LetNow that you know what SaaS, PaaS, and IaaS mean, let’s be more specific

about when each should be used and what their advantages and disadvantages

are.

When and Why You Should Use


SaaS
We’ve already mentioned some examples of SaaS solutions, so you have a

general understanding of when they’re used. Let’s provide some more details.

SaaS solutions can be used for:

 Personal purposes. Millions of individuals all over the world use email

services (Gmail, Hotmail, Yahoo), cloud storage services (Dropbox,

Microsoft OneDrive), cloud-based file management services (Google

Docs), and so on. People may not realize it, but all of these cloud services

are actually SaaS services.

 Business. Companies of various sizes may use SaaS solutions such as

corporate email services (Gmail is available for businesses, for example),

collaboration tools (Trello), customer relationship management software


(Salesforce, Zoho), event management software (EventPro, Cvent), and

enterprise resource planning software (SAP S/4HANA Cloud ERP).

SaaS services offer plenty of advantages to individuals and businesses:

 Access to applications from anywhere. Unlike on-premises software,

which can be accessed only from a computer (or a network) it’s installed

on, SaaS solutions are cloud-based. Thus, you can access them from

anywhere there’s internet access, be it your company’s office or a hotel

room.

 Can be used from any device. Cloud-based SaaS services can be

accessed from any computer. You only need to sign in. Many SaaS

solutions have mobile apps, so they can be accessed from mobile devices

as well.

 Automatic software updates. You don’t need to bother updating your

SaaS software, as updates are carried out by a cloud service vendor. If

there are any bugs or technical troubles, the vendor will fix them while you

focus on your work instead of on software maintenance.

 Low cost. Compared to on-premises software, SaaS services are rather

affordable. There’s no need to pay for the whole IT infrastructure; you pay
only for the service at the scale you need. If you need extra functionality,

you can always update your subscription.

 Simple adoption. SaaS services are available out-of-the-box, so adopting

them is a piece of cake. We’ve already mentioned what you need to do:

just sign up. It’s as simple as that. There’s no need to install anything.

Of course, SaaS solutions have certain disadvantages as well, so let’s mention a

couple of them:

 You have no control over the hardware that handles your data.

 Only a vendor can manage the parameters of the software you’re using.

When and Why You Should Use


PaaS
PaaS solutions are used mostly by software developers. PaaS provides an

environment for developing, testing, and managing applications. PaaS is

therefore the perfect choice for software development companies.

No wonder that software developers use PaaS services such as Heroku, Elastic

Beanstalk (offered by Amazon Web Services), and Google App Engine.

PaaS provides a number of benefits to developers:


 Reduced development time. PaaS services allow software developers to

significantly reduce development time. Server-side components of the

computing infrastructure (web servers, storage, networking resources, etc.)

are provided by a vendor, so development teams don’t need to configure,

maintain, or update them. Instead, developers can focus on delivering

projects with top speed and quality.

 Support for different programming languages. PaaS cloud services

usually support multiple programming languages, giving developers an

opportunity to deliver various projects, from startup MVPs to enterprise

solutions, on the same platform.

 Easy collaboration for remote and distributed teams. PaaS gives

enormous collaboration capabilities to remote and distributed teams.

Outsourcing and freelancing are common today, and many software

development teams are comprised of specialists who live in different parts

of the world. PaaS services allow them to access the same software

architecture from anywhere and at any time.

 High development capabilities without additional staff. PaaS provides

development companies with everything they need to create applications

without the necessity of hiring additional staff. All hardware and

middleware is provided, maintained, and upgraded by a PaaS vendor,


which means businesses don’t need staff to configure servers and

databases or deploy operating systems.

Of course, PaaS cloud services have certain disadvantages:

 You have no control over the virtual machine that’s processing your data.

 PaaS solutions are less flexible than IaaS. For example, you can’t create

and delete several virtual machines at a time.

When and Why You Should Use


IaaS
IaaS solutions can be used for multiple purposes. Unlike SaaS and PaaS, IaaS

provides hardware infrastructure that you can use in a variety of ways. It’s like

having a set of tools that you can use for constructing the item you need.

Here are several scenarios when you can use IaaS:

 Website or application hosting. You can run your website or application

with the help of IaaS (for example, using Elastic Compute Cloud from

Amazon Web Services).

 Virtual data centers. IaaS is the best solution for building virtual data

centers for large-scale enterprises that need an effective, scalable, and

safe server environment.


 Data analysis. Analyzing huge amounts of data requires incredible

computing power, and IaaS is the most economical way to get it.

Companies use Infrastructure as a Service for data mining and analysis.

Infrastructure as a Service provides the following major advantages for

businesses:

 No expenses on hardware infrastructure. IaaS vendors provide and

maintain hardware infrastructure: servers, storage, and networking

resources. This means that businesses don’t need to invest in expensive

hardware, which is a substantial cost savings as IT hardware infrastructure

is rather pricey.

 Perfect scalability. Though all cloud-based solutions are scalable, this is

particularly true of Infrastructure as a Service, as additional resources are

available to your application in case of higher demand. Apps can also be

scaled down if demand is low.

 Reliability and security. Ensuring the safety of your data is a IaaS

vendor’s responsibility. Hardware infrastructure is usually kept in specially

designed data centers, and a cloud provider guarantees security of your

data.

Finally, let’s specify the disadvantages of IaaS cloud solutions:


 IaaS is more expensive than SaaS or PaaS, as you in fact lease hardware

infrastructure.

 All issues related to the management of a virtual machine are your

responsibility.

IaaS vs PaaS vs SaaS: Which Cloud


Service Is Suitable for You?
It’s time to pick which cloud-based service you need. In fact, the choice totally

depends on your business goals, so first of all consider what your company

needs. Here are some common business needs that can easily be met with the

appropriate cloud service:

 If your business needs out-of-the-box software (CRM, email, collaboration

tools, etc.), choose Software as a Service.

 If your company requires a platform for building software products, pick

Platform as a Service.

 If your business needs a virtual machine, opt for Infrastructure as a

Service.

If you feel that you can’t make the right choice on your own, we can help you

choose the most appropriate solution to meet your business goals.


’s give a definition to each of these terms.

Perfect for: IT administrators

As you can see, each cloud service (IaaS, PaaS, and SaaS) is tailored to the

business needs of its target audience. From the technical point of view, IaaS

gives you the most control but requires extensive expertise to manage the

computing infrastructure, while SaaS allows you to use cloud-based applications

without needing to manage the underlying infrastructure. Cloud services, thus,

can be depicted as a pyramid:

Software as a Service (SaaS)


SaaS allows people to use cloud-based web applications.

In fact, email services such as Gmail and Hotmail are examples of cloud-based

SaaS services. Other examples of SaaS services are office tools (Office 365 and

Google Docs), customer relationship management software (Salesforce), event

management software (Planning Pod), and so on.

SaaS services are usually available with a pay-as-you-go (which means

subscription) pricing model. All software and hardware are provided and

managed by a vendor, so you don’t need to install or configure anything. The

application is ready to go as soon as you get your login and password.


Software as a Service (SaaS)

Managed by you Managed by vendor

Hosted applications

Development and management tools

Operating system

Servers and storage

Networking resources

Data center

Perfect for: end users

Platform as a Service (PaaS)


PaaS refers to cloud platforms that provide runtime environments for developing,

testing, and managing applications.

Thanks to PaaS solutions, software developers can deploy applications, from

simple to sophisticated, without needing all the related infrastructure (servers,

databases, operating systems, development tools, etc). Examples of PaaS

services are Heroku and Google App Engine.

PaaS vendors supply a complete infrastructure for application development,

while developers are in charge of the code.


Just like SaaS, Platform as a Service solutions are available with a pay-as-you-

go pricing model.

Platform as a Service (PaaS)

Managed by you Managed by vendor

Development and management tools

Operating system

Hosted applications Servers and storage

Networking resources

Data center

Perfect for: software developers

Infrastructure as a Service (IaaS)


IaaS is a cloud service that provides basic computing infrastructure: servers,

storage, and networking resources. In other words, IaaS is a virtual data center.

IaaS services can be used for a variety of purposes, from hosting websites to

analyzing big data. Clients can install and use whatever operating systems and
tools they like on the infrastructure they get. Major IaaS providers include

Amazon Web Services, Microsoft Azure, and Google Compute Engine.

As with SaaS and PaaS, IaaS services are available on a pay-for-what-you-use

model.

Infrastructure as a Service (IaaS)

Managed by you Managed by vendor

Hosted applications Servers and storage

Development and management tools Networking resources

Operating system Data center

Perfect for: IT administrators

Vous aimerez peut-être aussi