Java Guide1
Java Guide1
JDK:
JDK stands for Java Development Kit.
It is installable software used for developing java applications. It includes Java Runtime
Environment (JRE), an interpreter/loader (Java), a compiler (javac), an achiever (jar), a
Document generator (javadoc), and other tools needed for java development.
JRE:
It provides very good environment to run java applications only.
JVM:
It is an interpreter which is used to execute our program line by line procedure.
length length()
It is a final variable applicable for arrays. It is a final method applicable for String
objects.
It will return size of an array. It will return number of characters present
in a string.
== .equals()
It is used for reference or address It is used for content comparison.
comparison.
We can compare objects and primitives. We can’t compare primitives.
C++ Java
It was developed by Bjarne Stroustrup. It was developed by James Gosling.
It is a partial object oriented programming. It is purely object oriented programming.
It is platform dependent. It is platform independent.
It supports multiple inheritance. It does not support multiple inheritance.
It supports pointers. It does not support pointers.
It supports goto statement. It does not support goto statement.
It supports operator overloading. It does not support operator overloading.
Memory allocation and deallocation will Memory allocation and deallocation will
take care by a programmer. take care by a JVM.
It supports three access specifiers i.e public, It supports four access modifiers i.e default,
private and protected. public, private and protected.
It supports three loops i.e do while loop, It supports four loops i.e do while loop,
while loop and for loop. while, for loop and for each loop.
class object
It is a blueprint or template for an object. It is an instance of a class.
It is a logically entity. It is a physical entity.
It does not allocate the memory. It allocates the memory.
It can’t manipulate. It can manipulate.
It is declared once. It is declared many times.
To declare a class we will use class To declare object we will use new keyword.
keyword.
Abstraction Encapsulation
Hiding internal implementation and The process of encapsulating or grouping
highlighting the set of services is called variables and its associate methods in a
abstraction. single entity is called encapsulation.
It is used to hide the data. It is used to protect the data.
Using abstract classes and interfaces we Using access modifiers we can implements
can implements abstraction. encapsulation.
It is a process of gaining the information. It is a process of containing the
information.
It solves an issue at design level. It solves an issue at implementation level.
Composition Aggregation
Without existing container object there is a Without existing container object there is a
no chance of having contained object is chance of having contained object is called
called composition and aggregation. aggregation.
It is strongly association. It is weakly association.
10. What is the difference between default class and public class?
11. What is the difference between final class and abstract class?
Mutable Immutable
After object creation if we perform any After object creation if we perform any
changes then all changes will reflect in a changes then for every change a new
same object. object will be created.
Fields can be change after object creation. Fields can’t be change after object creation.
It contains setter and getter methods. It contains only setter method.
StringBuffer, StringBuilder, Date are String, Wrapper classes are immutable.
mutable.
StringBuffer StringBuilder
Every method present in StringBuffer is No method present in StringBuilder is
synchronized. synchronized.
At a time only one thread is allow to Multiple Threads are allowed to operate
operate on the StringBuffer object hence simultaneously on the StringBuilder object
StringBuffer object is Thread safe. hence StringBuilder is not Thread safe.
It increases waiting time of the Thread and Threads are not required to wait and hence
hence relatively performance is low. relatively performance is high.
Introduced in 1.0 version. Introduced in 1.5 version.
15. What is the difference between final, finally and finalize method?
Final:
Final is the modifier applicable for class, methods and variables.
If a class declared as the final then child class creation is not possible.
If a method declared as the final then overriding of that method is not possible.
If a variable declared as the final then reassignment is not possible.
Finally:
It is the block always associated with try catch to maintain clean up code which should be
executed always irrespective of whether exception raised or not raised.
List Set
It is an indexed sequence. It is a non-indexed sequence.
List allows duplicate objects. Set does not allow duplicate objects.
Insertion order is preserved. Insertion order is not preserved.
Multiple null insertion is possible. Null insertion is possible only once.
List implementations are ArrayList, Set implementations are HashSet,
LinkedList, Vector and Stack. LinkedHashSet and TreeSet.
Arrays Collections
It is a collection of homogeneous data It is a collection of homogeneous and
elements. heterogeneous data elements.
Arrays are fixed in size. Collections are growable in nature.
Performance point of view arrays are Memory point of view collections are
recommended to use. recommended to use.
Arrays are type safe. Collections are not type safe.
Arrays are not implemented based on data Collections are implemented based on data
structure concept so we can’t expect any structure concept so we can expect
readymade (utility) methods. readymade (utility) methods.
It holds primitive and object types. It holds only object types but not primitive
types.
ArrayList Vector
No method is synchronized Every method is synchronized
At a time multiple Threads are allow to At a time only one Thread is allow to operate
operate on ArrayList object and hence on Vector object and hence Vector object is
ArrayList object is not Thread safe. Thread safe.
Relatively performance is high because Relatively performance is low because
Threads are not required to wait. Threads are required to wait.
It is non legacy and introduced in 1.2v. It is legacy and introduced in 1.0v.
ArrayList LinkedList
The underlying data structure is resizable The underlying data structure is doubly
array or growable array. linked list.
ArrayList is better for storing and accessing LinkedList is better for manipulating data.
data.
The memory location for the elements of The location for the elements of a linked list
an ArrayList is contiguous. is not contagious.
When an ArrayList is initialized, a default There is no case of default capacity in a
capacity of 10 is assigned to the ArrayList. LinkedList.
HashSet LinkedHashSet
The underlying data structure is Hashtable. The underlying data structure is Hastable
and LinkedList.
Insertion order is not preserved. Insertion order is preserved.
Introduced in 1.2 version. Introduced in 1.4 version.
HashSet TreeSet
The underlying data structure is Hashtable. The underlying data structure is Balanced
Tree.
Null insertion is possible. Null insertion is not possible.
Heterogeneous objects are allowed. Heterogeneous objects are not allowed.
Insertion order is not preserved. Insertion order is sorting order of an object.
Comparable Comparator
It is present in java.lang package It is present in java.util package
It contains only one method i.e It contains two methods i.e compare() and
compareTo() equals()
If we depend upon natural sorting order If we depend upon customized sorting order
then we need to use Comparable interface. then we need to use Comparator interface.
HashMap LinkedHashMap
The underlying data structure is Hashtable. The underlying data structure is Hastable
and LinkedList.
Insertion order is not preserved. Insertion order is preserved.
Introduced in 1.2 version. Introduced in 1.4 version.
HashMap TreeMap
The underlying data structure is Hashtable. The underlying data structure is Red Black
Tree.
Insertion order is not preserved. Insertion order is sorting order of an object.
Both key and value can be null. Key can’t be null but value can be null.
HashMap Hashtable
The underlying data structure is The underlying data structure is
Hashtable. Hashtable.
Both key and value can be null Both key and value can’t be null.
It is a non-legacy class. It is a legacy class
It is introduced in 1.2 version. It is introduced in 1.0 version
Methods are not synchronized. All methods are synchronized.
Collection Collections
It is a root interface for entire collection It is a utility class.
framework.
It is used to represent a group of individual It defines several utility methods that are
objects in a single unit. used to operate on collection.
It contains abstract methods, static It contains only static methods.
methods and default methods.
DBMS RDBMS
DBMS stands Database Management RDBMS stands for Relational Database
System Management System
It stores the data in the form of files It stores the data in the form of tables
It is designed to handle small amount of It is designed to handle large amount of
data data
It provides support for a single user at a It provides support for multiple users at a
time time
Normalization is not possible for DBMS Normalization is possible for RDBMS
No security of data High security of data
RDBMS MongoDB
It is a relational database. It is a non-relational or document based
database.
It can’t stores the data in key and value pair. It stores the data in key and value pair.
Not suitable for hierarchical data storage. Suitable for hierarchical data storage.
It has a predefined(static) schema. It has a dynamic schema.
It contains tables. It contains Collections.
It is a row based. It is a document based.
It is a column based. It is a field based.
It is slower. It is faster.
It supports SQL query language. It supports JSON query language.
Normalization Denormalization
It increases the complexity due to multiple It reduces the complexity due to single table
tables
No redundant data Redundant data
No waste of memory Waste of memory
Slower reads Slower writes
Low data availability High data availability
Need of joins No need of joins
Delete truncate
It is a DML command. It is DDL
It deletes the data temporary. It deletes the data permanently.
We can rollback the data. We can’t rollback the data.
Where clause can be used. Where clause can’t be used.
ROWID ROWNUM
It is physical address of row. It is a sequential number for row.
It is permanent. It is temporary.
It returns address of row. It returns numeric value.
It is automatically generated at the time of It is automatically generated at the time of
insert. select.
36. What is the difference between simple view and complex view?
37. What is the difference between inner join and outer join?
SQL PL/SQL
It is Structured Query Language. It is Procedural Language extension to the
Structured Query Language.
It is data-oriented language. It is application-oriented language.
It directly interacts with database server. It does not interact with database server.
It does not provide errors and exceptions. It provides errors and exceptions.
It does not give programming features like It gives programming features like control
control statements, loops, variables and statements, loops, variables and etc.
etc.
It is used to write queries in DML, DDL, DRL, It is used to write procedures, functions,
TCL and DCL. packages, cursors and triggers.
Procedures Functions
It may or may not returns a value. It always returns a value.
DML operations are allowed. DML operations are not allowed.
Can’t be invoke by using select command. Can be invoke by using select command.
It is compiled once. It is compiled every time.
DatabaseMetaData ResultSetMetaData
It provides metadata of a database. It provides metadata of a table.
It gives information about database It gives information about number of
product name, database product version, columns, type of columns, size of columns,
database driver name, database driver column counts and etc.
version, username and etc.
We can create object by using We can create object by using
getMetaData() method of Connection getMetaData() method of ResultSet object.
object.
41. What is the difference between Scrollable and Non-Scrollable ResultSet object?
ServletConfig ServletContext
It is created by web container for every It is created by web container for every web
servlet. application.
It is created during the initialization process It is created during the deployment of web
of servlet. application.
As long as servlet is executing, Servletconfig As long as web application is executing,
object will be available. ServletContext object will be available.
It reads configuration information from It reads configuration information from
web.xml file which is local to one servlet. web.xml file which is global to all servlets.
Using getServletConfig() method we will Using getServletContext() method we will
create ServletConfig object. create ServletContext object.
Servlets JSP
To work with servlets strong java To work with JSP strong java knowledge is
knowledge is required. not required.
It is not suitable for non-java programmers. It is suitable for non-java programmers.
It does not support tags. It supports tags.
It does not give any implicit object. It gives 9 implicit objects.
Configuration of servlet program in Configuration of jsp program in web.xml
web.xml file is mandatory. file is optional.
Handling exceptions are mandatory. Handing exceptions is optional.
We can’t maintain HTML code and Java We can maintain HTML code and Java code
code separately. separately.
It runs faster than JSP. It runs slower than servlet because it takes
time to compile the program and convert
into Servlets.
GET POST
It is a default methodology. It is not a default methodology.
It sends the request fastly. It sends the request bit slow.
It carries limited amount of data. It carries unlimited amount of data.
It is not suitable for secure data. It is suitable for secure data.
Not suitable for encryption and file Suitable for encryption and file uploading.
uploading.
To process GET methodology we will use To process POST methodology we will use
doGet(-,-) method. doPost(-,-) method.
GenericServlet HttpServlet
It is present in javax.servlet package. It is present in javax.servlet.http package.
It is protocol independent. It is protocol dependent.
Session management is not possible. Session management is possible.
Redirection is not possible. Redirection is possible.
We can define service() method. We can define doGet(), doPost(), doPut(),
doOption(), doTrace(), doHead() and
doDelete() method.
forward() sendRedirect()
It sends the request to resource that is It sends the request to resource that is
present in same server. present in same sever or different server.
It passes same request to next resource. It passes new request to next resource.
To forward the request we will use To forward the request we will use
RequestDispatcher object of sendRedrect() method of
HttpServletRequest. HttpServletResponse.
It works within the server. It works within the server and outside the
server.
47. What is the difference between spring framework and spring boot?
@Controller @RestController
It is used to develop spring MVC based It is used to develop RESTful Web Services.
applications.
It is a specialized version of @Component It is a specialized version of @Controller
annotation. annotation.
We need to use @ResponseBody in every It is a combination of @Controller and
handler method. @ResponseBody annotation.
It returns view in spring MVC. It does not return view.
It is added to Spring 2.5 version. It is added to Spring 4.0 version.
@RequestMapping @GetMapping
It is used to map request to controller It is used for mapping the request onto
methods. specific handler method.
It is a class level and method level It is a method level annotation.
annotation.
It is used for all kind of HTTP methods. It is used only for HTTP GET method.
@RequestBody @ResponseBody
This annotation indicates that Spring This annotation indicates that Spring should
should deserialize HttpRequest body(JSON) serialize java object into JSON or XML or
into Java object. simple text.
It is used with POST, PUT & PATCH It is used with GET method.
methods.
Application for incoming request data. Application for outgoing response data.
CrudRepository JpaRepository
It extends Repository interface. It extends CrudRepository and
PagingAndSortingRepository.
It contains methods like save(), findAll(), It contains extra methods related to JPA
delete(), count() And etc. such as delete records in batch and flushing
the data directly to the database.
It does not provide methods for It provides all the methods for implementing
implementing pagination and sorting. pagination and sorting.
application.properties application.yml
It follows non-hierarchical structure. It follows hierarchical structure.
We can configure only one spring profile. We can configure multiple spring profiles.
It is primarily used in java. It is used in many languages like Java,
python, Ruby and etc.
Supports key/val, but doesn’t support Supports key/val, basically map, List and
values beyond the string. scalar types (int, string etc.)
53. What is the difference between Spring Bean and POJO class?