Java developer position Interview questions Tips

1. What gives Java its “write once and run anywhere” nature?
- Java is compiled to be a byte code which is the intermediate language between source code and machine code. This byte code is not platorm specific and hence can be fed to any platform. After being fed to the JVM, which is specific to a particular operating system, the code platform specific machine code is generated thus making java platform independent.
2. What are the four corner stones of OOP?
- Abstraction, Encapsulation, Polymorphism and Inheritance.
3. Difference between a Class and an Object?
- A class is a definition or prototype whereas an object is an instance or living representation of the prototype.
4. What is the difference between method overriding and overloading?
- Overriding is a method with the same name and arguments as in a parent, whereas overloading is the same method name but different arguments.
5. What is a “stateless” protocol?
- Without getting into lengthy debates, it is generally accepted that protocols like HTTP are stateless i.e. there is no retention of state between a transaction which is a single request response combination.
6. What is constructor chaining and how is it achieved in Java?
- A child object constructor always first needs to construct its parent (which in turn calls its parent constructor.). In Java it is done via an implicit call to the no-args constructor as the first statement.
7. What is passed by ref and what by value?
- All Java method arguments are passed by value. However, Java does manipulate objects by reference, and all object variables themselves are references
8. Can RMI and Corba based applications interact?
- Yes they can. RMI is available with IIOP as the transport protocol instead of JRMP.
9. You can create a String object as String str = “abc"; Why cant a button object be created as Button bt = “abc";? Explain
- The main reason you cannot create a button by Button bt1= “abc"; is because “abc” is a literal string (something slightly different than a String object, by the way) and bt1 is a Button object. The only object in Java that can be assigned a literal String is java.lang.String. Important to note that you are NOT calling a java.lang.String constuctor when you type String s = “abc";
10. What does the “abstract” keyword mean in front of a method? A class?
- Abstract keyword declares either a method or a class. If a method has a abstract keyword in front of it,it is called abstract method.Abstract method hs no body.It has only arguments and return type.Abstract methods act as placeholder methods that are implemented in the subclasses. Abstract classes can’t be instantiated.If a class is declared as abstract,no objects of that class can be created.If a class contains any abstract method it must be declared as abstract.
11. How many methods do u implement if implement the Serializable Interface?
- The Serializable interface is just a “marker” interface, with no methods of its own to implement. Other ‘marker’ interfaces are
12. java.rmi.Remote
13. java.util.EventListener
14. What are the practical benefits, if any, of importing a specific class rather than an entire package (e.g. import java.net.* versus import java.net.Socket)?
- It makes no difference in the generated class files since only the classes that are actually used are referenced by the generated class file. There is another practical benefit to importing single classes, and this arises when two (or more) packages have classes with the same name. Take java.util.Timer and javax.swing.Timer, for example. If I import java.util.* and javax.swing.* and then try to use “Timer", I get an error while compiling (the class name is ambiguous between both packages). Let’s say what you really wanted was the javax.swing.Timer class, and the only classes you plan on using in java.util are Collection and HashMap. In this case, some people will prefer to import java.util.Collection and import java.util.HashMap instead of importing java.util.*. This will now allow them to use Timer, Collection, HashMap, and other javax.swing classes without using fully qualified class names in.
15. What is the difference between logical data independence and physical data independence?
- Logical Data Independence - meaning immunity of external schemas to changeds in conceptual schema. Physical Data Independence - meaning immunity of conceptual schema to changes in the internal schema.
16. What is a user-defined exception?
- Apart from the exceptions already defined in Java package libraries, user can define his own exception classes by extending Exception class.
17. Describe the visitor design pattern?
- Represents an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates. The root of a class hierarchy defines an abstract method to accept a visitor. Subclasses implement this method with visitor.visit(this). The Visitor interface has visit methods for all subclasses of the baseclass in the hierarchy.