Tech Mahindra Java interview Questions

Q : What are pass by reference and passby value?
Ans : Pass by Reference means the passing the address itself rather than passing the value and pass by value means passing a copy of the value as an argument.
Q : Difference between Vector and ArrayList?
Ans : 1) Java Vector class is internally synchronized and ArrayList is not.
  2) Arraylist has no default size while vector has a default size of 10.    
Q : How can you force garbage collection?
Ans : We can't force GC, but could request it by calling System.gc(). JVM does not guarantee that GC will be started immediately.
Q : How to do memory management in JAVA?
Ans: In Java, memory is allocated only to objects. There is no explicit allocation of memory, there is only the creation of new objects.
 The Garbage collector reclaims the unused memory occupied by an object once it determines that object is no longer accessible. 
Q : What is the use of synchronization in java?
Ans: Synchronization is a feature by which only one thread can access a resource in a particular time of instance. No other thread can interrupt for that resource.
Q : What is the difference between an Interface and an Abstract class?
Ans : An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract. An interface has all public members and no implementation. An abstract class is a class which may have the usual flavors of class members (private, protected, etc.), but has some abstract methods.
Q : What is the difference between executeupdate() and executequery() in JDBC ?
Ans : 1) executeUpdate() is used for inserting,deleting,modifying,update the data.executeQuery() is used for select statement for displaying tha data..
 2)return type of executeUpdate() method is "int" where as return type of executeQuery() method is "resultset" obj.
Q : what is connection pooling?
Ans: It's a technique to allow multiple clinets to make use of a cached set of shared and reusable connection objects providing access to a database.
Q : What’s the difference between load() and get()? 
Ans : Only use the load() method if you are sure that the object exists. load() method will throw an exception if the unique id is not found in the database. 
If you are not sure that the object exists, then use one of the get() methods. get() method will return null if the unique id is not found in the database. 
Q : If you want to see the Hibernate generated SQL statements on console, what should we do?
Ans: <property name="show_sql">true</property>
Q : What are Callback interfaces? 
Ans :Callback interfaces allow the application to receive a notification when something interesting happens to an object—for example, when an object is loaded, saved, or deleted. Hibernate applications don't need to implement these callbacks, but they're useful for implementing certain kinds of generic functionality.
Q : What are the types of inheritance models in Hibernate? 
Ans : 1) Table per class hierarchy 2) Table per subclass 3) Table per concrete class
Q : What is a Trigger?
Ans : A trigger is a SQL procedure that initiates an action when an event (INSERT, DELETE or UPDATE) occurs. Triggers are stored in and managed by the DBMS. 
Q : Difference forward() and response.sendRedirect()?
Ans: Forward : when forward is used server forwards the request to the new url and the control stays on the same page. in other words it just forward the request to new url and come back fomr where forward is called.
sendRedirect : sendRedirect forward the request to url as new request and the cotrol goes to the destination page and never come back to the calling page.
Q : What is the difference between the getRequestDispatcher(String path) method of ServletRequest and ServletContext ?
Ans : The ServletContext.getRequestDispatcher method takes a String argument describing a path within the scope of the ServletContext.
The ServletContext.getNamedDispatcher method takes a String argument indicating the NAME of a servlet known to the ServletContext.
Q : What is the difference between request.getParameter() and request.getAttribute()? 
Ans : GetAttribute() returns an object so when ever we use a getAttribute() we have to cast the return type that is we have to convert it to the required type like string or int.getParameter always returns a string.



Please share your faced interview questions by faqs@javastuff.in
which can help job seekers as well as java learners. 






Enter your email address to get our daily JOBS & INTERVIEW FAQ's Straight to your Inbox.

Make sure to activate your subscription by clicking on the activation link sent to your email