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