Skip to main content

Posts

Hibernate Interview Questions

get() vs load() Hibernate session comes with different methods to load data from database. get and load are most used methods, at first look they seems similar but there are some differences between them. when we use get() to retrieve data that doesn’t exists, it returns null. It fires database query and throws org.hibernate.ObjectNotFoundException if there is no record found with the given identifier. It’s hibernate specific Runtime Exception, so we don’t need to catch it explicitly./li> Hibernate first level cache Hibernate first level cache is associated with the Session object. Hibernate first level cache is enabled by default and there is no way to disable it. However hibernate provides methods through which we can delete selected objects from the cache or clear the cache completely. Any object cached in a session will not be visible to other sessions and when the session is closed, all the cached objects will also be lost.
Recent posts

Spring Interview Questions

Inversion of Control As the name implies Inversion of control means now we have inverted the control of creating the object from our own using new operator to container or framework. Now it’s the responsibility of container to create an object as required. Dependency Injection The technology that Spring is most identified with is the Dependency Injection (DI) flavor of Inversion of Control. The Inversion of Control (IoC) is a general concept, and it can be expressed in many ways. Dependency Injection is merely one concrete example of Inversion of Control. When writing a complex Java application, application classes should be as independent as possible of other Java classes to increase the possibility to reuse these classes and to test them independently of other classes while unit testing. Dependency Injection helps in gluing these classes together and at the same time keeping them independent. What is dependency injection exactly? Let's look at these two words separately. ...

Java interview questions

Matcher vs Pattern Pattern : A compiled representation of a regular expression. Matcher : An engine that performs match operations on a character sequence by interpreting a Pattern. A regular expression, specified as a string, must first be compiled into an instance of this class. The resulting pattern can then be used to create a Matcher object that can match arbitrary character sequences against the regular expression. All of the state involved in performing a match resides in the matcher, so many matchers can share the same pattern. A typical invocation sequence is thus Pattern p = Pattern.compile("a*b"); Matcher m = p.matcher("aaaaab"); boolean b = m.matches(); A matches method is defined by this class as a convenience for when a regular expression is used just once. This method compiles an expression and matches an input sequence against it in a single invocation. The statement boolean b = Pattern.matches("a*b", "aaaaab"); is e...

Spring MVC Flow

Step 1: First request will be received by DispatcherServlet. Step 2: DispatcherServlet will take the help of HandlerMapping and get to know the Controller class name associated with the given request. Step 3: So request transfer to the Controller, and then controller will process the request by executing appropriate methods and returns ModeAndView object (contains Model data and View name) back to the DispatcherServlet. Step 4: Now DispatcherServlet send the model object to the ViewResolver to get the actual view page. Step 5: Finally DispatcherServlet will pass the Model object to the View page to display the result.
Struts Actions Forward Action :          In Struts MVC model, you have to go through the Action Controller to get a new view page. In some cases, you really just need to get a specified JSP page only, it's so stupid to create an action controller class which just forward the pate to you.        ForwardAction acts as bridge from the current view and pages it link to.ForwardAction uses the RequestDispatcher to forward to a specified web resource.This allow you to link to an action instead of directly to a jsp.  Used of Forward Action :- The ForwardAction class is useful when you’re trying to integrate Struts into an existing application that uses Servlets to perform business logic functions.  ForwardAction used to forward a request to another resource in your application, such as a Servlet that already does business logic processing or even another JSP page. Include Action :         Includ...

Struts Flow

Hi All,     Here are the simple 10 steps for how Struts Framework will work - It is a general question in many Interviews!     Initially let us assume /login.do is our action - the result will be successful login.  Here I will explain 15 steps how/what Struts framework will do ? As end user triggerred / clicked on /login.do - > as usual it is a web application - first it will look for Web.xml So here - Web.xml loading is the first step! In Web.xml it looks for *.do mapping and it finds the Struts plug-in  i.e., ActionServelt and it loads the same. Example of Mapping:    <servlet-name>action</servlet-name>    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>    .....    <servlet-mapping>    <servlet-name>action</servlet-name>    <url-pattern>*.do</url-pattern>    </servlet-mapping> As part of load...

OOPs Principles

Java Abstraction    Abstraction is the concept of exposing only the required essential characteristics and behavior with respect to a context. Abstraction Layers          When we see a nice car on the road as a casual onlooker, we get to see the whole picture. The car as a one single unit, a vehicle. We do not see the underlying complex mechanical engineering. Now consider we are going to a showroom to buy a car. What do we see now? We see four wheels, powerful engine, power steering etc. We see the car at high level components. But, there is so much inside it which gives the completeness to the car.     Now consider a mechanic, who is going to service the car. He will see one more level deeper with more level of information.     When we design software, we take the context. In the above example, we ask the question whether we are designing the software for a causal on looker or a buyer or a mechanic? Levels of ...