Java - J2EE Interview Preparation

Java - J2EE Interview Preparation
 Method overloading means having two or more methods with the same name but different signatures in the same scope. These two methods may exist in the same class or another one in base class and another in derived class.Generally, you should consider overloading a method when you have required same reason that take different signatures, but conceptually do the same thing.
Method overriding means having a different implementation of the same method in the inherited class. These two methods would have the same signature, but different implementation. One of these would exist in the base class and another in the derived class. These cannot exist in the same class.
Overriding methods
Overriding method definitionsIn a derived class, if you include a method definition that has the same name and exactly the same number and types of parameters as a method already defined in the base class, this new definition replaces the old definition of the method.
Explanation
A subclass inherits methods from a superclass. Sometimes, it is necessary for the subclass to modify the methods defined in the superclass. This is referred to as method overriding. The following example demonstrates method overriding.
  • Constructor
  •      It will invoke when an object is instantiated.
  •      Will have same name as class name.
  •      This will not have any return type. Not even void.
  •       It will be called only once when an object is created.
  •       It cannot be override.
  •       It can be overload.
  • Interface Vs Abstract class
  • Final 
    •  Members, Variables are final means Constant
    •  Method is final means cant override
    • Class is final means cant inherit i.e. cant extend
  •  
  • Finally
    • The code which needs to executed before even if any exception occurs or not.
  •  
  • Finalize
    • If any resource needs to be freeze before the object gets destroyed we can use finalize Garbage collector internally call finalize.
  •  
  • Inheritance
    • Taking the properties of another class
  •  
  • Encapsulation
    • Wrapping the member and method with the use of access specifiers to prevent from the outside use
  •  
  • Exceptions:  Throwable >>
    • Error (checked exception) compile time exception no such Method,class not found exception
    • Exception (unchecked exception) runtime exception Index out of bounce, Null pointer exception
  •  
  • Try :
    • Nested try is allowed try can have either catch or finally
    • Exception should be on top and IOException sub class should be in down that the order
    • try{}catch(IOException){}catch(Exception)
  •  
  • Catch  : Catches the exception and handle it.
  •  
  • Finally : It will execute the code no matter whether the exception is catches or not.
  •  
  • Throw : To manually throw an exception
  •  
  • Throws : Any exception that will throws by an system built-in exception.
  •  
  • Threads : Running multiple process in a sequence .
    • Threads shares same heap memory but different stack memory
    • Two ways of creating threads : Extends thread and  Implements Runnable Interface
    • What are the different states of a thread's life-cycle?Ans) The different states of threads are as follows:
      1) New – When a thread is instantiated it is in New state until the start() method is called on the thread instance. In this state the thread is not considered to be alive.
      2) Runnable – The thread enters into this state after the start method is called in the thread instance. The thread may enter into the Runnable state from Running state. In this state the thread is considered to be alive.
      3) Running – When the thread scheduler picks up the thread from the Runnable thread’s pool, the thread starts running and the thread is said to be in Running state.
      4) Waiting/Blocked/Sleeping – In these states the thread is said to be alive but not runnable. The thread switches to this state because of reasons like wait method called or sleep method has been called on the running thread or thread might be waiting for some i/o resource so blocked.
      5)      Dead – When the thread finishes its execution i.e. the run() method execution completes, it is said to be in dead state. A dead state can not be started again. If a start() method is invoked on a dead thread a run-time exception will occur.
    • Sleep Vs Wait ?
      1) wait is called from synchronized context only while sleep can be called without synchronized block.
      2) wait is called on Object while sleep is called on Thread.
      3) waiting thread can be awake by calling notify and notifyAll while sleeping thread can not be awaken by calling notify method.
      4) wait is normally done on condition, Thread wait until a condition is true while sleep is just to put your thread on sleep.
      5) wait release lock on object while waiting while sleep doesn’t release lock while waiting.
      6) The notifyAll() method must be called from a synchronized context.
    • What is garbage collection? What is the process that is responsible for doing that in java?
      Ans : Reclaiming the unused memory by the invalid objects. Garbage collector is responsible for this process.
    •  What kind of thread is the Garbage collector thread?
      Ans. It is a daemon thread.
    • What is a daemon thread?
      Ans : These are the threads which can run without user intervention. The JVM can exit when there are daemon thread by killing them abruptly.
  •  
  • Synchronization : It is the process of making only one thread to access the resource at a time by using synchronized(this) .
    • we can use synchronize block also to avoid the deadlock condition
  •  
  • String Vs StringBuffer : Read more about this here : http://www.krishnababug.com/2013/12/string-is-immutable-string-vs-string.html
  •  
  • Static class loading : Class will be loaded statically with new operator
  •  
  • Dynamic class loading : Class.forName(); string class name
  •  
  • Connection pool :
    • 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.
    • Opening/Closing database connections is an expensive process and hence connection pools improve the performance of execution of commands on a database for which we maintain connection objects in the pool.
    • It facilitates reuse of the same connection object to serve a number of client requests.
    • Every time a client request is received, the pool is searched for an available connection object and it's highly likely that it gets a free connection object.
    • It's normally used in a web-based enterprise application where the application server handles the responsibilities of creating connection objects, adding them to the pool, assigning them to the incoming requests, taking the used connection objects back, returning them back to the pool, etc.
  •  
  • Wrapperclass : As the name says, a wrapper class wraps (encloses) around a data type and gives it an object appearance. Wherever, the data type is required as an object, this object can be used. Wrapper classes include methods to unwrap the object and give back the data type. It can be compared with a chocolate. The manufacturer wraps the chocolate with some foil or paper to prevent from pollution. The user takes the chocolate, removes and throws the wrapper and eats it.
    • Example :
    • int k = 100;
    • Integer it1 = new Integer(k);
    • The int data type k is converted into an object, it1 using Integer class. The it1 object can be used in Java programming wherever k is required an object.
  •  
  • Session tracking :
    • By using URLRewriting
    • Using session object
    • Using cookies
    • Using hidden fields
  •  
  • Collections : Read this article for more information on collecitons http://www.krishnababug.com/2013/12/collections-java.html

  • Sorting list in collection - using sort method : refere this article for more information : http://www.krishnababug.com/2014/01/sorting-list-using-comparator.html
  •  
  • JSP Scripting elements :
    • JSP scripting elements enable you insert Java code into the servlet that will be generated from the current JSP page.
      • There are three forms:
        •     Expressions of the form <%= Java_expression%> that are evaluated and inserted into output, Example :Your hostname: <%= request.getRemoteHost() %>
        •     Scriptlets of the form <% java_code %> that are inserted into the servlets service method, and Example : <%
          String name = request.getParameter("name");
          out.println("name: " + name);
          %>
        •     Declarations of the form <%! Java_code %> that are inserted into the body of the servlet class, outside of any existing methods. Example : <%!
          public int getValue(){
              return 78;
              }
          %>
  •  
  • Difference between JSP & Servlet : Servlet is html in java ,     JSP is java in html .  JSP is a webpage scripting language that can generate dynamic content while Servlets are Java programs that are already compiled which also creates dynamic web content.In MVC, jsp act as a view and servlet act as a controller.
  •  
  • What is the servlet lifecycle?
    Ans:

    Instantiation and initialization
    The servlet engine  creates an instance of the servlet. The servlet engine creates the servlet configuration object and uses it to pass the servlet initialization parameters to the init() method. The initialization parameters persist until the servlet is destroyed and are applied to all invocations of that servlet.
    Servicing requests
    The servlet engine creates a request object and a response object. The servlet engine invokes the servlet service() method, passing the request and response objects.
    The service() method gets information about the request from the request object, processes the request, and uses methods of the response object to create the client response. The service method can invoke other methods to process the request, such as doGet(), doPost(), or methods you write.
    Termination
    The servlet engine stops a servlet by invoking the servlet's destroy() method. Typically, a servlet's destroy() method is invoked when the servlet engine is stopping a Web application which contains the servlet. The destroy() method runs only one time during the lifetime of the servlet and signals the end of the servlet.
    After a servlet's destroy() method is invoked, the servlet engine unloads the servlet, and the Java virtual machine eventually performs garbage collection on the memory resources associated with the servlet.
  •  
  • Design patterns : Refer this link for more information on designpatterns : http://www.krishnababug.com/2014/01/design-pattern-interview-questions.html
  •  
  • Webservices :
    • Web services are Web based applications that use open, XML-based standards and transport protocols to exchange data with clients. Web services are developed using Java Technology APIsWeb services are Web based applications that use open, XML-based standards and transport protocols to exchange data with clients. Web services are developed using Java Technology APIs.
    • Web services are client and server applications that communicate over the World Wide Web’s (WWW) HyperText Transfer Protocol (HTTP). As described by the World Wide Web Consortium (W3C), web services provide a standard means of interoperating between software applications running on a variety of platforms and frameworks. Web services are characterized by their great interoperability and extensibility, as well as their machine-processable descriptions, thanks to the use of XML.
  • Simple Webservice code for online Webservice Stock Quote 
  •  
  • Hibernate :
    • Hibernate is an object-relational mapping (ORM) library for the Java language, providing a framework for mapping an object-oriented domain model to a traditional relational database. Hibernate solves object-relational impedance mismatch problems by replacing direct persistence-related database accesses with high-level object handling functions.
    • Hibernate's primary feature is mapping from Java classes to database tables (and from Java data types to SQL data types). Hibernate also provides data query and retrieval facilities. It generates SQL calls and relieves the developer from manual result set handling and object conversion. Applications using Hibernate are portable to supported SQL databases with little performance overhead
    • If you are designing the database schema and your domain objects afresh.
    • You envision that your domain objects and your schema will be in sync, for example an automobile vendor application where your vehicle objects are likely to be close to your table structures. Just an example.
    • You really want to use an ORM and tie your objects closely to schema.
    • Want to use a ORM framework to handle connections etc.
  •  
  • Struts :
    • Apache Struts is a web page development framework and an open source software that helps developers build web applications quickly and easily. Struts combines Java Servlets, Java Server Pages, custom tags, and message resources into a unified framework.
    • Struts is based on famous MVC design pattern.The role played by Structs is controller in Model/View/Controller(MVC) style. The View is played by JSP and Model is played by JDBC or generic data source classes. The Struts controller is a set of programmable components that allow developers to define exactly how the application interacts with the user.
    • core classes of Struts: Action, ActionForm, ActionServlet, ActionMapping, ActionForward are basic classes of Structs.
    • configuration files used in Struts : ApplicationResources.properties , struts-config.xml .These two files are used to bridge the gap between the Controller and the Model.

  • JDBC : http://www.krishnababug.com/2014/02/jdbc-java-interview-questions.html
  • SQL Injection : http://www.krishnababug.com/2014/02/sql-injection-java.html
  • xcfd
 References : [1] [2] [3] [4]


    0 comments to "Java - J2EE Interview Preparation"

    Post a Comment

    Who ever writes Inappropriate/Vulgar comments to context, generally want to be anonymous …So I hope U r not the one like that?
    For lazy logs u can at least use Name/URL option which don’t even require any sign-in, good thing is that it can accept your lovely nick name also and URL is not mandatory too.
    Thanks for your patience
    ~Krishna(I love "Transparency")
    వీలయితే నాల్గు పోస్టులు ...కుదురితే ఒక కామెంటూ ...

    Translate

    Enter your email address:

    Buffs ...

    Visitors


    hits counter
    View My StatsCheck Google Page Rank

    Add to Google Reader or Homepage

    Bookmark and Share

    Tags


    Powered by WidgetsForFree