Wednesday, October 24, 2007

CORE JAVA Interview Questions-Part10


Question: How many methods do u implement if implement the Serializable Interface?

Answer: The Serializable interface is just a "marker" interface, with no methods of its own to implement. Other 'marker' interfaces are

java.rmi.Remote

java.util.EventListener

Question: 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)?

Answer: 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.

Question: What is the difference between logical data independence and physical data independence?

Answer: 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.

Question: What is user defined exception ?

Answer: Apart from the exceptions already defined in Java package libraries, user can define his own exception classes by extending Exception class.

Question: Difference Between Abstraction and Encapsulation

Answer: Abstraction is removing some distinctions between objects, so as to show their commonalities.

Encapsulation is hiding the details of the implementation of an object so that there are no external dependencies on the particular implementation.

Question: Why are there no global variables in Java?

Answer: Global variables are considered bad form for a variety of reasons:

· Adding state variables breaks referential transparency (you no longer can understand a statement or expression on its own: you need to understand it in the context of the settings of the global variables).

· State variables lessen the cohesion of a program: you need to know more to understand how something works. A major point of Object-Oriented programming is to break up global state into more easily understood collections of local state.

· When you add one variable, you limit the use of your program to one instance. What you thought was global, someone else might think of as local: they may want to run two copies of your program at once.

For these reasons, Java decided to ban global variables.

0 comments:

Advertisement

 

Copyright 2008 All Rights Reserved Revolution Two Church theme by Brian Gardner Converted into Blogger Template by Bloganol dot com