Java Full Package Interview
Java Full Package Interview
Java Full Package Interview
Core Java
= = = = =
1. What is overloading and overriding?
???The process of defining more than one method with the same name with different
parameters in a class is called method overloading
??The process of defining a method in a supper and sub class with same signature
(with same parameter and with same name) is called method overriding.
what is the difference between class variables and instance variables?
Class variable means global variable which is used in class level(anywhere in the
class)
Instance variable means method level .
what is the difference between static binding and data binding?
1) Static binding in Java occurs during Compile time while Dynamic binding occurs
during Runtime.
2) private, final and static methods and variables uses static binding and bonded
by compiler while virtual methods are bonded during runtime based upon runtime
object.
3) Static binding uses Type(Class in Java) information for binding while Dynamic
binding uses Object to resolve binding.
3) Overloaded methods are bonded using static binding while overridden methods are
bonded using dynamic binding at runtime.
In java, exception is an event that disrupts the normal flow of the program. It is
an object which is thrown at runtime.
What is constructor?
Constructor is a special java member used to create an object and also used to
provide an initialization to the properties of an object.
What is the difference between throw and throws keyword?
Difference between Throw and Throws Keyword:-
?
Throw
Throws
1)
Java throw keyword is used to explicitly throw an exception.
Java throws keyword is used to declare an exception.
2)
Checked exception cannot be propagated using throw only.
Checked exception can be propagated with throws.
3)
Throw is used in method level.
Throws is used in class level.
4)
Throw is used within the method.
Throws is used with the method signature.
5)
You cannot throw multiple exceptions.
You can declare multiple exceptions e.g.
public void method()throws IOException,SQLException.
Eg:-
void m()throws ArithmeticException{
Collections:-
= = = = = =
Difference between comparator and comparable?
Comparable:-
? Comparable provide single sorting sequence, means we can sort the collection on
the basis of single element such as id or name or price etc.,
? Comparable affects the original class i.e., actual class is modified
? To sort the elements we can use the method is compareTo() method
? Collections.sort(List);{java.lang package}
Comparator:- ?
? Comparator provides multiple sorting sequence, means we can sort the collection
on the basis of multiple elements such as id, name and price etc.,
? Comparator doesn�t affect the original class i.e., actual class is not modified.
? To sort the elements we can use the method is compare() method.
? Collections.sort(List, Comparator);{java.util package}
Difference between equals and hashcode?
?HashCode is the unique identification of an object generating by JVM based on the
original base address.
?HashCode is a 32-bit positive random integer number.
?To get the JVM generated HashCode of an object we can use object class hashCode()
method (OR) System class identityHashCode() method
Object Class :-
?Public native int hashCode();
System Class:-
?public static native int identityHashCode(object obj);
Difference between hashmap and hash table?
Hashmap:-
? HashMap is a class given in 1.2
? hashMap is non Synchronized
? it is not thread safe because of single thread
? hashmap allows one null key and multiple null values
? hasmap is faster than hash table
? to synchronize the hashmap we can call the method as
collections.synchronizedMap(hashMap);
? HashMap inherits AbstractMap class
? HashMap is traversed by Iterator, means hashmap is get through iterator
? Iterator in hashmap is fail-fast.
HashTable:-
? hashTable is legacy class.
? hashTable is synchronized.
? It is thread safe because multi threaded object
? hashTable doesn�t allows any null key or values
? hashTable is slower than HashMap
? hashTable is internally synchronized and can�t be unsynchronized
? hashTable inherits from Dictionary class
? HashTable is traversed by enumerator and iterator, means hashtable data getting
through enumerator and iterator.
? Enumerator in hashTable is not fail-fast.
how to retrieve the data from hashmap and as key and value?
Map<String, List<String>>map=newHashMap<String, List<String>>();
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
String key = entry.getKey();
List<String> values = entry.getValue();
System.out.println("Key = " + key);
System.out.println("Values = " + values + "n");
}
Adv Java:-
= = = = =
Difference between servlet and JSP?
Servlet:
? Servlets are java programs that are already compiled which also creates dynamic
web content
? Servlets run faster compared to JSP
? Its little much code to write
? In mvc servlet act as a controller
?
JSP:-
? JSP is a webpage scripting language that can generate dynamic content
? JSP runs slow compared to servlets because it will convert JSP code into servlet
code
? It�s easier code in JSP than in java servlet
? In mvc JSP act as a view
? The advantages of JSP programming over servlets is that we can build custom tags
which can directly call java beans
? We can achieve functionality if JSP at client side by running javascript at
client side.
JSP life cycle?
? Translation of JSP page
? Compilation of JSP page
? Class ;loading(class file is loaded by the class loader)
? Instantiation (object of the generated servlet is created)
? Initialization(JSPinit() method is invoked by the container)
? Request processing (-JSPService() method is invoked by the container)
? Destroy (JSPDestroy() method in invoked by the container)
o JSP page is translated into servlet by the help of JSP translator.
o The JSP translator is a part of web server that is responsible to translate the
JSP page into servlet and gets converted into the .class files.
o Moreover all the processes that happens in servlet is performed on JSP late like
initialization, committing response to the browser and destroy.
What is JDBC?
?Jdbc is an api . it is used to communicate from java application to data base .
how many types of drivers in jdbc and what are they?
1. JDBC-ODBC bridge driver
2. Native-API driver (partially java driver)
3. Network Protocol driver (fully java driver)
4. Thin driver (fully java driver)
As displayed in the above diagram, there are three states of a servlet: new, ready
and end. The servlet is in new state if servlet instance is created. After invoking
the init() method, Servlet comes in the ready state. In the ready state, servlet
performs all the tasks. When the web container invokes the destroy() method, it
shifts to the end state.
What are the problems you are getting in the projects, which is resolved
successfully. how you are resolve it? explain with detail?
After logout -> press back buttorn-> then again active the session ->
Solution:-
?After login success redirect the request with a new url to another controller. For
this we can use redirect view.
And in JSP page we need write the session related code :-
<%
Response.setHeader(�cache-control�, �no-cache�);
Response.setHeader(�cache-control�, �no-store�);
Response.setDateHeader(�Expires�, 0);
Response.setHeader(�Pragma�, �no-cache�);
If(session==null || Session.getAttribute(�agented�)==null){
Response.setHeader(�Location�, �Login�);
Response.setStatus(301);
}
%>
How to get the list of data in a JSP page?
<table>
<c:forEach items="${userList}" var="user">
<tr>
<td>${user.userName}</user>
</tr>
</c:forEach>
</table>
(OR)
<c:forEach var="user" items="${listUsers.rows}">
<c:out value="${user.name}" />
<c:out value="${user.email}" />
<c:out value="${user.profession}" />
</c:forEach>
WebService:
= = = = = = =
Difference between soap and rest
SOAP is a protocol.?????REST is an architectural style.
SOAP stands for Simple Object Access Protocol.?REST stands for Representational
State Transfer.
SOAP can't use REST because it is a protocol.??REST can use SOAP web services
because it is a concept and can use any protocol like HTTP, SOAP.
SOAP uses services interfaces to expose the business logic. REST uses URI to expose
business logic.
JAX-WS is the java API for SOAP web services.?JAX-RS is the java API for RESTful
web services.
SOAP defines standards to be strictly followed.?REST does not define too much
standards like SOAP.
SOAP requires more bandwidth and resource than REST. ?REST requires less bandwidth
and resource than SOAP.
SOAP defines its own security.???RESTful web services inherits security measures
from the underlying transport.
SOAP permits XML data format only.??REST permits different data format such as
Plain text, HTML, XML, JSON etc.
SOAP is less preferred than REST.??REST more preferred than SOAP.
SpringCore:-
= = = = = =
Types of Framework?
?There are two types of framework.
1. Invasive Framework like Struts 1.X
2. Non-Invasive framework like Struts 2.x, Spring and Hibernate
Invasive framework means it always forced the developers to implement pre-defined
classes or interfaces given by framework.
Non � invasive framework means it doesn�t forced the developers to extend /
implements the predefined classes/ interfaces given by the freamework
The non � invasive framework are very light weight framework.
What is Java Bean?
? Java bean is used to store the data and send across the network.
? The java bean class contain private data members, public setters and getter
methods default constructor and implements serializable interface
What is Spring?
? Spring is a non-invasive framework.
? It is a light weight and open source framework.
? Spring is an application framework used to develop any kind java application like
stand alone application and enterprise application
? It is used develop any kind of logics in the project.
SpringMVC:-
= = = = = =
scope of spring bean classes?(Default : Singleton)
Singleton, prototype, session, request, global-session.
what is the Dispatcher Servlet, how it work, where we define it?
Front controller is a typical design pattern in the web applications development.
In this case, a single servlet receives all requests and transfers them to all
other components of the application. The task of the DispatcherServlet is send
request to the specific Spring MVC controller.
What is a Viewresolver?
ViewResolver is an interface to be implemented by objects that can resolve views by
name. There are plenty of ways using which you can resolve view names. These ways
are supported by various in-built implementations of this interface. Most commonly
used implementation is InternalResourceViewResolver class.
what is handler mapping?
When no handler mapping is explicitly specified in configuration,
BeanNameUrlHandlerMapping is created and used by default. From the article you
linked: "By default the DispatcherServlet uses the BeanNameUrlHandlerMapping to map
the incoming request. The BeanNameUrlHandlerMapping uses the bean name as the URL
pattern
what is dependency injection ?
injecting dependencies into a dependent is called dependency injection.
? Dependency Injection (DI) is a software design pattern that implements inversion
of control for resolving dependencies.
? An injection is the passing of a dependency to a dependent object that would use
it.
? DI is a process whereby objects define their dependencies. The other objects they
work with�only through constructor arguments or arguments to a factory method or
property�are set on the object instance after it is constructed or returned from a
factory method.
? The container then injects those dependencies, and it creates the bean. This
process is named Inversion of Control (IoC) (the bean itself controls the
instantiation or location of its dependencies by using direct construction classes
or a Service Locator).
? DI refers to the process of supplying an external dependency to a software
component.
Dependency Injection Performed Two Ways
What is autowired annotations? if we are not used the autowired annotation what
happened?
SpringBoot:-
= = = = = =
What is spring boot?
?Spring Boot is not a framework, it is a way to create any kind of application with
minimal or zero configurations.
It is an approach to develop spring based applications with less configurations.
Spring boot on top of spring framework .
It is reduce the development time and increasing productivity.
It is very useful for creating new applications with spring boot.
It is not recommended to convert old spring projects into boot application .
The framework takes an opinionated approach to configuration, freeing developers
from the need to define boilerplate configuration.
Spring Scheduling :-
?Scheduling jobs are used to execute same logic automatically without use
interaction based on date and time configurations
Hibernate:-
= = = = = =
2. what is the difference between first level cache and second level cache in
hibernate?
??first level cache is associated with session and the second level cache is
associated with SessionFactory. By default session is enabled.
States of hibernate?
Persistent Object has three life cycle states:-
1. Transient State: The Object not associated with session, that object is an
transient state(Before starting session or before saving the object into the DB).
Example every entity class is in transient state. In this state object is non-
transactional and not synchronized with record.
2. Persistent State: The Object associated with session, that object is an
persistent state(after starting session or getting object from DB). In this state
object is transactional and synchronized with database record.
3. Detached State: The object is not associated with session but present in data
base, that object is an Detached state(After session closing and object is stored
in the DB).
Difference between Session and SessionFactroy?
?Session:-
? Session is an interface and SessionImpl is an implemented class
? Session is related to First level cache
? Session is single threaded object
? Session is not thread safe object, short lived object
? It has the methods to perform persistence operations
? It is a factory for Transaction object.
?SessionFactory:-
? SessionFactory is an interface and SessionFactoryImpl is an implemented class
? SessionFactory is related to second level cache and it is an heavy weighted
object that has to be create once per application.
? SessionFactory is not a singleton
? Session factory is an long live multi threaded object
? Session factory is thread safe object
? SessionFactory is an ImmutableObject.
? For multiple sessions we can use single session factory object
? If we want to work multiple database than we need to create multiple session
factory objects , it means one session factory object is associated with one Data
base.
o We can work with multiple sessions in one session factory object.
Why SessionFactory is an heavyweight?
?Session factory encapsulates session object, connections, hibernate properties
caching and mappings.
How to invoke procedures in Hibernate?
1. To invoke Stored procedure in hibernate directly we can call following method
with native sql
?Session.createSQLQuery(�??Procedure---Name-??�);
2. NameNativeQuery in annotation and call with getNamedQuery() method
3. Sql-query in xml mapping file and call with getNamedQuery() method.
Something about criteria?
? Criteria api is provides to build queries dynamically at runtime without direct
string manipulations.
? Criteria is an alternative way to write a query without using hql
? We can execute select statement by using criteria, we can not executeUpdate,
delete statements using criteria.
Difference between Get and load methods in hibernate?
Get:-
? It always hit the database and return the real object.
? An object that represents the database row , not proxy, if no row found , it
returns null.
? It doesn�t supports lazy loading
Load:-
? It always returns a proxy object without hitting the database.
? In hibernate proxy is not a real object but working like a real object
? If no row is found then it will throws an objectNotFoundException.
? This method is supporting lazy loading
Difference between save and persist methods in hibernate?
Save():-
? The return type of save method is serializable object
? This method is used for inserting the record into DB
? It will return identifier value
Persist():-
? The return type of persist method is void.
? This method is used for inserting the record into DB
Do you know what is generators in hibernate, explain with detail?
Generators:-
? It is used to generate identifier value for persistence object, while saving the
object into the database.
? In this we have few generators are there like IncrementGenerator, Assigned
IdentityGenerator, SequenceGenerator, SequenceHiLoGenerator, ForeignGenerator and
etc..,
? If we want to implement our own generator then we can work with take any java
class and implement IdentifierGenerator and override generate() method .
? In this method our own business login based on the our requirement.
Tools:-
What is JIRA?
??JIRA is a bug tracking tool developed by Australian company Atlassian. It is used
for bug tracking, issue tracking and project management. The name JIRA is actually
inherited from Japanese word �Gojira� which means �Godzilla�.
??The basic use of this tool is to track issues, and bugs related to your software
and mobile apps. It is also used for project management. The JIRA dashboard
consists of many useful functions and features which make handling of issue easy.
what is Maven?
??? MAVEN is a application build tool and project management tool, it gives common
directory structure for applications
What is maven?
How to configure server local repository in maven pom.xml?
What is plugins in maven?
Can you write a code to configure location of the repository for maven?
SQL:-
= = =
joins in SQL?
A JOIN clause is used to combine rows from two or more tables, based on a related
column between them.
? (INNER) JOIN: Returns records that have matching values in both tables
? LEFT (OUTER) JOIN: Return all records from the left table, and the matched
records from the right table
? RIGHT (OUTER) JOIN: Return all records from the right table, and the matched
records from the left table
? FULL (OUTER) JOIN: Return all records when there is a match in either left or
right table
JSON:-
= = = =
What is json?
o JSON stands for JavaScript Object Notation.
o JSON is lightweight data-interchange format.
o JSON is easy to read and write than XML.
o JSON is language independent.
o JSON supports array, object, string, number and values.
Angular JS:-
= = = = = = = =
What is AngularJS?
? Angular js is a open source structural framework from google to develop dynamic
web applications
? Angular js is completely java script based framework client side programming
? It implements the MVC design pattern to develop the application
? Generally the MVC design pattern used by server side technology but angular js
provides a facility to use this MVC pattern in client side programming
? Angular js is not a library.
? Angular js provides its own runtime environment, compile process at client side.
How MVC design pattern is implemented in Angular JS:-
? MVC is a design pattern
? MVC can be used in any technology.
? Angular JS is also uses MVC design pattern to implement client side programming
? In MVC based applications development process is split into three modules
o Model
o View
o Controller
AngularJs Modules:-
Model:-
? Model is responsible for data storage
? It will be implemented by using Java Script, Variables , Arrays , Objects and
Array of Objects
? These data will be stored to view to display
View:-
? View is responsible for data presentation
? It can be implemented by using �html, css and AngularJS�directives(eg: ng-repeat)
? Views are bind with controller to get the data(ng-controller)
Controller:-
? Controller is responsible for data processing
? It act as mediator between view and model
? Controller will communicate with model to get the data
? Controller will transfer the data to view
Features or advantages of AngularJS:-
Data Binding:-
? Data binding is primary feature of AngularJS
? Data Binding can be implemented in 2 different ways
o One way data binding
o Two way data binding
? In data binding model variables, objects are bind with views
? First time in client side frameworks, AngularJS introduced this data binding
concept
? These features will reduce lot of client side code
Structural Programming :-
? AngularJS is structural framework
? It uses MVC structure to implement the application development
? AngularJS is client side MVC
? Due to this structure, we can devide application development into multiple
modules
o Model � View - Controller
? So , that we can reduce the complexity of the application development
Highly Testing:-
? AngularJs application are more comfortable top perform unit testing
? Unit testing is a process of testing the required portion of the application
? Due to MVC structure, we can easily test required module in the application
TDD Support(Test Driven Development):-
? It is the latest development process in which testers will provides the
guidelines to developers
? According to their guidelines developers will modify / update the application
development
? It is possible because of MVC structure at any point of time MVC based
applications are morte comfortable to update
? AngularJS applications are MVC so that it will be more comfortable TDD
Environment
Parallel Development :-
? In Angular JS applications, multiple programmers works parallel on controllers,
model and views
? We are creating in separate files to implement each one (views as *.html,
controller as *.js)
? This feature makes your application development more faster
? If you write view context and controller code is same file, only one programmer
can work at a time.
HTML as Template :-
? Angular JS uses existing html tags as template for views preparation
? Angular JS provides couple of directives to implement these templates
? At the time of execution AngularJS framework executes these templates to generate
actual content for view
Routing support for SPA(Single Page Application)
? SPA is used to develop the application single page
? In this applications only first time page will loaded from server
? Remaining all requests are processed at client side without loading the whole
page
? AngularJS provides special features to support routing in SPA
? Routing concept of AngularJS organizing multiple routes for multiple requests
with Single page
Client Side State Management:-
? One of the challenging task in SPA is state management
? AngularJS supports required options to manage the state between multiple requests
of SPA
? One of primary intention of Angular JS development is to support SPA development
Dependency Injection
? AngularJS Applications are strongly supports Dependency Injection
? It means developing the independent code and organize the development objects
based on the requirement
? Instead of depending on fixed set of objects /values , we can make application
modules are independent
? Dependency Injection is concept is involved in several concepts of AngularJS
o Eg:- creating modules, creating controllers, etc..,
Powered by Google:-
? Google maintained and support the Angular JS framework
? It organizes the Angular JS by group of Google team in order to address all
technical issues
? Google is one of the testable and world famous it organization
? From 2012 onwards, officially Angular JS is supported by Google
? Note:- Angular JS was initially developed by Miscko Hevery( He is Google
employee, he is author for several web related frameworks)
Execution Process of AJS:-
? Browser will load the html document
? AJS framework will load at the time of loading framework, it will create a global
object called �Angular�
? Angular object will compile and execute the AJS related elements
? AJS framework generates dynamic content based on the diurectives that we
involved.
AnularJS Directives:-
? In Angular JS application development will split into model, view and controller
? Views are developed by using html tags and AngularJS directives.
? Angular JS uses html as template and generate the dynamic content at runtime
? Directives plays very important role to generate dynamic content
What is directive in Angular JS
? Directives are used as html attributes
? Directive can extend the behavior of html tags
? Every view in Angular JS is depend on the directives
? Eg:-Ng-app, ng-model, ng-init, ng-controller, ng-show, ng-repeat, ng-view, ng-
hide, ng-if, ng-switch, etc..,
? Directives are prefix with �ng-�
? According to HTML, these user defined attributes are prefix with �data-�
? Eg:- data-ng-model, data-ng-app etc..,