PDA

View Full Version : Java Interview Questions :: Challenging all Java Developers


javaguru
13-02-2010, 08:36 AM
Hi all Java developers of abhisays.com Discussion zone. I am starting a new thread of Java interview questions.. I will ask small questions and you have to answer.. The person who will answer maximum number of questions correctly will be awarded the title of Java Geek.. Let's start the quiz..and best of luck to all members.. :cheers:

Which programming language was the main inspiration behind the development of Java?

umesh
14-02-2010, 09:59 AM
Java is inspired from smalltalk, one of the first object oriented programming languages..

sony
18-02-2010, 08:36 PM
Now my question.. what are marker interfaces and its advantages? Why we use marker interfaces?

abhishek
13-03-2010, 05:00 PM
A so-called marker interface is a Java interface which doesn't actually define any fields. It is just used to "mark" Java classes which support a certain capability -- the class marks itself as implementing the interface.

There are few Java supplied marker interfaces like Cloneable, Serializable, etc. One can create their own marker interfaces the same way as they create any other interface in Java.

The main purpose to have marker interfaces is to create special types in those cases where the types themselves have no behavior particular to them. If there is no behavior then why to have an interface?

Because the implementor of the class might only need to flag that it belongs to that particular type and everything else is handled/done by some other unit - either internal to Java (as in the case of Java supplied standard marker interfaces) or an app specific external unit.

rambler
14-03-2010, 07:59 PM
My question..

When destory method is called in servlet life cycle?

shefali
16-03-2010, 04:46 PM
The destroy() method is usually called by the servlet container immediately before it takes a servlet out of service. It is typically used to clean-up any resource references, save temporary data and suchlike. For example, it is called during server restart..

abhishek
17-03-2010, 10:02 PM
Next question.. What is the difference between call by value and call by reference?

sunita
18-03-2010, 07:23 AM
The arguments passed to function can be of two types namely



1. Values passed
2. Address passed



The first type refers to call by value and the second type refers to call by reference.



For instance consider program1



main()
{
int x=50, y=70;
interchange(x,y);
printf(“x=%d y=%d”,x,y);
}

interchange(x1,y1)
int x1,y1;
{
int z1;
z1=x1;
x1=y1;
y1=z1;
printf(“x1=%d y1=%d”,x1,y1);
}


Here the value to function interchange is passed by value.



Consider program2



main()
{
int x=50, y=70;
interchange(&x,&y);
printf(“x=%d y=%d”,x,y);
}

interchange(x1,y1)
int *x1,*y1;
{
int z1;
z1=*x1;
*x1=*y1;
*y1=z1;
printf(“*x=%d *y=%d”,x1,y1);
}


Here the function is called by reference. In other words address is passed by using symbol & and the value is accessed by using symbol *.



The main difference between them can be seen by analyzing the output of program1 and program2.



The output of program1 that is call by value is



x1=70 y1=50
x=50 y=70



But the output of program2 that is call by reference is



*x=70 *y=50
x=70 y=50



This is because in case of call by value the value is passed to function named as interchange and there the value got interchanged and got printed as



x1=70 y1=50



and again since no values are returned back and therefore original values of x and y as in main function namely



x=50 y=70 got printed.

abhishek
26-03-2010, 07:55 PM
nice explanation with examples.. thanks for sharing.. Next question please..

swati.
27-03-2010, 07:47 PM
Next question from my side.

What are wrapper classes in Java?

neha
30-03-2010, 07:22 PM
Next question from my side.

What are wrapper classes in Java?

A primitive wrapper class in the Java programming language is one of eight classes provided in the java.lang package to provide object methods for the eight primitive types. All of the primitive wrapper classes in Java are immutable. J2SE 5.0 introduced autoboxing of primitive types into their wrapper object, and automatic unboxing of the wrapper objects into their primitive value—the implicit conversion between the wrapper objects and primitive values.

Wrapper classes are used to represent primitive values when an Object is required. The wrapper classes are used extensively with Collection classes in the java.util package and with the classes in the java.lang.reflect reflection package.

The primitive wrapper classes and their corresponding primitive types are:

Primitive type Wrapper class Constructor Arguments
byte Byte byte or String
short Short short or String
int Integer int or String
long Long long or String
float Float float, double or String
double Double double or String
char Character char
boolean Boolean boolean or String

The Byte, Short, Integer, Long, Float, and Double wrapper classes are all subclasses of the Number class.

sumit
31-03-2010, 08:24 AM
nice answer.

abhishek
02-04-2010, 07:36 AM
next question.

What are the advantages of using Spring framework?

abhishek
22-04-2010, 06:31 AM
A primitive wrapper class in the Java programming language is one of eight classes provided in the java.lang package to provide object methods for the eight primitive types. All of the primitive wrapper classes in Java are immutable. J2SE 5.0 introduced autoboxing of primitive types into their wrapper object, and automatic unboxing of the wrapper objects into their primitive value—the implicit conversion between the wrapper objects and primitive values.

Wrapper classes are used to represent primitive values when an Object is required. The wrapper classes are used extensively with Collection classes in the java.util package and with the classes in the java.lang.reflect reflection package.

abhishek
22-04-2010, 06:31 AM
Next question, what are the differences between doGet and doPost?

brajesh
13-06-2010, 10:27 AM
Is this question related to java servlets?

abhishek
20-06-2010, 09:14 PM
Yes, now please answer the question.. :)