Friday, 14 September 2012

Java Training: -What do you mean by Bootstrap, Extension and System Class loader?

There three types of class loaders:-
  • Bootstrap Class loader also called as primordial class loader.
  • Extension Class loader.
  • System Class loader.
Let’s now try to get the fundamentals of these class loaders.

Bootstrap Class loader

Bootstrap class loader loads those classes those which are essential for JVM to function properly. Bootstrap class loader is responsible for loading all core java classes for instance java.lang.*, java.io.* etc. Bootstrap class loader finds these necessary classes from “jdk/jre/lib/rt.jar”. Bootstrap class loader cannot be instantiated from JAVA code and is implemented natively inside JVM.

Extension Class loader

The extension class loader also termed as the standard extensions class loader is a child of the bootstrap class loader. Its primary responsibility is to load classes from the extension directories, normally located the “jre/lib/ext” directory. This provides the ability to simply drop in new extensions, such as various security extensions, without requiring modification to the user's class path.

System Class loader

The system class loader also termed application class loader is the class loader responsible for loading code from the path specified by the CLASSPATH environment variable. It is also used to load an application’s entry point class that is the "static void main ()" method in a class.

See the following video on overview and working of Servlets in Java: -



Click to get Java Training

Regards,

Get more Java Training from author’s blog

Saturday, 8 September 2012

Java Training: - Mention the concept of local interfaces?

One of the biggest issues of creating objects using home interface is performance. Below are the steps which follow when you call the EJB object:-
  • JAVA client calls the local stub.
  • Stub marshal the values in to some other form which the network understands and sends it to the skeleton.
  • Skeleton then de-marshals it back to a form which is suitable for JAVA.
  • Skeleton then calls the EJB object and methods.
  • EJB object then does object creation, connection pooling, transaction etc.
  • Once EJB object calls the bean and the bean completes its functionalities. All the above steps must again be repeated to reach back to the JAVA client.
So you can easily guess from the above step that its lot of work. But this has been improved in EJB 2.0 using Local objects. Local objects implement local interface rather than using remote interface. Just to have a comparison below are the steps how the local object works.
  • JAVA client calls the local object.
  • Local object does connection pooling, transactions and security.
  • It then passes calls the bean and when bean completes its work it returns the data to the Local object who then passes the same to the end client.
See the following video on Introduction to EJB in Java: -



Click to get Java Training

Regards,

Get more Java Training from author’s blog

Wednesday, 5 September 2012

Java Training: - Show different types of resultset?

“ResultSet” is an object that contains the results of SQL query. That means it contains the rows that satisfy the conditions of the query.

There are three basic types of resultsets:-

Forward-only results set

These types of resultset are non-scrollable and moves only forward.

Scroll-insensitive set

Resultset is scrollable so the cursor can move forward, backward, to a particular row etc.
While the resultset is open it does not show any changes done to the underlying database.

Scroll-sensitive set
Resultset is scrollable so the cursor can move forward, backward, to a particular row etc.
Resultset is sensitive to changes when it is open or used. That means if any values are modified in the database it’s propagated to the resultset.

See the following video on Factory Pattern in Java: -



Click to get Java Training

Regards,

Get more Java Training from author’s blog

Monday, 3 September 2012

Java Training: - Explain “ResultSet”, “RowSet”, “CachedRowset”, “JdbcRowset” and “WebRowSet” relation ship?

Below are the major points of difference:-
  • “ResultSet” is a connected architecture while “RowSet” is a disconnected architecture.
  • As “ResultSet” is a connected architecture we cannot serialize the object while “RowSet” can be serialized.
  • “RowSet” object is a Java bean while “ResultSet” is not. In the below diagram you can see “RowSet” interface also derives from “BaseRowSet” interface. “BaseRowSet” interface has all the ingredients to make it a Java bean.
Below diagram shows the complete relationship between all the interface and classes.


Figure: - Interface diagram for “Resultset” and “RowSet”
As "RowSet" is a disconnected from database it need to maintain Meta data for columns. "RowSet" can also provide scrollable resultsets or updatable resultsets even if the JDBC driver is not supporting the same. Java client can get a “RowSet” manipulate the same and finally send all the results to the database at one go. Sun has provided three implementation of “RowSet” as below:-

CachedRowSet: - Disconnected rowset always keeps the data in memory. It is scrollable and can also be serialized. It’s an ideal choice where we want to pass data between tiers or to do batch updates. "CachedRowSet" are disconnected so can be used for huge number of updates. Get the "CachedRowSet" object manipulate all your data and send the whole bunch of manipulated data in on go to the Database.

JDBCRowSet: - It’s opposite to "CachedRowSet". It maintains a connection to the database while the client has reference to it. So it’s a connected architecture as compared to CachedRowSet.

WebRowSet :- "WebRowSet" is a extension of "CachedRowSet". But the added feature is it can produce XML presentation of the data cached. If you are thinking of exposing your data through web services or to provide data to thin client which are written in different language other than JAVA. Best bet if you want to pass data in XML format over HTTP protocol.

See the following video on FlyWeight Pattern in Java: -



Click to get Java Training

Regards,

Get more Java Training from author’s blog

Wednesday, 29 August 2012

Java Training: - Differences between JNDI context, Initial context, session context and EJB context?


JNDI context
JNDI Context Provides a mechanism to lookup resources on the network

Initial context
Initial Context constructor provides the initial context.

Session context
Session Context has all the information a session bean would require from the container

Entity Context
Entity Context has all the information that an Entity bean would need from a container

EJB context
EJB Context contains the information that is common to both the session and entity bean

See the following video on EJB (Enterprise Java Beans): -



Click to get Java Training

Regards,

Get more Java Training from author’s blog

Wednesday, 22 August 2012

Java Training: - Elaborate stateful and stateless session bean?

Stateful Session bean:-
  • Stateful session bean maintain the state of the conversation between the client and itself
  • When the client invokes a method on the bean the instance variables of the bean may contain a state but only for the duration of the invocation
  • implements the javax.ejb.SessionBean interface and is deployed with the declarative attribute "stateful"
Stateless session bean:-
  • A stateless session bean is an enterprise bean that provides a stateless service to the client.
  • Conceptually, the business methods on a stateless session bean are similar to procedural applications or static methods; there is no instance state, so all the data needed to execute the method is provided by the method arguments
  • implements the javax.ejb.SessionBean interface and is deployed with the declarative attribute "stateless
See the following video on Factory Pattern in Hibernate: -



Click to get Java Training

Regards,

Get more Java Training from author’s blog

Saturday, 18 August 2012

Java Training: - Mention ORM and different levels of ORM quality?

ORM: -

ORM stands for Object/Relational mapping which is mainly used to remove the difference between object oriented and relation model

Different levels of ORM quality: -
  • Pure relational entire application, including the user interface, is designed around the relational model and SQL-based relational operations
  • Light object mapping The entities are represented as classes that are mapped manually to the relational tables
  • Medium object mapping The application is designed around an object model. The SQL code is generated at build time. And the associations between objects are supported by the persistence mechanism, and queries are specified using an object-oriented expression language
  • Full object mapping supports sophisticated object modeling: composition, inheritance, polymorphism and persistence
See the following video on Batch Processing in Hibernate: -



Click to get Java Training

Regards,

Get more Java Training from author’s blog

Monday, 13 August 2012

Java Training: - How will you explain marshaling and unmarshalling?

Marshaling: -

Marshalling creates an XML document from a content tree.

To marshal a content tree,
  • Create a JAXBContext object
  • Create a Marshaller object (Marshaller marshaller = jaxbContext.createMarshaller();)
  • Set required properties using setProperty method of Marshaller marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, new Boolean(true));
  • Call the marshal method marshaller.marshal(collection, new FileOutputStream("jaxbOutput.xml"));
Unmarshalling: -

Unmarshalling an XML document means creating a tree of content objects that represents the content and organization of the document.

To unmarshal an XML document,
  • Create a JAXBContext object(JAXBContext jaxbContext = JAXBContext.newInstance("package name ");
  • Create an Unmarshaller object Unmarshaller unmarshaller = jc.createUnmarshaller();
  • Call the unmarshal method unmarshaller.unmarshal(new File( "xml name"));
  • Use the get methods in the schema-derived classes to access the XML data
See the following video on Introduction to Hibernate and it concepts in Java: -



Click to get Java Training

Regards,

Get more Java Training from author’s blog

Saturday, 11 August 2012

Java Interview Questions: - How will you explain navigation rules and how to declare the same?

Navigation rules tells JSF implementation which page to send back to the browser after a form has been submitted
The above configuration says that navigation will happen to page2.jsp if the action eventAction happens inside page1.jsp

See the following video on Getting Started with Servlet in Java: -



Click to get Java Interview Questions

Regards,

Get more Java Interview Questions from author’s blog

Thursday, 9 August 2012

Java Training: - Differences between DTDs and Schema?

Schema
DTD
Schema document is an XML document i.e., the structure of an XML document is specified by another XML documentDTDs follow SGML syntax
supports variety of data types similar to programming languageIn DTD everything is treated as text
creating relationship among elements is possibleThis is not possible in DTD without invalidating existing documents
Grouping of elements and attributes are possible to form a single logical unitGrouping of elements and attributes is not possible in DTD
it is possible to specify an upper limit for the number of occurrences of an elementIt is not possible to specify an upper limit of an element in DTDs

See the following video on overview on Servlets in Java: -



Click to get Java Training

Regards,

Get more Java Training from author’s blog

Friday, 3 August 2012

Java Training: - Elaborate Bean lifecycle in Spring framework?

  • The spring container finds the beans definition from the XML file and instantiates the bean
  • Using the dependency injection, spring populates all of the properties as specified in the bean definition
  • If the bean implements the BeanNameAware interface, the factory calls setBeanName() passing the bean’s ID
  • If the bean implements the BeanFactoryAware interface, the factory calls setBeanFactory(), passing an instance of itself
  • If there are any BeanPostProcessors associated with the bean, their post ProcessBeforeInitialization() methods will be called
  • If an init-method is specified for the bean, it will be called
  • Finally, if there are any BeanPostProcessors associated with the bean, their postProcessAfterInitialization() methods will be called
See the following video on Inheritance between beans and Spring in Java: -



Click to get Java Training

Regards,

Get more Java Training from author’s blog

Tuesday, 31 July 2012

Java Interview Questions: - Can you explain blocking Queues in Java?

The java.util.concurrent package contains a set of synchronized Queue interfaces and classes. Blocking Queue extends Queue with operations that wait for the queue to become nonempty when retrieving an element and for space to become available in the queue when storing an element. This interface is implemented by the following classes:
  • LinkedBlockingQueue — an optionally bounded FIFO blocking queue backed by linked nodes
  • ArrayBlockingQueue — a bounded FIFO blocking queue backed by an array
  • PriorityBlockingQueue — an unbounded blocking priority queue backed by a heap
  • DelayQueue — a time-based scheduling queue backed by a heap
  • SynchronousQueue — a simple rendezvous mechanism that uses the BlockingQueue interface
See the following video on Front Controller in Java: -



Click to get Java Interview Questions

Regards,

Get more Java Interview Questions from author’s blog

Saturday, 21 July 2012

Java Interview Questions: - Show Passivation and Activation in EJB?

When we are dealing with stateful session beans we need to store the client conversation of the bean so that it can be available in client’s next request. But when we talk about server it has limited resources. If the conversation of the bean is large then the server can run out of resource. So in order to preserve resources EJB server swaps this conversational data in memory to hard disk thus allowing memory to be reclaimed. This process of saving the memory data to hard disk is called as “Passivation”. Now when the client comes back the conversational data is again swapped from the hard disk to the bean. This process is called as “Activation”. The container informs the bean that its about to passivate or activate using the "ejbPassivate()" and "ejbActivate()" methods.

See the following video on Getting started with EJB in Java: -



Click to get Java Interview Questions

Regards,

Get more Java Interview Questions from author's blog

Thursday, 19 July 2012

Java Training: -Elaborate JAXR?

JAXR is a standard API used to access XML registries from the JAVA platform. An XML registry is a listing of services available on the Web. JAXR provides APIs for the client applications to query the registries, or publish their own information in them using the registry standards.

It acts as a pluggable layer that allows access to registries implemented on different standards, such as Universal Description Discovery and Integration (UDDI) and Electronic Business using eXtensible Markup Language (ebXML). You can see from the figure below how JAXR API interacts with the respective provider to get data.


Figure: - JAXR architecture
See the following video on Overview and working of Servlets: -



Click to get Java Training

Regards,

Get more Java training stuffs from author's blog

Saturday, 14 July 2012

Java Training: -Mention about SOAP?

SOAP is an XML-based protocol that enables software components and applications to communicate with one another. It defines rules to translate application and platform-specific data into the XML format. SOAP allows you to communicate with the Web Service using protocols such as HTTP and Simple Mail Transfer Protocol.

SOAP has three main sections:-

Envelope: Contains elements such as the header and body of the SOAP messaging structure. It also includes an encodingStyle attribute that specifies the representation of data in messages.

Header: Encapsulates extended messages without adding or modifying the standard message flow.

Body: Contains Web application-specific data. It defines the purpose of sending the message. The body element should be the first element under the envelope element if there is no header element.

Below is a snippet of a sample SOAP header.

See the following video on Web service in Java: -



Click to get Java Training

Regards,

Get more Java training stuffs from author's blog

Wednesday, 11 July 2012

Java Training: - What are the different scopes of an object can have in a JSP page?

There are four scope which an object can have in a JSP page:-

Page Scope

Objects with page scope are accessible only within the page. Data only is valid for the current response. Once the response is sent back to the browser then data is no more valid. Even if request is passed from one page to other the data is lost.

Request Scope

Objects with request scope are accessible from pages processing the same request in which they were created. Once the container has processed the request data is invalid. Even if the request is forwarded to another page, the data is still available though not if a redirect is required.

Session Scope

Objects with session scope are accessible in same session. Session is the time users spend using the application, which ends when they close their browser or when they go to another Web site. So, for example, when users log in, their username could be stored in the session and displayed on every page they access. This data lasts until they leave the Web site or log out.

Application Scope

Application scope objects are basically global object and accessible to all JSP pages which lie in the same application. This creates a global object that's available to all pages. Application scope variables are typically created and populated when an application starts and then used as read-only for the rest of the application.

See the following video on getting started with servlet: -



Click to get Java Training

Regards,

Get more Java training stuffs from author's blog

Wednesday, 4 July 2012

Java Training: - What do you mean by four essential properties of a transaction?

A transaction is proper if it fulfils ACID properties. These four properties are as below:-

Atomicity: - This rule states if one part of the transaction fails then the entire transaction should fail.

Consistency: - This rule states that only valid data should be written to database. Any invalid data should roll back the whole transaction. If the transaction executes successfully then it should take database from one state which is consistent to other state which is also consistent.

Isolation: - This rule states that multiple transactions occurring at the same time should not impact each other. If “shiv” and “raju” is withdrawing and depositing money both the transaction should operate in an isolated manner. Isolation ensures that transactions do not affect each other.

Durability: - This rule states that any transaction committed should not be lost. It’s ensured through database backups and transaction logs in database. So that if there is a problem at any point we can restore back to the original state.

See the following video on Service Loader in Java : -



Click to get Java Training

Regards,

Get more Java training stuffs from author's blog

Thursday, 28 June 2012

Java Training: - How do you implement inheritance in Java?

To understand this better lets do a small project to get the actual feel of the same.

Below is the project structure of the “Inheritance” project. It has the three classes:-

• “ClsAdd.java”
This class has a basic subroutine which adds two numbers.

• “ClsSpecialAdd.java”
This class inherits from “ClsAdd.java” and overrides the subroutine which does the basic addition. It changes the basic addition functionality a bit by adding the two numbers but also adds up an extra adjustment value “20”.

• “ClsRun.java”
This is the class which has the “public static void main (String [] args)” method. It’s the main class which will run the whole show by creating the objects of “ClsAdd” and “ClsSpecialAdd” and executing the “Add” method.

Figure: - Project File structure of inheritance structure

Figure: - Inheritance in Action


When you run the project you can see two outputs one from the parent class and second from the child class with the adjustment value added up. So the child class has made the parent add class more specialized.

Figure: - Output from Inheritance Project


See the following video on Inheritance between beans and Springin Java: -



Click to get Java Training

Regards,

Get more Java training stuffs from author's blog

Monday, 25 June 2012

Java Training: - Elaborate Page directives?

Page directive is used to define page attributes the JSP file. Below is a sample of the same:-


To summarize some of the important page attributes:-

Import: - Comma separated list of packages or classes, just like import statements in usual Java code.

Session: - Specifies whether this page can use HTTP session. If set "true" session (which refers to the javax.servlet.http.HttpSession) is available and can be used to access the current/new session for the page.

If "false", the page does not participate in a session and the implicit session object is unavailable.

buffer :- If a buffer size is specified (such as "50kb") then output is buffered with a buffer size not less than that value.

isThreadSafe :- Defines the level of thread safety implemented in the page. If set "true" the JSP engine may send multiple client requests to the page at the same time. If "false" then the JSP engine queues up client requests sent to the page for processing, and processes them one request at a time, in the order they were received. This is the same as implementing the javax.servlet.SingleThreadModel interface in a servlet.

errorPage: - Defines a URL to another JSP page, which is invoked if an unchecked runtime exception is thrown. The page implementation catches the instance of the Throwable object and passes it to the error page processing.

See the following video on overview Service Loader in Java: -



Click to get Java Training

Regards,

Get more Java training stuffs from author's blog

Thursday, 21 June 2012

Java Training: -Elaborate implicit EL (Expression Language) objects in JSP?

Following are the implicit EL (Expression Language) objects:-

Page Context: The context for the JSP page.

Provides access to various objects for instance:-

servletContext: The context for the JSP page's servlet and any web components contained in the same application
.
session: The session object for the client.

request: The request triggering the execution of the JSP page.

response: The response returned by the JSP page. See Constructing Responses.

In addition, several implicit objects are available that allow easy access to the following objects:

param: Maps a request parameter name to a single value

paramValues: Maps a request parameter name to an array of values

header: Maps a request header name to a single value

header Values: Maps a request header name to an array of values

cookie: Maps a cookie name to a single cookie

initParam: Maps a context initialization parameter name to a single value

Finally, there are objects that allow access to the various scoped variables described in Using Scope Objects.

page Scope: Maps page-scoped variable names to their values

request Scope: Maps request-scoped variable names to their values

session Scope: Maps session-scoped variable names to their values

application Scope: Maps application-scoped variable names to their values

For instance the below snippet will indentify the browser used by the client.

See the following video on overview and working of Servlets: -



Click to get Java/Servlets Training

Regards,

Get more Java/Servlets training stuffs from author's blog

Thursday, 14 June 2012

Java Training: -Explain Garbage collector in Java?

Garbage collection is the process of automatically freeing objects that are no longer referenced by the program. This frees the programmer from having to keep track of when to free allocated memory, thereby preventing many potential bugs. Thus making programmers more productive as they can now put more effort in coding rather than worrying about memory management.

The only disadvantage of garbage collector is it adds overheads. Because the JVM (Java virtual machine) has to keep a constant track of the objects which are not referenced and then free these unreferenced objects on fly. This whole process has a slight impact on the application performance. But garbage collector has a good algorithm and it runs in its own thread thus having a least impact on the application performance but still it has some impact.

See the following video on Service Loader in java: -



Click to get Java Training

Regards,

Get more Java training stuffs from author's blog

Saturday, 26 May 2012

Service Loader, a new feature in Java

What is Service loader in Java?


Service Loader is a new class added in Java 1.6 and it provides good means of developing loosely coupled application.
It allows us to link an interface to a particular implementation at run time based on configuration thus providing us with loose coupling
It also provides a sort of Dependency Injection (DI) though not as powerful as Spring framework but does provide a good facility in case you don’t require a full blown DI feature.
Also various design patterns like Strategy can be easily done with the help of Service Loader.


What is the Logic behind Service Loader?


Each interfaces present in the application is called service since they define what can be done but not how it can be done.
A single interface can have multiple implementations and each implementation is called service provider
Service Loader makes use of both the above concepts and to link a particular implementation with interface i.e. link a particular service with a service provider makes use of provider configuration file


Provider configuration file:


This file contains mapping of interface to implementation and is present in the resource directory META-INF/services
Within this file, contains a list of fully-qualified binary names of concrete provider classes, one per line and is compliant with UTF -8


Not clear yet, See example to make things crisp and clear


Let consider Account Interface as shown, We can see it has following methods
  • getType()
  • setType(String type)
  • getBalance()
  • getBranch()
  • setBalance(int balance)
  • setBranch(String branch)
Let say we have two implementing classes SavingAccount and CurrentAccount

We will create this example using Eclipse IDE. Following are the steps: -

1) Create a Java Project as shown. Give project name as ServiceLoaderEg


Figure: -


Figure: -

2) Create new package com.questpond.eg


Figure: -

3) Create interface Account within the above created package with discussed method signatures


Figure: -

4) Create class SavingAccount which implements Account. The implementation is shown


Figure: -

5) Similarly CurrentAccount


Figure: -

6) Create a folder META-INF within the project and within it create services folder. Within this create a file and name of the file should match fully qualified name of Account interface i.e. com.questpond.eg.Account


Figure: -

7) Within the file write the name of implementation you want to use . In the above example we have used the implementation as CurrentAccount. Again fully qualified name of CurrentAccount is needed to be put within the file. Same is shown in above figure

8) Create a main class called Main and within it write the following code


Figure: -

As we see in the screen shot we are making use of static load method of ServiceLoader and we have passed the class as interface type i.e. Account. The act of mapping this interface to corresponding implementation is done via the file which we created with META-INF/services folder

9) On running the above code we get following output


Figure: -

As we see from the screen shot the CurrentAccount implementation is used which is evident by the Sys out method printed and the type of Account

Note: Before running the example please copy META-INF folder completely within bin folder of eclipse
10) From the above example we see that the invoking class is not dependant directly on the Implementation and just depends on interface and the mapping between them is done by using ServiceLoader. Thus we achieve loosely coupled application

Application areas:



Many times when development happens cross team it is quite possible the team may have dependency on the code each other develop. So some classes if not completely developed can affect the dead lines of project as well testing. To do up with this we can create Mock objects corresponding to each classes which has not been fully developed and the mapping can be done by using ServiceLoader. Once the class is completely developed we can replace the Mock object with actual implementation via again Service Loader Thus we achieve Loosely coupled application as well Dependency Injection.

Download Source Code for Service Loader in Java.

Video on Service Loader:



Also see the following video which will clear your picture more on Service Loader.




More articles and videos coming:



I am going to write more articles as well as record more videos on
Java interview questions and new rich features like concurrent collections. Semaphores, Executors and so on in coming time. So stay tuned


Thursday, 17 May 2012

Java Training: -Show JDBC (Java Database Connectivity) and its different section?

JAVA interacts with database using a common database application programming interface called as JDBC. JDBC allows a developer to write applications that is database independent. So the developer will be interacting with JDBC API rather than getting in to complications of the database.JDBC allows you to write Java code, and leave the platform (database) specific code to the driver. JAVA was designed to be platform independent and JDBC takes java one step ahead making java database code database independent. That means if you use JDBC for connectivity for SQL Server you can run the same code without changing for ORACLE.


Figure: - JDBC as a layer
Different sections in JDBC: -
There are four major components in JDBC. Below is the diagram which shows the four major sections and the way they interact to achieve the final “resultset”.

Figure: - JDBC in detail

Driver manager section creates the connection object. Connection object create the statement object with the required SQL which is then executed against the database. And finally database gives the result back in the resultset.

See the following starter video on Servlet: -



Click to get Java Training

Regards,

Get more Java training stuffs from author's blog

Saturday, 5 May 2012

Java Training: -How will you explain taglib directives?

Taglib are also termed as JSP tag extensions. They provide a way of encapsulating reusable functionality on JSP pages. One of the biggest drawbacks of scripting environments such as JSP is that it's easy to get carried away without thinking about how it will be maintained and grown in the future. For example, the ability to generate dynamic content by using Java code embedded in the page is a very powerful feature of the JSP specification. Custom tags allow such functionality to be encapsulated into reusable components. You can make write your reusable class in JAVA and call the same using XML tag.

There are four files which play an important role:-
  • Main class file which encapsulates the logic.
  • Tag library descriptor file.
  • Web.xml file which has the tag library descriptor file location.
  • Finally the JSP file which calls it.
Below is the image which shows the four files in one go.

Figure: - taglib directive in action
The first file is the class file which will has the reusable code which will be called in the JSP file. The above class is also called as tag handler class. One of the important things to note is doStartTag() and doEndTag(). doStartTag is called when the JSP engine encounters an open tag and doEndTag is called when it encounters a closed tag.

The second important file is the tag descriptor file. This file maps the class name with a name which will be used to call this class.

The third file is the web.xml file. We need to define the tag library descriptor file location in web.xml file.
Finally is the JSP file which calls the class. There are two things to be noted in the JSP file first is the taglib which refers to the URI. Second is the custom tag which calls the datetime class.

See the following video on Java which describes introduction to EJB (Enterprise Java Beans): -



Click to get Java Training

Regards,

Get more Java training stuffs from author's blog

Wednesday, 25 April 2012

Java/Servlets interview questions: -Can you explain the concept of SSI(Server Side Includes)?

Server Side Includes (SSI) are commands and directives placed in Web pages that are evaluated by the Web server when the Web page is being served. SSI are not supported by all web servers. So before using SSI read the web server documentation for the support. SSI is useful when you want a small part of the page to be dynamically generated rather than loading the whole page again.

Below is the code for SSI which needs to be inserted in between the HTML tags.

Here the CODE attribute specifies the servlet name. The CODEBASE attribute indicates the servlet location. If you are using a servlet deployed in the same Web server, you can omit the CODEBASE attribute. You can pass any request parameters to the servlet using the PARAM tags.

Below is the code how the SSI looks in the HTML.

See the following video on Java which describes EJB(Enterprise Java Beans): -



Click for more Java/Servlets interview questions

Regards,

Visit for more author’s blog on Java/Servlets interview questions

Friday, 20 April 2012

Java/Servlets interview questions: -Mention differences between getSession(true) and getSession(false)?

Session's can be considered as a series of related interactions between client and the server that take place over a period of time. Because HTTP is a stateless protocol these series of interactions are difficult to track. That’s where we can use HttpSession object to save in between of these interactions so that server can co-relate between interactions between clients.

Figure: - Session code walkthrough

Above is the code snippet which displays session data. Step1 returns an HttpSession object from the request object. “true” parameter in the “getsession” function ensures that we get a session object if there is no current session object in request which ensures that we never get a null session object. In Step 2 we are using the “getattribute” function to return the session value. In step 3 we are setting the session value with “Name” key.

See the following video on Java which describes Hibernate and it concepts: -



Click for more Java/Servlets interview questions

Regards,

Visit for more author’s blog on Java/Servlets interview questions

Monday, 16 April 2012

Java interview questions: - Can you explain cookies in Java?

Cookies are piece of data which are stored at the client’s browser to track information regarding the user usage and habits. Servlets sends cookies to the browser client using the HTTP response headers. When client gets the cookie information it’s stored by the browser in the client’s hard disk. Similarly client returns the cookie information using the HTTP request headers.
Figure: - Cookies in action

Figure: - Cookies code walkthrough
Above is a simple snippet which shows how to use cookies. To create a cookie you need to use the “Cookie” class. In the above snippet step1 creates a cookie using the “Cookie” class. In this case “favoritecookiebook” is the name of the cookie. In Step 2 you can see how a cookie has been added to the response. Step 3 code shows how to get all the cookies which has come in the current request header. Step 4 shows the way to get a cookie from a collection in this case we wanted to retrieve “favoritecookiebook” from the cookies collection.

See the following video on Java which describes Batch processing in Hibernate: -



Click for more Java interview questions

Regards,

Visit for more author’s blog on Java interview questions

Friday, 13 April 2012

Java interview questions: - Which other protocol is also called as stateless protocol?

A protocol is stateless if it can remember difference between one client request and the other. HTTP is a stateless protocol because each request is executed independently without any knowledge of the requests that came before it.


Figure: - HTTP Protocol in action

Above is a pictorial presentation of how a stateless protocol operates. User first sends “request1” and server responds with “response1”. When the same user comes back with “request2” server treats this as new user and has no idea that it’s the same user who has come with the request. In short every request is a new request for the HTTP protocol so it’s called as a stateless protocol.

See the following video on java for implementation of many To One relations in database using Hibernate: -



Click for more Java interview questions

Regards,

Visit for more author’s blog on Java interview questions

Monday, 2 April 2012

Java/servlets interview questions: - How will you explain Servlets and its lifecycle?

Servlets are small program which execute on the web server. They run under web server environment exploiting the functionalities of the web server.

Servlet life cycle
Figure: - Servlet Life cycle

There are three methods which are very important in servlet life cycle i.e. "init”, "service" and "destroy". Server invokes "init ()" method when servlet is first loaded in to the web server memory. Servlet reads HTTP data provided in HTTP request in the "service ()" method. Once initialized servlet remains in memory to process subsequent request. So for every HTTP request "service ()" method of the servlet is called. Finally when server unloads the "servlet ()" from the memory it calls the "destroy" method which can be used to clean up any resource the servlet is consuming.

See the following video on Java/J2EE Interview question which describes String Literal Pool: -



Click for more Java/Servlets interview questions

Regards,

Visit for more author’s blog on Java/Servlets interview questions

Wednesday, 28 March 2012

Java interview questions: - Explain Native Interface in JAVA?

JNI is a mechanism by which you can invoke method written in native language like C and C++. Native languages allow you to use a platform specific feature which is not in control of java language. For instance if you want java to interact directly with some specific type of hardware it will extremely difficult to achieve it. So you can write a C code and declare its native methods and call the same in Java.


Figure: - JNI in action


The above figure indicates how JVM interacts with JNI and without. With JNI it has the extra layer of C or C++ DLL i.e. native source code or native methods which interacts with the operating system.

See the following video on Batch Processing in Hibernate: -



Click for more Java interview questions

Regards,

Visit for more author’s blog on Java interview questions

Saturday, 24 March 2012

Java interview questions: - Elaborate the flow between bootstrap, extension and system class loader?

To understand this answer we will use below simple class lets get in to details of how the class will be loaded.

Import Koirala.Interview.Java;
public class mySimpleClass
{
public static void main(String[] args)
{
String myStr = "I am going to get a job";
System.out.println(myStr);
}}
Figure: - Flow between class loaders

The above class uses “String” class that means it has reference to “java.lang.String”.JVM will request the system class loader to load “java.lang.String”. But before he tries to load it will delegate to extension class loader. Extension class loader will pass it to Boot strap class loader. Now Boot Strap class loader does not have any parent so it will try to load “java.lang.String” using “rt.jar”. Now the Boot strap will return the class back using the same chain to the application.

Now lets see how “Import Koirala.Interview.Java;” is loaded using the class loaders. For the import statement JVM will make a call to the system class loader who will delegate the same to the extension class loader which will delegate the same to the boot strap class loader. Boot strap loader will not find “Koirala.Interview.Java” and return nothing to the extension class loader. Extension class loader will also check the same in its path and will not find anything thus returning nothing to the system class loader. System class loader will use its class path and load the class and return the same to the JVM who will then return it to the application.

See the following video on Java/J2EE Interview question which describes String Literal Pool: -



Click for more Java interview questions

Regards,

Visit for more author’s blog on Java interview questions

Wednesday, 21 March 2012

Java interview questions: - What do you mean by fundamentals of deep and shallow Cloning?

This is the most practical oriented Java Interview Questions which may be asked during the Interview by the Interviewer.

Many times in project you need to create exact copy of the object and operate on them. To do this there two ways of doing it Shallow clone and Deep clone. When an object is Shallow cloned the parent object or the top level object and its members are duplicated. But any lower level objects are not duplicated. Rather references of these objects are copied. So when an object is shallow cloned and you modify any of it child classes it will affect the original copy. When an object is deep cloned the entire object and its aggregated objects are also duplicated.

Below is the diagram which explains things in a clear and pictorial manner.

Figure: - Deep clone and Shallow clone in action
In the above diagram there are three blocks the first block is the original object, second block is the Shallow clone and the third is Deep clone block. Here the object to be cloned is a simple Customer class which has multiple addresses. Now when you shallow clone it you can see the top class clsCustomer is duplicated but clsAddresses still refers to the original object. But in case of Deep clone complete new copy is created of the whole structure.

See the following video on Java which describes Value List Handler: -



Click for more Java interview questions

Regards,

Visit for more author’s blog on Java interview questions

Monday, 19 March 2012

Java Interview questions: -Can you explain marshaling & unmarshalling in Java?

This is the most practical oriented Java Interview Questions which may be asked during the Interview by the Interviewer.

Marshalling:

Marshalling creates an XML document from a content tree
To marshal a content tree
  • Create a JAXBContext object
  • Create a Marshaller object (Marshaller marshaller = jaxbContext.createMarshaller();)
  • Set required properties using setProperty method of Marshaller marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, new Boolean(true));
  • Call the marshal method marshaller.marshal(collection, new FileOutputStream("jaxbOutput.xml"));
Unmarshalling:

Unmarshalling an XML document means creating a tree of content objects that represents the content and organization of the document
To unmarshal an XML document,
  • Create a JAXBContext object(
    JAXBContext jaxbContext = JAXBContext.newInstance("package name ");
  • Create an Unmarshaller object
    Unmarshaller unmarshaller = jc.createUnmarshaller();
  • Call the unmarshal method unmarshaller.unmarshal(new File( "xml name"));
  • Use the get methods in the schema-derived classes to access the XML data
See the following video on Introduction to Hibernate and it concepts: -



Click for more Java interview questions

Regards

Visit for more author’s blog on Java interview questions

Wednesday, 14 March 2012

Java Interview Questions: – Can you explain the main components of JDBC?

This is the most practical oriented Java Interview Questions which may be asked during the Interview by the Interviewer.

Driver Manager:
  • Manages a list of database drivers.
  • Matches connection requests from the java application with the proper database driver using communication
Driver:
  • The database communications link, handling all communication with the database.
  • Normally, once the driver is loaded, the developer need not call it explicitly.
Connection
  • Interface with all methods for contacting a database
  • Represents communication context, i.e., all communication with database is through connection object only.
Statement
  • Encapsulates an SQL statement which is passed to the database to be parsed, compiled, planned and executed.
Result Set
  • The ResultSet represents set of rows retrieved due to query execution
Data source
  • is a facility for storing data
  • Data Source may point to RDBMS, file system, any DBMS
See the following video on Inheritance between beans and Spring: -



Click for more Java interview questions

Regards,

Visit for more author’s blog on Java interview questions

Tuesday, 6 March 2012

Java Interview Questions: – Elaborate configuration of JSF application in web.xml?

URL containing faces is mapped to FacesServlet which will perform the required task when invoked.

Following are the important entries










Additional entities are made as context param



See the following video on Inheritance between beans and Spring: -



Click for more Java interview questions

Regards,

Visit for more author’s blog on Java interview questions

Wednesday, 29 February 2012

Java Interview Questions: – Can you explain the many types of Advice?

Before advice
  • Advice that executes before a join point
  • does not have the ability to prevent execution flow proceeding to the join point
After returning advice
  • Advice to be executed after a join point completes normally
After throwing advice
  • Advice to be executed if a method exits by throwing an exception
After advice
  • Advice to be executed regardless of the means by which a join point exits
Around advice
  • Advice that surrounds a join point such as a method invocation
  • It is also responsible for choosing whether to proceed to the join point
See the following video on Spring: -



Click for more Java interview questions

Regards,

Visit for more author’s blog on Java interview questions

Saturday, 25 February 2012

Java/J2EE Design Pattern Interview Questions: – 20 Basics interview questions on Java/J2EE Design Patterns?

We are putting forward 20 basic Java/J2EE design pattern Interview questions. Hope every one benefits. Normally the Java/J2EE design pattern interviewer starts with...
  • Explain how J2EE design patterns are classified?
  • What is Front Controller pattern?
  • What is Intercepting Filter pattern?
  • What is Composite View pattern?
  • What is View Helper pattern?
  • What is Dispatcher?
  • What is Service to Worker pattern?
  • What is Service Locator pattern?
  • What is Business Delegate pattern?
  • What is Session Fa├žade pattern?
  • What is EJB Command pattern?
  • What is Value Object pattern?
  • What is Value Object Assembler pattern?
  • What is Data Access Object pattern?
  • What is Version Number pattern?
  • What is the application of business objects?
  • Why transfer objects(TO) are not used to store state in business objects(BO)?
  • Is Service Locator still be used in EJB 3?
  • What is the use of Transfer objects(TO)?
  • What is the use of TO Assembler?
See the following video on Batch Processing in Hibernate: -



Click for more Java/J2EE Design Pattern interview questions

Regards,

Visit for more author’s blog on Java/J2EE Design Pattern interview questions

Wednesday, 22 February 2012

Java Interview Questions: - How will you explain EAR, JAR and WAR file?

Following is the differences between EAR, JAR and WAR file asked during Java Interview Questions.

JAR: - EJB modules which contains enterprise java beans class files and EJB deployment descriptor are packed as JAR files with .jar extension

WAR: - Web modules which contains Servlet class files, JSP FIles,supporting files, GIF and HTML files are packaged as JAR file with .war( web achive) extension

EAR: - All above files(.jar and .war) are packaged as JAR file with .ear ( enterprise archive) extension and deployed into Application Server

SAR (Service ARchive): -  It provides a service.xml file and accompanying JAR files. And used in case of SOA

APK (Android Application Package):- A variant of the Java archive format, is used for Android applications

See the following video on Java - Inheritance between beans and spring asked during java Interview:



Click for more Java interview questions

Regards,

Visit for more author’s blog on Java interview questions

Saturday, 18 February 2012

Java Interview Questions: - Mention the life-cycle phases of JSF (Java Server Faces)?

Following is the brief Life-cycle phases of JSF (Java Server Faces) asked during Java interview questions.

Restore View : A request comes through the FacesServlet controller. The controller examines the request and extracts the view ID, which is determined by the name of the JSP page.

Apply request values: The purpose of the apply request values phase is for each component to retrieve its current state. The components must first be retrieved or created from the Faces Context object, followed by their values.

Process validations: In this phase, each component will have its values validated against the application's validation rules.

Update model values: In this phase JSF updates the actual values of the server-side model, by updating the properties of your backing beans.

Invoke application: In this phase the JSF controller invokes the application to handle Form submissions.
Render response: In this phase JSF displays the view with all of its components in their current state.

See the following video by using String or String Buffer performance increases asked during java Interview: -



Click for more Java interview questions

Regards,

Visit for more author’s blog on Java interview questions

Tuesday, 14 February 2012

Java Interview questions: -Show difference between SAX Parser and DOM Parser?

Following is the difference between SAX Parser and DOM Parser asked during Java interview questions.

SAXDOM
Event based processingTree based processing
Traversing only from top to bottom that too onceTraversing can be in any direction and any number of times
Document content cannot be modified in SAXDocument content can be modified in DOM
A SAX parser serves the client application always only with pieces of the document at any given timeA DOM parser always serves the client application with the entire document no matter   how much is actually needed by the client
More space efficient in case of a big input documentis space inefficient when the document is huge

See the following video on String Literal Pool asked during java Interview:-



Click for more Java interview questions

Regards,

Visit for more author’s blog on Java interview questions

Friday, 3 February 2012

Java interview questions: - Mention blocking Queues?

Following classes are blocking Queues in Java interview questions.

The java.util.concurrent package contains a set of synchronized Queue interfaces and classes. Blocking Queue extends Queue with operations that wait for the queue to become nonempty when retrieving an element and for space to become available in the queue when storing an element. This interface is implemented by the following classes:-
  • Linked Blocking Queue — an optionally bounded FIFO blocking queue backed by linked nodes
  • Array Blocking Queue — a bounded FIFO blocking queue backed by an array
  • Priority Blocking Queue — an unbounded blocking priority queue backed by a heap
  • Delay Queue — a time-based scheduling queue backed by a heap
  • Synchronous Queue — a simple rendezvous mechanism that uses the Blocking Queue interface
See the following video on Java - Getting started with spring: -



Click for more Java interview questions

Regards,

Visit for more author’s blog on Java interview questions

Friday, 27 January 2012

Java interview questions: - Explain different types of inner classes?

Following are the different types of inner classes in  Java interview questions.

Nested top-level classes-
  • If you declare a class within a class and specify the static modifier, the compiler treats the class just like any other top-level class
  • Any class outside the declaring class accesses the nested class with the declaring class name acting similarly to a package. eg, outer. Inner
  • Top-level inner classes implicitly have access only to static variables. There can also be inner interfaces. All of these are of the nested top-level variety.
Member classes -
  • Member inner classes are just like other member methods and member variables and access to the member class is restricted, just like methods and variables.
  • This means a public member class acts similarly to a nested top-level class
  • The primary difference between member classes and nested top-level classes is that member classes have access to the specific instance of the enclosing class.
Local classes-
  • Local classes are like local variables, specific to a block of code. Their visibility is only within the block of their declaration. In order for the class to be useful beyond the declaration block, it would need to implement a more publicly available interface.
  • Because local classes are not members, the modifiers public, protected, private, and static are not usable.
Anonymous classes-
  • Anonymous inner classes extend local inner classes one level further. As anonymous classes have no name, you cannot provide a constructor
  • Anonymous class is a class defined inside a method without a name and is instantiated and declared in the same place and cannot have explicit constructors
See the following video on Java - Introduction to Hibernate and it concepts: -



Click for more  Java interview questions

Regards,

Visit for more author’s blog on Java interview questions

Tuesday, 24 January 2012

Java/J2EE interview questions: - Define singleton in a clustered environment?

In clustering there are multiple J2EE containers running on multiple JVM'S as a Result maintaining singleton is possible with following steps

1) RMI singleton object is created on only one container

2) Stubs of the same are registered in the cluster by adding the same in JNDI Name tree, thus making itself available to entire cluster

The disadvantage of the above approach as follows:

1) In case the singleton has not been created then the container created one Adds the same to JNDI. If 2 container creates singletons simultaneously then there will be a problem

2) The above problem can be solved by delegating the responsibility of creating the singleton to a single container but will cause problem in case the container in consideration fails

Also see the following video on Java and J2EE Design Pattern - Value List Handler: -



Click for more Java/J2EE Design Pattern Interview questions.

Regards,

Visit for more author’s blog on Java /J2EE Design Pattern Interview questions.

Saturday, 21 January 2012

Java interview questions: - Different types of rowset in java 5?

This is one of the typical Java interview questions asked by the interviewer during the interview session. So one can proceed answering it as follows: -

JdbcRowSet:
  • A wrapper around a ResultSet object that makes it possible to use the result set as a JavaBeans component
  • By default all result set are scrollable and updatable
CachedRowSet
  • object is a container for rows of data that caches its rows in memory, which makes it possible to operate without always being connected to its data source
  • Further, it is a JavaBeans component and is scrollable, updatable, and serializable
FilteredRowSet
  • Provides a degree of filtering on contents without heavy weight query language
  • Extends CacheRowSet and overrides methods for filtering
JoinRowSet
  • Provides a mechanism for combining related data from different RowSet objects into one JoinRowSet object, which represents an SQL JOIN
  • can take one of the following to denote type of join
  1. CROSS_JOIN
  2. FULL_JOIN
  3. INNER_JOIN - the default if no JOIN type has been set
  4. LEFT_OUTER_JOIN
  5. RIGHT_OUTER_JOIN
WebRowSet

It describes the standard XML document format required when describing a RowSet object in XML

SyncResolver

Is a rowset object wgich implement SyncResolver interface which allows applications to use a manual decision tree to decide what should be done when a synchronization conflict occur

Also see video on Many To One relation in database using Hibernate as follows: -



Click for more Java interview questions

Regards,

Visit for more author’s blog on Java interview questions.

Wednesday, 18 January 2012

Java interview questions: – 20 Basic Interview questions on Java? Part: -3.

  • What is Upper bounded wildcards in generics?
  • What is JAR file?
  • What are different types of inner classes?
  • Can we declare an anonymous class as both extending a class and implementing an interface?
  • What is the difference between a static and a non-static inner class?
  • How does Java handle integer overflows and underflows?
  • Does garbage collection guarantee that a program will not run out of memory?
  • What is the purpose of finalization?
  • Can an unreachable object become reachable again?
  • What is a reflection package?
  • What do you mean by immutable? How to create an immutable object?
  • What is class loader in java?
  • What is a weak reference?
  • What is object cloning?
  • What is object pooling?
  • What are marker interface /tag interface?
  • What is the difference between Comparable and Comparator?
  • Does a class inherit the constructors of its superclass?
  • What are annotations used for?
  • What are the annotations used by compiler?
View the following video on Hibernate and it concept in Java: -



For more on Java interview questions so click and visit.

Regards,

Author’s more on Java interview questions


Friday, 13 January 2012

JAVA INTERVIEW QUESTIONS: - 20 BASICS INTERVIEW QUESTIONS ON JAVA? Part: -2.

  • What is a native method?
  • Does Java provide any construct to find out the size of an object?
  • Is Empty .java file a valid source file?
  • Can a .java file contain more than one java classes?
  • What is the difference between an argument and a parameter?
  • What is UNICODE?
  • What are Transient and Volatile Modifiers?
  • What are the different scopes for Java variables?
  • What are wrapper classes?
  • What is a the difference between System.err and System.out?
  • What are the contracts defined by .equals()?
  • If two objects are considered equal by .equals() , can it be said they has same hashCode()?
  • If two objects have same hashCode() is it necessary they will be equal by using .equals() method?
  • What contracts hashCode () defines?
  • What is the difference between == and equals?
  • What is the difference between List and List (not parameterized list and list parameterized by String) in Java?
  • What are generics in jdk1.5?
  • Are generics covariant?
  • What are Lower-bounded wildcards in generics?
  • What is Upper bounded wildcards in generics?
View the following video on Inheritance between beans and Spring in Java: -



For more on  Java interview questions so click and visit.

Regards,

Author’s more on Java interview questions

Tuesday, 10 January 2012

Java Interview Questions: - 25 Basics interview questions on Java?

  • What if the main method is declared as private?
  • What if the static modifier is removed from the signature of the main method?
  • Can we define private and protected modifiers for variables in interfaces?
  • Can there be an abstract class with no abstract methods in it?
  • What modifiers are allowed for methods in an Interface?
  • What is a local, member and a class variable?
  • What does it mean that a method or field is “static”?
  • Is null a keyword?
  • What modifiers may be used with an inner class that is a member of an outer class?
  • What is class path?
  • What is path?
  • What is the difference among JVM Spec, JVM Implementation, JVM Runtime?
  • What are JDK and JRE?
  • What is JIT?
  • What is a JVM heap?
  • What is sandbox?
  • What is Locale?
  • What is a ResourceBundle class?
  • How will you get the platform dependent values like line separator, path separator, etc?
  • How does garbage collector decide which objects are to be removed? Can garbage collector be forced?
  • What is the final keyword denotes w.r.t class, method and variable?
  • What are the methods in Object?
  • Can you instantiate the Math class?
  • What is the difference between the instanceof and get class, these two are same or not?
  • Can main method be declared final?
View the following video on Batch Processing in Java: -



For more on  Java interview questions so click and visit.

Regards,

Author’s more on Java interview questions


Friday, 6 January 2012

Java Interviews questions: -How can you explain views and its type?

A view can be thought of as either a virtual table or a stored query is a database object that is a logical representation of a table Views are mainly classified as

Simple view:
  • is created by selecting only one table
  • does not contains functions.
  • can perform operations through simple view
Complex view :
  • It is created by selecting more than one table.
  • It can performs functions.
  • can not perform always DML operations
Also see the following interesting video on Java - Inheritance between beans and Spring : -



Know more on Java interview questions

Regards,

Get more on Java interview questions from author’s blog