Continuing our Java/J2EE/JEE interview questions and answers series, today's questions are:
Q Describe the principles of OOPS.
A There are three main principals of oops which are called Polymorphism, Inheritance and Encapsulation.
Q Explain the Encapsulation principle.
A Encapsulation is a process of binding or wrapping the data and the codes that operates on the data into a single entity. This keeps the data safe from outside interface and misuse. One way to think about encapsulation is as a protective wrapper that prevents code and data from being arbitrarily accessed by other code defined outside the wrapper.
Q Explain the Inheritance principle.
A Inheritance is the process by which one object acquires the properties of another object.
Q Explain the Polymorphism principle.
A The meaning of Polymorphism is something like one name many forms. Polymorphism enables one entity to be used as general category for different types of actions. The specific action is determined by the exact nature of the situation. The concept of polymorphism can be explained as "one interface, multiple methods".
Q Explain the different forms of Polymorphism.
Answer: From a practical programming viewpoint, polymorphism exists in three distinct forms in Java:
Method overloading
Method overriding through inheritance
Method overriding through the Java interface
Q What are Access Specifiers available in Java?
A Access specifiers are keywords that determines the type of access to the member of a class. These are:
Public
Protected
Private
Defaults
Q Describe the wrapper classes in Java.
A Wrapper class is wrapper around a primitive data type. An instance of a wrapper class contains, or wraps, a primitive value of the corresponding type.
Q What's the difference between J2SDK 1.5 and J2SDK 5.0?
A There's no difference, Sun Microsystems just re-branded this version.
Q What would you use to compare two String variables - the operator == or the method equals()?
A I'd use the method equals() to compare the values of the Strings and the == to check if two variables point at the same instance of a String object.
Q Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written?
A Yes, it does. The FileNoFoundException is inherited from the IOException. Exception's subclasses have to be caught first.
Q Can an inner class declared inside of a method access local variables of this method?
A It's possible if these variables are final.
Q What can go wrong if you replace && with & in the following code:
String a=null; if (a!=null && a.length()>10) {...}
A A single ampersand here would lead to a NullPointerException.
Q What's the main difference between a Vector and an ArrayList
A Java Vector class is internally synchronized and ArrayList is not.
Q When should the method invokeLater()be used?
A This method is used to ensure that Swing components are updated through the event-dispatching thread.
Q How can a subclass call a method or a constructor defined in a superclass?
A Use the following syntax: super.myMethod(); To call a constructor of the superclass, just write super(); in the first line of the subclass's constructor.
Q You can create an abstract class that contains only abstract methods. On the other hand, you can create an interface that declares the same methods. So can you use abstract classes instead of interfaces?
A Sometimes. But your class may be a descendent of another class and in this case the interface is your only option.
Q What comes to mind when you hear about a young generation in Java?
A Garbage collection.
Q What comes to mind when someone mentions a shallow copy in Java?
A Object cloning.
Q If you're overriding the method equals() of an object, which other method you might also consider?
A hashCode()
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?
A ArrayList
Q How would you make a copy of an entire Java object with its state?
A Have this class implement Cloneable interface and call its method clone().
Q How can you minimize the need of garbage collection and make the memory use more effective?
A Use object pooling and weak object references.
Previous Java, J2EE, JEE Interview Questions can be read here.
- Popular Java Interview Questions - 1
- Java J2EE Interview Questions - 2
- Java Interview Questions -3
- J2EE Interview Questions - 4
- J2EE Interview Questions - 5
- Java J2EE Interview Questions - 6
- J2EE Server Side Debugging in Eclispe
- Serialization in Java/J2EE - Demystified
- Convert java.sql.Timestamp to java.util.Date
- What is the Difference between HashMap and HashTab...
- What are Checked and UnChecked Exceptions
- How to do a deep clone of an object
- What are the common methods used for session track...
- Run EJB client in Eclipse with jndi properties as ...
- J2EE Tutorial on Integrating Webservices with EJB ...
- J2EE Tutorial on JAX WS Style Webservices using JB...
- J2EE Tutorial on Webservices using JBoss
- Spring Framework - J2EE Development without EJB
- What is Service Oriented Architecture or SOA -1
- What is Service Oriented Architecture or SOA -2
- What is Service Oriented Architecture or SOA -3
- Opensource Cache/Caching Solutions in Java
- Secure Authentication in Web Based J2EE/JEE Devel...
0 Responses to Java J2EE Interview Questions - 7
Something to say?