Wednesday, 24 July 2013

Java interview questions

1. What is difference between Java and C++?
Ans :
(i) Java does not support pointers. Pointers are inherently insecure and troublesome. Since pointers do not exist in Java.
(ii) Java does not support operator overloading.
(iii) Java does not perform any automatic type conversions that result in a loss of precision
(IV) All the code in a Java interview program is encapsulated within one or more classes. Therefore, Java does not have global variables or global functions.
(v) Java does not support multiple inheritance.
Java does not support destructors, but rather, add the finalize () function.
(vi) Java does not have the delete operator.
(vii) The <> are not overloaded for I/O operations
2. Can you explain me OOPs Concepts ???
Ans : OOPs stands for Object Oriented Programming.
it has mainly four concepts ..
1. Polymorphism : It is ability to take more tahn one form (Poly : More and Morphism : forms). In java it is achieved by using Method Overloading(Compile time Polymorphism) and Method Overriding( Runtime Polymorphism)
2. Inheritance : It is the process by which one object acquires the properties of another object and also has some of its own.The main advantages of inheritance are reusability and accessibility of variables and methods of superclass by the sub classes.
3. Encapsulation: It is the process of wrapping the data and code into a single object. Like all class are a object. It is used for data hiding like variables declared as private can be accessed only by members of that particular class.It is mechanism that binds together code and data . It manipulates and keeps both safe from outside world.
4. Abstaction : it is representating the essential features without including background details. It is like providing the functionality without knowing who it happens.
eg : By cominations of Red Green and Blue we can form 256 no of colors.
In java if need to append a string with another, then we use append method of StringBuffer without bothering how it works.
3. what is difference between Abstraction and Encapsulation ??
Abstrction is used at the design side while Encapsulation is used at the implementation side.
Abstraction is used for hiding the unwanted information and giving revelant information.
Eg: Three set of customers are going to buy a bike First one wants information about the style. Second one wants about the milage. Third one wants the cost and brand of the bike.So the salesperson explains about the product which customer needs what. So he hiding some information and giving the revelant information.
Encapsulation combines one or more information into a component.
Eg: Capsule is mixed with one or more medicine and packed into the tube. so its related and acting in two moducles.
4. what is dynamic binding or late binding ??
In dynamic binding the code associated with a given procedure call runs at the run time(Not compile time).
5. What is difference between Class and Object??
Class is a blue print of an object while object is an instance of a class. Class is a virtual entity while object is an real implemetation
6. Can you explain how obkect is created in memory ??
Ans : Object is constructed either on a memory heap or on a stack.

Memory heap
generally the objects are created using the new keyword. Some heap memory is allocated to this newly created object. This memory remains allocated throughout the life cycle of the object. When the object is no more referred, the memory allocated to the object is eligible to be back on the heap.
Stack 
During method calls, objects are created for method arguments and method variables. These objects are created on stack.
7. What is mean by System.out.pritnln(“hello World”);
System : it is a claas.
out : It is an instance variable of java.lang.System class refers to console.
println() : It is a method of java.io.PrintWriter.
8. What is wrapper classes ?
primitive data types can be converted into objects by using wrapper classes. These ara part of java.lang package.
9. Does Java passes methos arguments by value or by reference ??
Java passes all arguments by value , not by references.

No comments:

Post a Comment