Friday, 23 September 2011

JAVA QUESTIONS




Java is not 100% pure object oriented programming language

1 It use primitive data type like int,char,float etc.
2 Here in this program no object use:
class Test
{
static
{
System.out.println("Hi!!!");
}
}

The above code does not use any object to show the output, so that java is not 100% Object Oriented Language because it is not using any object...!!!

but we can say it almost pure OOP language.



Java is not pure object oriented language, because in object oriented concept every method is called throw its objects.In java main()is also a method, but without creating object we accessing main method..."General think"
By using the key word static we can access any method without creating object...so java its not pure object oriented language.



 "Primitive data types can't be referenced as memory addresses.
 That's why we need wrappers which serve as placeholders for primitive values".











Q .How will you convert a String array to an ArrayList object?


String[] stringArray = new String[] {"x", "y", "Z"};
List list = Arrays.asList(stringArray);


Q.What's the difference between a queue and a stack?


Stacks works by last-in-first-out rule (LIFO), while queues use the FIFO rule.


Q.You are planning to do an indexed search in a list of objects. Which of the two Java collections should you use: ArrayList or LinkedList?

ArrayList.


Q.How do you know if an explicit object casting is needed?
In order to assign a superclass object to a variable of a subclass,one needs to do explicit casting. For example:

Person person;
Man man;
man = (Man)person;

While automatic casting happens when you typecast a subclass object as parent class object.






Q.What's the difference between the methods sleep() and wait() ?

 The code sleep(1000); puts thread aside for exactly one second. The code wait(1000), causes a wait of up to one second. A thread could stop waiting earlier if it receives the notify() or notifyAll() call. The method wait() is defined in the class Object and the method sleep() is defined in the class Thread.

No comments:

Post a Comment