Collection :
- is a framework that provides an architecture to store and manipulate the group of
objects
- Java collections can achieve all the operations that we perform on a data
- Some of operations are searching, sorting, insertion manipulation and deletion
- It provides readymade API
List :
- provides the facility to maintain the ordered collection
- It contains the index based methods to insert, update, delete and search the
elements
- It can have duplicate elements also
- we can also store the null elements in the list
ArrayList :
- used a dynamic array for storing the elements
- No size limit
- duplicate elements allow
- maintain the insertion order
- allows random access
- Non-Synchronized
LinkedList :
- uses a doubly linked list to store the elements
- contains duplicate elements
- Non-Synchronized
- maintain insertion order
- manipulation is fast because no shifting needs to occure
Vector :
- Synchronized
- vector is a legacy class
- vector is slow because it is synchronized
- A vector can use the iterator or enumeration interface to traverse the elements
HashSet :
- contains unique elements only
- allows null value
- non-synchrionized
- doesn't maintain the insertion order
LinkedHashSet :
- contains unique elements only
- allow null value
- non-synchrionized
- maintain the insertion order
TreeSet :
- stored in ascending order
- contains unique elements
- doesn't allow null element
- non-synchronized
HashMap :
- store elements in the form of key & value pair
- keys should be unique
- may have one null key and multiple null values
- non-synchronized
- maintain no order
Hashtable :
- Hashtable store data in key and value pair.
- Hashtable is synchronized. It is thread safe and can be shared with many threads.
- Hashtable doesn't allow any null key or value.
- Hashtable is a legacy class.
- Hashtable is slow.
- Hashtable is traversed by Enumerator and Iterator.
Stack :
- It follows the principle LIFO.
- It has only one end from which both the insertion & deletion
take place and that end is known as top.
- it contains only one pointer known as top pointer.
- The top pointer holds the address of the last inserted
or the topmost element of the stack.
- It performs two operations push and pop.
- The push operation inserts the elements in a list.
- The pop operation removes elements in a list.
Queue :
- It follows the principle FIFO.
- It has two ends i.e. front and rear.
- The front end is used for deletion & rear end for insertion.
- It contains two pointers front and rear.
- The front pointer holds the address of the first element.
- The rear pointer holds the address of the last elements in queue.
- It performs two operations enqueue and dequeue.
- The enqueue operation performs the insertion of the element in a queue.
- The dequeue operation performs the deletion of the element in a queue.
LinkedHashMap :
- contains values based on the key
- contains unique elements
- It may have one null key and multiple null values
- Non-synchronized
- maintain insertion order
TreeMap :
- stores in key-value pairs in sorted order
- It contains values based on the key
- contains only unique elements
- cannot have a null key but have multiple null values
- non-synchronized
- maintain ascending order
Abstract Class :
- It can have abstract & non abstract methods
- It needs to be extended and its method implemented
- It cannot be instantiated
- It can have constructor and static methods also
- It can have final methods
Interface :
- It is a blueprint of a class
- It has static final and abstract methods
- is a mechanism to achieve abstraction
- only abstract methods present
- also represents the IS-A relationship
- used to achieve loose coupling
Abstraction :
- Abstraction is a technique by which we can hide the data that is not
required to users.
- It hides all unwanted data so that users can work only with the required data.
Encapsulation :
- Binding or wrapping the code and data together into a single unit it is called
encapsulation
- The main purpose of encapsulation is to provide the security
- To achieve encapsulation declare the variables as private and methods as public
of a class
- The main objective of encapsulation is data hiding or data security
Inheritance :
- The process of acquire properties of one class to another
- The process of acquires parent class variables & methods into child class
- The process in which one object can acquires all properties & methods of parent
class
- Inheritance helps to reuse the code & establish a relationship between different
classes
Polymorphism :
- If one task is perform in different ways it is known as polymorphism
- The process of providing multiple implementation to a method to perform one
operation
based on sub-type or based on parameter type is called as polymorphism
- Two types of polymorphism
- Compile-time polymorphism
- Run-time polymorphism
Strings :
- String is an object that represents sequence of char values
- Strings is immutable which means it cannot be changed
- is a non-primitive/reference datatype.
- is a final class
Error :
- Errors are problems that mainly occure due to the lack of system resources
- It cannot be caught or handled
- It occurs at runtime
- These are mainly unchecked
- Ex : OutOfMemoryError
StackOverFlowError
VirtualMachineError
Exception :
- It is an event that occurs during the execution of the program and interrupts the
normal flow of program instructions.
- Exceptions are occurs at compile time & runtime
- It occurs in the code written by the developers
- It can be recovered by using the try-catch block and throws keyword
Throw :
- The throw keyword is used to throw an exception
Throws :
- The "throws" keyword is used to declare exception.
- It specifies that there may occur an exception in the method
- It doesn't throw an exception
- It is always used with method signature
Super Keyword :
- It is a non-static final reference variable
- super keyword holds super-class / parent class information
- used to differentiate subclass instance variables or methods from superclass
- we can not use super keyword in static methods and static blocks
This keyword :
- this is a keyword
- this is a reference variable that refers to current class object instance members
- this keyword we can to differentiate between local and global variables
- we can use this keyword inside a instance method and inside a constructor only
- we cannot use this keyword inside a static method or static block
Static Keyword :
- The static keyword in Java is mainly used for memory management.
- The static keyword in Java is used to share the same variable or method of a
given class.
- The users can apply static keywords with variables, methods, blocks, and nested
classes
Volatile Keyword :
- Volatile keyword is used to modify the value of a variable by different threads.
- It is also used to make classes thread safe.
- It means that multiple threads can use a method and instance of the classes at
the same time without any problem.
- The volatile keyword can be used either with primitive type or objects.
Transient Keyword :
- The transient keyword can be used with the data members of a class in order to
avoid their serialization.
Hibernate :
- hibernate is an open-source object-Relational Mapping(ORM) framework
- simplifies database interaction by mapping java objects to database tables and
vice-versa
Hibernate methods :
- save
- delete
- update
- load
- get
Session :
- A session in hibernate represents a single threaded unit of work with the
database
- It provides methods for CRUD operations as well as transaction management
Difference between JDBC & Hibernate :
- JDBC is a technology and hibernate is a framework.
- JDBC works with rows and columns whereas hibernate works with class and
variables.
- JDBC does not built-in functions for performing CRUD operations on database.
- Hibernate has built in methods for performing CRUD operations.
- JDBC code is database dependent code and hibernate code is database independent
code.
Spring :
- Spring is a framework using which we can develop web application and web services
both.
- Before Spring Boot, Spring developers would develop this application using XML
based configuration.
Spring Boot :
- Spring Boot is open-source framework.
- Spring Boot is completely new project from spring community.
- In spring boot project, dependencies are managed using pom.xml file,
no need to configure tomcat server separetely, no need to write configuration
using XML.
Spring Annotations :
- Component
- Autowired
- Controller
- Service
- Repository
- RequestParam
SpringBoot Annotations
- SpringBootApplication
- RequestMapping
- GetMapping
- PostMapping
- PutMapping
- DeleteMapping
- RestController
- Value
Iterator :
-An Iterator is an object that can be used to loop through collections, like
ArrayList and HashSet.
-It is called an "iterator" because "iterating" is the technical term for looping.
-To use an Iterator, you must import it from the java.util package.
Wrapper Classes :
-Wrapper classes provide a way to use primitive data types (int, boolean, etc..) as
objects.
Threads :
- Threads allows a program to operate more efficiently by doing multiple things at
the same time.
- Threads can be used to perform complicated tasks in the background without
interrupting the main program.
- There are two ways to create a thread.
It can be created by extending the Thread class and overriding its run() method:
Another way to create a thread is to implement the Runnable interface:
Multithreading :
- Multithreading is a Java feature that allows concurrent execution of two or more
parts of a program for maximum utilization of CPU.
- Each part of such program is called a thread.
- So, threads are light-weight processes within a process.
- Threads can be created by using two mechanisms :
* Extending the Thread class
* Implementing the Runnable Interface
Serialization & Deserialization :
Serialization is a mechanism of converting the state of an object into a byte
stream.
Deserialization is the reverse process where the byte stream is used to recreate
the actual Java object in memory.
Occurance Of letters :
import java.io.*;
import java.util.*;
class HelloWorld {
public static void main(String[] args) {
String name = "Pratik";
char[] ch = name.toCharArray();
HashMap<Character,Integer> hm = new HashMap<Character,Integer>();
for(char c : ch)
{
if(hm.containsKey(c))
{
hm.put(c,hm.get(c)+1);
}
else
{
hm.put(c,1);
}
}
for(Map.Entry entry : hm.entrySet())
{
System.out.println(entry.getKey()+" -> "+entry.getValue());
System.out.println();
}
}
}