www.studyjava.org || interview home||
Q1. Describe the three OOO principles?
A1. Encapsulation - It is the way the code and data are confined and are in isolation from the
outside environment of the system.
EXAMPLE : In a car the engine can be thought about as an encapsulated which is controlled by the starter key and the gear.The operation of the engine does not affect the functioning of other parts of car like the headlight and wiper. In JAVA basis of encapsulation is the CLASS.
Inheritence - It is the process by which one object acquires the properties of another object.
Polymorphism - It is a feature that allows one interface to be used for a general class of actions. The specific action is determined by the exact nature of the situation.
EXAMPLE : In a college cafeteria if an old music is put the students would not like it , but if the latest number of Brittney Spears is put then they would love it.If analysed then we can see that even though the process of listening is the same i.e. for the old song the students listen it from there ears and even for the latest Brittney Spears number they listen it from there ear. But there is a difference by which the students react. This difference can be explained by the concept polymorphism.
Q2. What is meant by Endianness?
A2. Endianness describes how multiple data types such as short , int and long are stored in memory.If it takes two bytes to represent a short, then to predict if the most significant or the least significant comes first.If the most significant byte is first, followed by the least significant one then the machine is said to be big endian. Machines such as the SPARC and Power PC are big-endian, while the Intel x86 series is little-endian.
Q3. How many types of literals are there in JAVA?
A3. There are four types of literals they are Integer literals, Flaoting point literals, Boolean literals and character literals.
Q4. A note on compiling & Executing a JAVA pgm
A4. (i) The name of the sourcefile is called in terms of .java
(ii) A source file is called a compilation unit. This has one or more class definitions.
(iii) The name of the class should be same as that of the file.
(iv) Once compiled the .java file creates a .class file. This is done by the compiler javac
(v) This classfile contains the bytecode version of the program.
Q5. A note on PUBLIC , PRIVATE , STATIC , VOID & MAIN.
A5. (i) All Java applications begin execution by calling main ()
(ii) When a class member is defined as public. Then that member may be accessed by code outside the class in which it is declared.
(iii) The opposite of public is private which prevents a member from being used by code defined outside of its class.
(iv) The keyword static allows main() to be called without having to instantiate a particular instance of the class. This is mandatory because main () is called by the Java interpreter before any objects are made.
(v) CASE SENSITIVE : Main () is different from main(). It is important to know that that Main() would be compiled. But the Java interpreter would report an error if it would not find main().
Q6. What is meant by Garbage collection ?
A6. The technique that automatically destroys the dynamically created objects is called garbage collection. When no reference to an object exists, that object is assumed to be no longer needed , and memory occupied by that object can be reclaimed.
Q7. What are the access modifiers?
A7. There are three types of access modifiers.
(i) Private - Makes a method or a variable accessible only from within its own class.
(ii) Protected - Makes a method or a variable accessible only to classes in the same package or subclasses of the class.
(iii) Public - Makes a class , method or variable accessible from any other class.
Q8. A note on keywords for Error handling.
A8. (i) Catch - Declares the block of code used to handle an exception.
(ii) Finally - Block of code , usually following a typecatch statement, which is executed no matter what program flow occurs when dealing with an exception.
(iii) Throw - Used to pass an exception up to the method that calls this method.
(iv) Throws - Indicates the method will pass an exception to the method that called it.
(v) Try - Block of code that will be tried but which may cause an exception.
(vi) Assert - Evaluates a conditional _expression to verify the programmer's assumption.
Q9. How many ways can you represent integer numbers in JAVA?
A9. There are three ways , you can represent integer numbers in JAVA. They are decimal (base 10) , octal (base 8) , and hexadecimal (base 16).
Q10. A note on defining floating point literal ?
A10. A floating point literal is defined as float g = 3576.2115F.
Q11. A note on arrays of object references?
A11. If the array type is CLASS then one can put objects of any subclass of the declared type into the array. The following example on sports explains the above concept :
class sports { }
class football extends sports { }
class hockey extends sports { }
class baseball extends sports { }
sports [ ] mysports = { new football (),
new hockey (),
new baseball ()};
Q12. What is meant by Instance of comparison?
A12. It is used for object reference variables only.You can use it to check wether an object is of a particular type.
Q13. when is amethod said to be overloaded?
A13. Two or more methods are defined within the same class that share the same name and their parameter declarations are different then the methods are said to be overloaded.
Q14. What is meant by Recursion?
A14. It is the process of defining something in terms of itself. Interms of JAVA it is the attribute that allows a method to call itself.The following example of calculating a factorial gives an example of recursion.
class Factorial {
int fact (int n) {
int result;
if (n= 1) return 1;
result = fact(n -1) * n;
return result;
}
}
class Recursion {
Public static void main (string args[ ]) {
Factorial f = new Factorial ();
system.out.println ("Factorial of 10 is " + f.fact(10));
}
}
Q15. A cool example to explain the concept of METHOD in JAVA.
A15. Let us say you are in Mcdonalds and you order for #7 for here with medium coke. The cashier takes your order and punches it on the computer. The folks in the kitchen get the order and they get the crispy chicken and pass it on to the guy who puts a medium fries and finally a medium coke is filled and the order is served to you. In other terms if all this was supposed to be done by a robot then it could have been programmed the following way.
void #7forherewithmediumcoke( )
{
Get (crispy chicken, lattice, butter, fries, coke);
make (sandwich);
fill (coke, fries);
}