Thursday, 14 January 2016

Core Java Interview questions

Hello guys, in this post I will try to cover as many interview questions as possible.These are most commonly asked interview questions that can be useful for freshers as well as experienced people.

In this post I will try to concentrate maximum on core Java questions only. 

1. What is the difference between String, StringBuffer and StringBuilder?

String Object is immutable. I.e. if we create a String object, we cannot change it at the same memory location. 
If we change the string object, it creates a new memory location and copies the content into that new location.

Example 

String s1 = new String ("Java interview")

Suppose that Address of s1 is 200 

if we say s1 = s1 +" questions”

Then it will create a new memory location (say at 300) and copies the content to new location.


I.e. address of s1 will change to 300. Please click on the image below to maximize it.

StringBuffer :

StringBuffer is mutable. I.e. if we create a string buffer object, then we can modify it at the same location.

StringBuffer sb = new String Buffer (“Java interview”);

Suppose that address of sb is 200

If we say
Sb.sppend(“questions”)

Then its value will be changed to Java Interview Questions and address will be same 200.



  String Builder :

  1.  String Builder is Non-synchronized version of String buffer. i.e String Buffer is synchronized where as String builder is non-synchronized. 
  2. StringBuilder is much faster than StringBuffer as it doesnt have to deal with synchronization methods and locks
  3. so if you are not going to use threading in java then using StringBuilder will improve the efficiency of the program.
  4. StringBuffer is old class in java where as StringBuilder was introduced from java 1.5 version.

1.     Explain about finalize method in JAVA.

v  Finalize method is a protected method declared in Object class
v  It is by default available to all classes defined in Java.
v  This method is called by the garbage collected before destroying an object.
v  We can override this method in our class. When we override, it is our responsibility to call the finalize method of the super class.
v  Below is the syntax of finalize method.


Protected void finalize() throws Throwable;
 

Wednesday, 13 May 2015

Inheritance in Javascript

in Javascript inheritance can be achieved by using below two methods
1.Prototype chaining
2.Constructor stealing

1.prototype chaining

base=function()
{
this.name="base";
}

derived=function
{
this.marks="20";

this.prototype=new base();//creating inheritance using prototype
}

with above approach we face some problems while usig collectios like arrays.

Example


base=function()

{
this.name="base";
this.languages=["tel","eng","hindi"];
}

derived=function
{
this.marks="20";

this.prototype=new base();//creating inheritance using prototype
}

var  d1=new derived();
var d2=new derived();
d1.push("Kannada");

alert(d1.laguages) //prints tel,eng,hindi,kannada

alert(d2.languages) //also prints tel,eng,hindi,kannada

this is the problem with prototype chaiing when we use arrays, and try tomodify them,it will be reflected in all instances of the class.as when we modify an array, it points to a different location/reference


Constructor stealing


This is the second way of implementing inheritance in javascript where we invoke constructor of the parent class directly in the child class to perform inheritance.


base=function()
{
this.name="base";
}

derived=function
{
this.marks="20";

this.prototype=new base();//creating inheritance using prototype
}

with above approach we face some problems while usig collectios like arrays.

Example


base=function()

{
this.name="base";
this.languages=["tel","eng","hindi"];
}

derived=function
{
this.marks="20";

base.call(this);
}

var  d1=new derived();
var d2=new derived();
d1.push("Kannada");

alert(d1.laguages) //prints tel,eng,hindi,kannada

alert(d2.languages) // prints tel,eng,hindi 

so to avoid problems usig prototype chaiing, we can prefer constructor stealing.



Struts2 and Spring Integration

As we all now, struts2 can be integrated with other frameworks also. In this article,I will try to expalin how to integrate struts2 with spring framework.

To perform the integration, follow the below steps.

1.download the struts2-spring-plugin-x.y.z.jar file and add to class path file
2.In the web.config file configure the ContextLoaderListener listner as shown below.




<listener>
      <listener-class>
         org.springframework.web.context.ContextLoaderListener
      </listener-class>
 </listener>



The main purpose of this file is to load the applicatioContext.xml file. This file should be at the same level of web.xml file.

Friday, 24 April 2015

Spring Tutorials


Spring is a light weight framework used to develop complex java applications.
Advantages of spring are
1.It is very light weight when compared to EJBs
2.It can be easily integrated with other frameworks
3.No need of any web server while developing applications. As it provides some inbuilt containers.
4.Provides built in support for connection pooling and transaction management.

Spring provides below two containers

1.BeanFatory container.(Bean factory container is also called as IOC container or Core container)
2.ApplicationContextContainer

BeanFactory container :

1.BeanFactory container is also called as IOC Container or core container
2.It is implementation of BeanFactory class
2.It supports lazy loading. i.e. objects are injected only when they are invoked.
4.By default it considers all beans as singleton
5.

Wednesday, 15 October 2014

What is JAX-P-

Hello and welcome to JAX-P article,

in this article,we will discuss details about JAX-P. JAX-P stands for XML processing.

As we disscussed in 'What is XML' article, XML is also a document which contains data.

earlier there were no options in JAVA to read XML files, users has to use java I/O to XML document.

later JAVA has provided to this API to process XML documents.

XML can be read either from starting or in random order ,JAVA provides two types of parsers to process XML files.

SAX-PARSER :

SAX parser reads the document in sequential order.
it is event based parser.
there are different types of events called document start,element start,element end..

it can read only one element at any time.
it uses less memory
it is fast compared with DOM parser.

SAXParserFactory saxparserFactory=
SAXParserFactory.newInstance();

 SAXPARSER parser=saxparserFactory.newSAXParser();

using parser, we can parse the XML documents. it provides some set of methods to perform the read operations

SAX parser can only read the documents.

Web services-Part 01

Web services is a technology, using which applications of two different technologies can communicate with each other.

the application which implements web services is called provider

and the application which uses these web services is callled consumer.

W3C organization has provided some set of guidelines to implement web services.

Initially W3C has released a document with set of guidelines that document is called BP 1.0 (Basic profile).

Java has provided JAVA-RPC specification to follow these guidelines and to implement web services

later W3C has provided a document another set of guidelines called BP1.1. java has provided JAVA-WS API to implement these guidelines

Once we implement web services using any of the above API, we need to provide their details using WSDL.

WSDL stands for web services description language, using which we can provide details about our services and methods and heir parameters

When a consumer wants to use these web services, they can refer this WSDL document.


once this WSDL is ready, and if you want to make your web services public, we can add this WSDL in UDDI

UDDI stands for universal desciption,directory integration.
we can add details about our web services in UDDI.

read our next article to understand more about web services


What is XSD


Hello and welcome to this article... in this article, we will see some basic details of XSD

XSD stands for XML Schema definition.

in XSD root tag is mandatory, all other tags should come under this XSD.

as we already know,XML can contain either simple tag or compound tag.

to define simple tag, we can use

<xs: element name="itemcode" type="xs:string">

to define complex attributes, XSD provides xs:complexType as shown below.


<xs:complexType name="address">
<xs:sequence> or <xs:all>
 <xs: element name="street" type="xs:string">
<xs:element name="state" type="xs:string">
</xs:sequence> or </xs:all>
</xs:complexType>

when we use xs:sequence, it specifies the all the nested elements should come in the same order
 
when we use xs:all, these attributes can come in any order

once we define a complex element, we can refere them in any other complex types

<xs:element name="permentaddr" type="address">

</xs:element>


Working with multipole XSDs
________________________________

If you want to refer one XSD in another XSD, we can use import or include.

if both XSDs are in same location, we  can use include

if both XSDs are in different locations, we use import

<xs:schema targetNamespace="xxxx">
</xs:schema>

<xs:schema targetnamespace="XXX">

<xs:include schemalocation="po1.xsd"

</xs:schema?



Search This Blog