Você está na página 1de 38

OOPS Interview Questions and Answers (part 1)

1) What is meant by Object Oriented Programming? OOP is a method of programming in which programs are organised as cooperative collections of objects. Each object is an instance of a class and each class belong to a hierarchy. 2) What is a Class? Class is a template for a set of objects that share a common structure and a common behaviour. 3) What is an Object? Object is an instance of a class. It has state,behaviour and identity. It is also called as an instance of a class. 4) What is an Instance? An instance has state, behaviour and identity. The structure and behaviour of similar classes are defined in their common class. An instance is also called as an object. 5) What are the core OOPs concepts? Abstraction, Encapsulation,Inheritance and Polymorphism are the core OOPs concepts. 6) What is meant by abstraction? Abstraction defines the essential characteristics of an object that distinguish it from all other kinds of objects. Abstraction provides crisply-defined conceptual boundaries relative to the perspective of the viewer. Its the process of focussing on the essential characteristics of an object. Abstraction is one of the fundamental elements of the object model. 7) What is meant by Encapsulation? Encapsulation is the process of compartmentalising the elements of an abtraction that defines the structure and behaviour. Encapsulation helps to separate the contractual interface of an abstraction and implementation. What is meant by Inheritance? Inheritance is a relationship among classes, wherein one class shares the structure or behaviour defined in another class. This is called Single Inheritance. If a class shares the structure or behaviour from multiple classes, then it is called Multiple Inheritance. Inheritance defines is-a hierarchy among classes in which one subclass inherits from one or more generalised superclasses.

9) What is meant by Polymorphism? Polymorphism literally means taking more than one form. Polymorphism is a characteristic of being able to assign a different behavior or value in a subclass, to something that was declared in a parent class. 10) What is an Abstract Class? Abstract class is a class that has no instances. An abstract class is written with the expectation that its concrete subclasses will add to its structure and behaviour, typically by implementing its abstract operations. 11) What is an Interface? Interface is an outside view of a class or object which emphaizes its abstraction while hiding its structure and secrets of its behaviour. 12) What is a base class? Base class is the most generalised class in a class structure. Most applications have such root classes. In Java, Object is the base class for all classes. 13) What is a subclass? Subclass is a class that inherits from one or more classes 14) What is a superclass? superclass is a class from which another class inherits. 15) What is a constructor? Constructor is an operation that creates an object and/or initialises its state. 16) What is a destructor? Destructor is an operation that frees the state of an object and/or destroys the object itself. In Java, there is no concept of destructors. Its taken care by the JVM. 17) What is meant by Binding? Binding denotes association of a name with a class. 18) What is meant by static binding? Static binding is a binding in which the class association is made during compile time. This is also called as Early binding. 19) What is meant by Dynamic binding? Dynamic binding is a binding in which the class association is not made until the object is created at execution time. It is also called as Late binding.

20) Define Modularity? Modularity is the property of a system that has been decomposed into a set of cohesive and loosely coupled modules. 21) What is meant by Persistence? Persistence is the property of an object by which its existence transcends space and time. 22) What is colloboration? Colloboration is a process whereby several objects cooperate to provide some higher level behaviour. 23) In Java, How to make an object completely encapsulated? All the instance variables should be declared as private and public getter and setter methods should be provided for accessing the instance variables. 24) How is polymorphism acheived in java? Inheritance, Overloading and Overriding are used to acheive Polymorphism in java. 1.What are the principle concepts of OOPS? There are four principle concepts upon which object oriented design and programming rest. They are:

Abstraction Polymorphism Inheritance Encapsulation (i.e. easily remembered as A-PIE).

2.What is Abstraction? Abstraction refers to the act of representing essential features without including the background details or explanations.

3.What is Encapsulation? Encapsulation is a technique used for hiding the properties and behaviors of an object and allowing outside access only as appropriate. It prevents other objects from directly altering or accessing the properties or methods of the encapsulated object.

4.What is the difference between abstraction and encapsulation?

Abstraction focuses on the outside view of an object (i.e. the interface) Encapsulation (information hiding) prevents clients from seeing its inside view, where the behavior of the abstraction is implemented. Abstraction solves the problem in the design side while Encapsulation is the Implementation. Encapsulation is the deliverables of Abstraction. Encapsulation barely talks about grouping up your abstraction to suit the developer needs.

5.What is Inheritance?

Inheritance is the process by which objects of one class acquire the properties of objects of another class. A class that is inherited is called a superclass. The class that does the inheriting is called a subclass. Inheritance is done by using the keyword extends. The two most common reasons to use inheritance are: o To promote code reuse o To use polymorphism

6.What is Polymorphism? Polymorphism is briefly described as "one interface, many implementations." Polymorphism is a characteristic of being able to assign a different meaning or usage to something in different contexts - specifically, to allow an entity such as a variable, a function, or an object to have more than one form.

7.How does Java implement polymorphism? (Inheritance, Overloading and Overriding are used to achieve Polymorphism in java). Polymorphism manifests itself in Java in the form of multiple methods having the same name.

In some cases, multiple methods have the same name, but different formal argument lists (overloaded methods). In other cases, multiple methods have the same name, same return type, and same formal argument list (overridden methods).

8.Explain the different forms of Polymorphism. There are two types of polymorphism one is Compile time polymorphism and the other is run time polymorphism. Compile time polymorphism is method overloading. Runtime time polymorphism is done using inheritance and interface.

Note: From a practical programming viewpoint, polymorphism manifests itself in three distinct forms in Java:

Method overloading Method overriding through inheritance Method overriding through the Java interface

9.What is runtime polymorphism or dynamic method dispatch? In Java, runtime polymorphism or dynamic method dispatch is a process in which a call to an overridden method is resolved at runtime rather than at compile-time. In this process, an overridden method is called through the reference variable of a superclass. The determination of the method to be called is based on the object being referred to by the reference variable.

10.What is Dynamic Binding? Binding refers to the linking of a procedure call to the code to be executed in response to the call. Dynamic binding (also known as late binding) means that the code associated with a given procedure call is not known until the time of the call at run-time. It is associated with polymorphism and inheritance.

11.What is method overloading? Method Overloading means to have two or more methods with same name in the same class with different arguments. The benefit of method overloading is that it allows you to implement methods that support the same semantic operation but differ by argument number or type. Note:

Overloaded methods MUST change the argument list Overloaded methods CAN change the return type Overloaded methods CAN change the access modifier Overloaded methods CAN declare new or broader checked exceptions A method can be overloaded in the same class or in a subclass

12.What is method overriding? Method overriding occurs when sub class declares a method that has the same type arguments as a method declared by one of its superclass. The key benefit of overriding is the ability to define behavior thats specific to a particular subclass type. Note:

The overriding method cannot have a more restrictive access modifier than the method being overridden (Ex: You cant override a method marked public and make it protected). You cannot override a method marked final You cannot override a method marked static

13.What are the differences between method overloading and method overriding? Overloaded Method Arguments Return type Exceptions Must change Can change Can change Overridden Method Must not change Cant change except for covariant returns Can reduce or eliminate. Must not throw new or broader checked exceptions Must not make more restrictive (can be less restrictive) Object type determines which method is selected. Happens at runtime.

Access Invocation

Can change Reference type determines which overloaded version is selected. Happens at compile time.

14.Can overloaded methods be override too? Yes, derived classes still can override the overloaded methods. Polymorphism can still happen. Compiler will not binding the method calls since it is overloaded, because it might be overridden now or in the future.

15.Is it possible to override the main method? NO, because main is a static method. A static method can't be overridden in Java.

16.How to invoke a superclass version of an Overridden method? To invoke a superclass method that has been overridden in a subclass, you must either call the method directly through a superclass instance, or use the super prefix in the subclass itself. From the point of the view of the subclass, the super prefix provides an explicit reference to the superclass' implementation of the method.
// From subclass

super.overriddenMethod();

17.What is super?
super

is a keyword which is used to access the method or member variables from the superclass. If a method hides one of the member variables in its superclass, the method can refer to the hidden variable through the use of the super keyword. In the same way, if a method overrides one of the methods in its superclass, the method can invoke the overridden method through the use of the super keyword. Note:

You can only go back one level. In the constructor, if you use super(), it must be the very first code, and you cannot access any this.xxx variables or methods to compute its parameters.

18.How do you prevent a method from being overridden? To prevent a specific method from being overridden in a subclass, use the final modifier on the method declaration, which means "this is the final implementation of this method", the end of its inheritance hierarchy.
// } public final void exampleMethod() { Method statements

19.What is an Interface? An interface is a description of a set of methods that conforming implementing classes must have. Note:

You cant mark an interface as final. Interface variables must be static. An Interface cannot extend anything but another interfaces.

20.Can we instantiate an interface? You cant instantiate an interface directly, but you can instantiate a class that implements an interface.

21.Can we create an object for an interface?

Yes, it is always necessary to create an object implementation for an interface. Interfaces cannot be instantiated in their own right, so you must write a class that implements the interface and fulfill all the methods defined in it.

22.Do interfaces have member variables? Interfaces may have member variables, but these are implicitly public, static, and final- in other words, interfaces can declare only constants, not instance variables that are available to all implementations and may be used as key references for method arguments for example.

23.What modifiers are allowed for methods in an Interface? Only public and abstract modifiers are allowed for methods in interfaces.

24.What is a marker interface? Marker interfaces are those which do not declare any required methods, but signify their compatibility with certain operations. The java.io.Serializable interface and Cloneable are typical marker interfaces. These do not contain any methods, but classes must implement this interface in order to be serialized and de-serialized.

25.What is an abstract class? Abstract classes are classes that contain one or more abstract methods. An abstract method is a method that is declared, but contains no implementation. Note:

If even a single method is abstract, the whole class must be declared abstract. Abstract classes may not be instantiated, and require subclasses to provide implementations for the abstract methods. You cant mark a class as both abstract and final.

26.Can we instantiate an abstract class? An abstract class can never be instantiated. Its sole purpose is to be extended (subclassed).

27.What are the differences between Interface and Abstract class? Abstract Class Interfaces

An abstract class can provide complete, default code and/or just the details that have to be overridden. In case of abstract class, a class may extend only one abstract class. An abstract class can have non-abstract methods. An abstract class can have instance variables. An abstract class can have any visibility: public, private, protected. If we add a new method to an abstract class then we have the option of providing default implementation and therefore all the existing code might work properly. An abstract class can contain constructors . Abstract classes are fast.

An interface cannot provide any code at all,just the signature. A Class may implement several interfaces. All methods of an Interface are abstract. An Interface cannot have instance variables. An Interface visibility must be public (or) none. If we add a new method to an Interface then we have to track down all the implementations of the interface and define implementation for the new method. An Interface cannot contain constructors . Interfaces are slow as it requires extra indirection to find corresponding method in the actual class.

28.When should I use abstract classes and when should I use interfaces? Use Interfaces when

You see that something in your design will change frequently. If various implementations only share method signatures then it is better to use Interfaces. you need some classes to use some methods which you don't want to be included in the class, then you go for the interface, which makes it easy to just implement and make use of the methods defined in the interface.

Use Abstract Class when


If various implementations are of the same kind and use common behavior or status then abstract class is better to use. When you want to provide a generalized form of abstraction and leave the implementation task with the inheriting subclass. Abstract classes are an excellent way to create planned inheritance hierarchies. They're also a good choice for nonleaf classes in class hierarchies.

29.When you declare a method as abstract, can other nonabstract methods access it? Yes, other nonabstract methods can access a method that you declare as abstract.

30.Can there be an abstract class with no abstract methods in it? Yes, there can be an abstract class without abstract methods. 31.What is Constructor?

A constructor is a special method whose task is to initialize the object of its class. It is special because its name is the same as the class name. They do not have return types, not even void and therefore they cannot return values. They cannot be inherited, though a derived class can call the base class constructor. Constructor is invoked whenever an object of its associated class is created.

32.How does the Java default constructor be provided? If a class defined by the code does not have any constructor, compiler will automatically provide one no-parameter-constructor (default-constructor) for the class in the byte code. The access modifier (public/private/etc.) of the default constructor is the same as the class itself.

33.Can constructor be inherited? No, constructor cannot be inherited, though a derived class can call the base class constructor.

34.What are the differences between Contructors and Methods? Constructors Purpose Modifiers Return Type Name Create an instance of a class Cannot be abstract, final, native, static, or synchronized No return type, not even void Same name as the class (first letter is capitalized by convention) -- usually a noun Methods Group Java statements Can be abstract, final, native, static, or synchronized void or a valid return type Any name except the class. Method names begin with a lowercase letter by convention -- usually the name of an action

this

Refers to another constructor in the same class. If used, it must be the first line of the constructor Calls the constructor of the parent class. If used, must be the first line of the constructor Constructors are not inherited

Refers to an instance of the owning class. Cannot be used by static methods. Calls an overridden method in the parent class Methods are inherited

super

Inheritance

35.How are this() and super() used with constructors?


Constructors use this to refer to another constructor in the same class with a different parameter list. Constructors use super to invoke the superclass's constructor. If a constructor uses super, it must use it in the first line; otherwise, the compiler will complain.

36.What are the differences between Class Methods and Instance Methods? Class Methods Instance Methods Instance methods on the other hand require an instance of the class to exist before they can be called, so an instance of a class needs to be created by using the new keyword. Instance methods operate on specific instances of classes. Instance methods of the class can also not be called from within a class method unless they are being called on an instance of that class. Instance methods are not declared as static.

Class methods are methods which are declared as static. The method can be called without creating an instance of the class

Class methods can only operate on class members and not on instance members as class methods are unaware of instance members. Class methods are methods which are declared as static. The method can be called without creating an instance of the class.

37.How are this() and super() used with constructors?


Constructors use this to refer to another constructor in the same class with a different parameter list. Constructors use super to invoke the superclass's constructor. If a constructor uses super, it must use it in the first line; otherwise, the compiler will complain.

38.What are Access Specifiers? One of the techniques in object-oriented programming is encapsulation. It concerns the hiding of data in a class and making this class available only through methods. Java allows you to control access to classes, methods, and fields via so-called access specifiers..

39.What are Access Specifiers available in Java? Java offers four access specifiers, listed below in decreasing accessibility:

Public- public classes, methods, and fields can be accessed from everywhere. Protected- protected methods and fields can only be accessed within the same class to which the methods and fields belong, within its subclasses, and within classes of the same package. Default(no specifier)- If you do not set access to specific level, then such a class, method, or field will be accessible from inside the same package to which the class, method, or field belongs, but not from outside this package. Private- private methods and fields can only be accessed within the same class to which the methods and fields belong. private methods and fields are not visible within subclasses and are not inherited by subclasses. Situation
public protected

default yes no

private

Accessible to class from same package? Accessible to class from different package? 40.What is final modifier?

yes yes

yes no, unless it is a subclass

no no

The final modifier keyword makes that the programmer cannot change the value anymore. The actual meaning depends on whether it is applied to a class, a variable, or a method.

final Classes- A final class cannot have subclasses. final Variables- A final variable cannot be changed once it is initialized. final Methods- A final method cannot be overridden by subclasses.

41.What are the uses of final method? There are two reasons for marking a method as final:

Disallowing subclasses to change the meaning of the method. Increasing efficiency by allowing the compiler to turn calls to the method into inline Java code.

42.What is static block? Static block which exactly executed exactly once when the class is first loaded into JVM. Before going to the main method the static block will execute.

43.What are static variables? Variables that have only one copy per class are known as static variables. They are not attached to a particular instance of a class but rather belong to a class as a whole. They are declared by using the static keyword as a modifier.
static type varIdentifier;

where, the name of the variable is varIdentifier and its data type is specified by type. Note: Static variables that are not explicitly initialized in the code are automatically initialized with a default value. The default value depends on the data type of the variables.

44.What is the difference between static and non-static variables? A static variable is associated with the class as a whole rather than with specific instances of a class. Non-static variables take on unique values with each object instance.

45.What are static methods? Methods declared with the keyword static as modifier are called static methods or class methods. They are so called because they affect a class as a whole, not a particular instance of the class. Static methods are always invoked without reference to a particular instance of a class. Note:The use of a static method suffers from the following restrictions:

A static method can only call other static methods. A static method must only access static data. A static method cannot reference to the current object using keywords super or this. 1. Explain what is an object? An object is a combination of messages and data. Objects can receive and send messages and use messages to interact with each other. The messages contain information that is to be passed to the recipient object. 2. Explain about the Design Phase?

In the design phase, the developers of the system document their understanding of the system. Design generates the blue print of the system that is to be implemented. The first step in creating an object oriented design is the identification of classes and their relationships. 3. Explain about parametric polymorphism? Parametric polymorphism is supported by many object oriented languages and they are very important for object oriented techniques. In parametric polymorphism code is written without any specification for the type of data present. Hence it can be used any number of times. 4. Explain about multiple inheritance? Inheritance involves inheriting characteristics from its parents also they can have their own characteristics. In multiple inheritances a class can have characteristics from multiple parents or classes. A sub class can have characteristics from multiple parents and still can have its own characteristics. 5. Explain the mechanism of composition? Composition helps to simplify a complex problem into an easier problem. It makes different classes and objects to interact with each other thus making the problem to be solved automatically. It interacts with the problem by making different classes and objects to send a message to each other. 6. Explain about overriding polymorphism? Overriding polymorphism is known to occur when a data type can perform different functions. For example an addition operator can perform different functions such as addition, float addition etc. Overriding polymorphism is generally used in complex projects where the use of a parameter is more. 7. Explain about inheritance? Inheritance revolves around the concept of inheriting knowledge and class attributes from the parent class. In general sense a sub class tries to acquire characteristics from a parent class and they can also have their own characteristics. Inheritance forms an important concept in object oriented programming. 8. Explain the rationale behind Object Oriented concepts? Object oriented concepts form the base of all modern programming languages. Understanding the basic concepts of object-orientation helps a developer to use various modern day programming languages, more effectively. 9.Explain about instance in object oriented programming? Every class and an object have an instance. Instance of a particular object is created at runtime. Values defined for a particular object define its State. Instance of an object explains the relation ship between different elements. 10) Explain about encapsulation? Encapsulation passes the message without revealing the exact functional details of the class. It allows only the relevant information to the user without revealing the functional mechanism through which a particular class had functioned. 11) Explain about polymorphism? Polymorphism helps a sub class to behave like a parent class. When an object belonging to different data types respond to methods which have a same name, the only condition being that those methods should perform different function. 12) Explain about object oriented databases?

Object oriented databases are very popular such as relational database management systems. Object oriented databases systems use specific structure through which they extract data and they combine the data for a specific output. These DBMS use object oriented languages to make the process easier. 13) What are all the languages which support OOP? There are several programming languages which are implementing OOP because of its close proximity to solve real life problems. Languages such as Python, Ruby, Ruby on rails, Perl, PHP, Cold fusion, etc use OOP. Still many languages prefer to use DOM based languages due to the ease in coding. 14) Explain the implementation phase with respect to OOP? The design phase is followed by OOP, which is the implementation phase. OOP provides specifications for writing programs in a programming language. During the implementation phase, programming is done as per the requirements gathered during the analysis and design phases. 15) Explain about Object oriented programming? Object oriented programming is one of the most popular methodologies in software development. It offers a powerful model for creating computer programs. It speeds the program development process, improves maintenance and enhances reusability of programs. 16) Explain about a class? Class describes the nature of a particular thing. Structure and modularity is provided by a Class in object oriented programming environment. Characteristics of the class should be understandable by an ordinary non programmer and it should also convey the meaning of the problem statement to him. Class acts like a blue print.

46.What is an Iterator ?

The Iterator interface is used to step through the elements of a Collection. Iterators let you process each element of a Collection. Iterators are a generic way to go through all the elements of a Collection no matter how it is organized. Iterator is an Interface implemented a different way for every Collection.

47.How do you traverse through a collection using its Iterator? To use an iterator to traverse through the contents of a collection, follow these steps:

Obtain an iterator to the start of the collection by calling the collections iterator() method. Set up a loop that makes a call to hasNext(). Have the loop iterate as long as hasNext() returns true. Within the loop, obtain each element by calling next().

48.How do you remove elements during Iteration?

Iterator also has a method remove() when remove is called, the current element in the iteration is deleted.

49.What is the difference between Enumeration and Iterator? Enumeration Enumeration doesn't have a remove() method Enumeration acts as Read-only interface, because it has the methods only to traverse and fetch the objects Iterator Iterator has a remove() method Can be abstract, final, native, static, or synchronized

Note: So Enumeration is used whenever we want to make Collection objects as Read-only.

50.How is ListIterator? ListIterator is just like Iterator, except it allows us to access the collection in either the forward or backward direction and lets us modify an element

51.What is the List interface?


The List interface provides support for ordered collections of objects. Lists may contain duplicate elements.

52.What are the main implementations of the List interface ? The main implementations of the List interface are as follows :

ArrayList : Resizable-array implementation of the List interface. The best all-around implementation of the List interface. Vector : Synchronized resizable-array implementation of the List interface with additional "legacy methods." LinkedList : Doubly-linked list implementation of the List interface. May provide better performance than the ArrayList implementation if elements are frequently inserted or deleted within the list. Useful for queues and double-ended queues (deques).

53.What are the advantages of ArrayList over arrays ? Some of the advantages ArrayList has over arrays are:

It can grow dynamically It provides more powerful insertion and search mechanisms than arrays.

54.Difference between ArrayList and Vector ? ArrayList ArrayList is NOT synchronized by default. ArrayList can use only Iterator to access the elements. The ArrayList increases its array size by 50 percent if it runs out of room. ArrayList has no default size. Vector Vector List is synchronized by default. Vector list can use Iterator and Enumeration Interface to access the elements. A Vector defaults to doubling the size of its array if it runs out of room While vector has a default size of 10.

55.How to obtain Array from an ArrayList ? Array can be obtained from an ArrayList using toArray() method on ArrayList.
List arrayList = new ArrayList(); arrayList.add( Object a[] = arrayList.toArray();

56.Why insertion and deletion in ArrayList is slow compared to LinkedList ?

ArrayList internally uses and array to store the elements, when that array gets filled by inserting elements a new array of roughly 1.5 times the size of the original array is created and all the data of old array is copied to new array. During deletion, all elements present in the array after the deleted elements have to be moved one step back to fill the space created by deletion. In linked list data is stored in nodes that have reference to the previous node and the next node so adding element is simple as creating the node an updating the next pointer on the last node and the previous pointer on the new node. Deletion in linked list is fast because it involves only updating the next pointer in the node before the deleted node and updating the previous pointer in the node after the deleted node.

57.Why are Iterators returned by ArrayList called Fail Fast ?

Because, if list is structurally modified at any time after the iterator is created, in any way except through the iterator's own remove or add methods, the iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.

58.How do you decide when to use ArrayList and When to use LinkedList? If you need to support random access, without inserting or removing elements from any place other than the end, then ArrayList offers the optimal collection. If, however, you need to frequently add and remove elements from the middle of the list and only access the list elements sequentially, then LinkedList offers the better implementation. 59.What is the Set interface ?

The Set interface provides methods for accessing the elements of a finite mathematical set Sets do not allow duplicate elements Contains no methods other than those inherited from Collection It adds the restriction that duplicate elements are prohibited Two Set objects are equal if they contain the same elements

60.What are the main Implementations of the Set interface ? The main implementations of the List interface are as follows:

HashSet TreeSet LinkedHashSet EnumSet

61.What is a HashSet ?

A HashSet is an unsorted, unordered Set. It uses the hashcode of the object being inserted (so the more efficient your hashcode() implementation the better access performance youll get). Use this class when you want a collection with no duplicates and you dont care about order when you iterate through it.

62.What is a TreeSet ? TreeSet is a Set implementation that keeps the elements in sorted order. The elements are sorted according to the natural order of elements or by the comparator provided at creation time.

63.What is an EnumSet ? An EnumSet is a specialized set for use with enum types, all of the elements in the EnumSet type that is specified, explicitly or implicitly, when the set is created.

64.Difference between HashSet and TreeSet ? HashSet HashSet is under set interface i.e. it does not guarantee for either sorted order or sequence order. We can add any type of elements to hash set. TreeSet TreeSet is under set i.e. it provides elements in a sorted order (acceding order). We can add only similar types of elements to tree set.

65.What is a Map ?

A map is an object that stores associations between keys and values (key/value pairs). Given a key, you can find its value. Both keys and values are objects. The keys must be unique, but the values may be duplicated. Some maps can accept a null key and null values, others cannot.

66.What are the main Implementations of the Map interface ? The main implementations of the List interface are as follows:

HashMap HashTable TreeMap EnumMap

67.What is a TreeMap ? TreeMap actually implements the SortedMap interface which extends the Map interface. In a TreeMap the data will be sorted in ascending order of keys according to the natural order for the key's class, or by the comparator provided at creation time. TreeMap is based on the Red-Black tree data structure.

68.How do you decide when to use HashMap and when to use TreeMap ?

For inserting, deleting, and locating elements in a Map, the HashMap offers the best alternative. If, however, you need to traverse the keys in a sorted order, then TreeMap is your better alternative. Depending upon the size of your collection, it may be faster to add elements to a HashMap, then convert the map to a TreeMap for sorted key traversal.

69.Difference between HashMap and Hashtable ? HashMap HashMap lets you have null values as well as one null key. The iterator in the HashMap is fail-safe (If you change the map while iterating, youll know). HashMap is unsynchronized. Hashtable HashTable does not allows null values as key and value. The enumerator for the Hashtable is not failsafe. Hashtable is synchronized.

Note: Only one NULL is allowed as a key in HashMap. HashMap does not allow multiple keys to be NULL. Nevertheless, it can have multiple NULL values.

70.How does a Hashtable internally maintain the key-value pairs? TreeMap actually implements the SortedMap interface which extends the Map interface. In a TreeMap the data will be sorted in ascending order of keys according to the natural order for the key's class, or by the comparator provided at creation time. TreeMap is based on the Red-Black tree data structure.

71.What Are the different Collection Views That Maps Provide? Maps Provide Three Collection Views.

Key Set - allow a map's contents to be viewed as a set of keys. Values Collection - allow a map's contents to be viewed as a set of values. Entry Set - allow a map's contents to be viewed as a set of key-value mappings.

72.What is a KeySet View ? KeySet is a set returned by the keySet() method of the Map Interface, It is a set that contains all the keys present in the Map.

73.What is a Values Collection View ? Values Collection View is a collection returned by the values() method of the Map Interface, It contains all the objects present as values in the map.

74.What is an EntrySet View ? Entry Set view is a set that is returned by the entrySet() method in the map and contains Objects of type Map. Entry each of which has both Key and Value.

75.How do you sort an ArrayList (or any list) of user-defined objects ? Create an implementation of the java.lang.Comparable interface that knows how to order your objects and pass it to java.util.Collections.sort(List, Comparator).

76.What is the Comparable interface ? The Comparable interface is used to sort collections and arrays of objects using the Collections.sort() and java.utils.Arrays.sort() methods respectively. The objects of the class implementing the Comparable interface can be ordered. The Comparable interface in the generic form is written as follows:
interface Comparable<T>

where T is the name of the type parameter. All classes implementing the Comparable interface must implement the compareTo() method that has the return type as an integer. The signature of the compareTo() method is as follows:
int i = object1.compareTo(object2)

If object1 < object2: The value of i returned will be negative. If object1 > object2: The value of i returned will be positive. If object1 = object2: The value of i returned will be zero.

77.What are the differences between the Comparable and Comparator interfaces ? Comparable It uses the compareTo() method. Comparato t uses the compare() method.

int objectOne.compareTo(objectTwo). It is necessary to modify the class whose instance is going to be sorted. Only one sort sequence can be created. It is frequently used by the API classes.

int compare(ObjOne, ObjTwo) A separate class can be created in order to sort the instances. Many sort sequences can be created. It used by third-party classes to sort instances.

Asp.net question
What is a delegate? What is a Multicast Delegate? Delegate - It is a type safe function pointer. It is a type that holds the reference of a method. A delegate may be used to call a method asynchronously. Multicast Delegate - it is a delegate that holds reference of more than one method. Multicast Delegates must have a return type of void.

What is an application server?


As defined in Wikipedia, an application server is a software engine that delivers applications to client computers or devices. The application server runs your server code. Some well known application servers are IIS (Microsoft), WebLogic Server (BEA), JBoss (Red Hat), WebSphere (IBM).

Compare C# and VB.NET


A detailed comparison can be found over here.

What is a base class and derived class?


A class is a template for creating an object. The class from which other classes derive fundamental functionality is called a base class. For e.g. If Class Y derives from Class X, then Class X is a base class. The class which derives functionality from a base class is called a derived class. If Class Y derives from Class X, then Class Y is a derived class.

What is an extender class?

An extender class allows you to extend the functionality of an existing control. It is used in Windows forms applications to add properties to controls. A demonstration of extender classes can be found over here.

What is inheritance?
Inheritance represents the relationship between two classes where one type derives functionality from a second type and then extends it by adding new methods, properties, events, fields and constants. C# support two types of inheritance:

Implementation inheritance Interface inheritance

What is implementation and interface inheritance?


When a class (type) is derived from another class(type) such that it inherits all the members of the base type it is Implementation Inheritance. When a type (class or a struct) inherits only the signatures of the functions from another type it is Interface Inheritance. In general Classes can be derived from another class, hence support Implementation inheritance. At the same time Classes can also be derived from one or more interfaces. Hence they support Interface inheritance. Source: Exforsys.

What is inheritance hierarchy?


The class which derives functionality from a base class is called a derived class. A derived class can also act as a base class for another class. Thus it is possible to create a tree-like structure that illustrates the relationship between all related classes. This structure is known as the inheritance hierarchy.

How do you prevent a class from being inherited? When should you use inheritance?
Read this.

In VB.NET you use the NotInheritable modifier to prevent programmers from using the class as a base class. In C#, use the sealed keyword.

Define Overriding?
Overriding is a concept where a method in a derived class uses the same name, return type, and arguments as a method in its base class. In other words, if the derived class contains its own implementation of the method rather than using the method in the base class, the process is called overriding.

Can you use multiple inheritance in .NET?

.NET supports only single inheritance. However the purpose is accomplished using multiple interfaces.

Why dont we have multiple inheritance in .NET?


There are several reasons for this. In simple words, the efforts are more, benefits are less. Different languages have different implementation requirements of multiple inheritance. So in order to implement multiple inheritance, we need to study the implementation aspects of all the languages that are CLR compliant and then implement a common methodology of implementing it. This is too much of efforts. Moreover multiple interface inheritance very much covers the benefits that multiple inheritance has.

What is an Interface?
An interface is a standard or contract that contains only the signatures of methods or events. The implementation is done in the class that inherits from this interface. Interfaces are primarily used to set a common standard or contract.

When should you use abstract class vs interface or What is the difference between an abstract class and interface?
I would suggest you to read this. There is a good comparison given over here.

What are events and delegates?


An event is a message sent by a control to notify the occurrence of an action. However it is not known which object receives the event. For this reason, .NET provides a special type called Delegate which acts as an intermediary between the sender object and receiver object.

What is business logic?

It is the functionality which handles the exchange of information between database and a user interface.

What is a component?
Component is a group of logically related classes and methods. A component is a class that implements the IComponent interface or uses a class that implements IComponent interface.

What is a control?

A control is a component that provides user-interface (UI) capabilities. The differences can be studied over here.

What are the differences between a control and a component? What are design patterns?
Design patterns are common solutions to common design problems.

What is a connection pool?

A connection pool is a collection of connections which are shared between the clients requesting one. Once the connection is closed, it returns back to the pool. This allows the connections to be reused.

What is a flat file?

A flat file is the name given to text, which can be read or written only sequentially.

What are functional and non-functional requirements?

Functional requirements defines the behavior of a system whereas non-functional requirements specify how the system should behave; in other words they specify the quality requirements and judge the behavior of a system. E.g. Functional - Display a chart which shows the maximum number of products sold in a region. Non-functional The data presented in the chart must be updated every 5 minutes.

What is the global assembly cache (GAC)?


GAC is a machine-wide cache of assemblies that allows .NET applications to share libraries. GAC solves some of the problems associated with dlls (DLL Hell).

What is a stack? What is a heap? Give the differences between the two?

Stack is a place in the memory where value types are stored. Heap is a place in the memory where the reference types are stored. Check this link for the differences.

What is instrumentation? What is code review?

It is the ability to monitor an application so that information about the applications progress, performance and status can be captured and reported.

The process of examining the source code generally through a peer, to verify it against best practices.

What is logging?

Logging is the process of persisting information about the status of an application.

What are mock-ups?

Mock-ups are a set of designs in the form of screens, diagrams, snapshots etc., that helps verify the design and acquire feedback about the applications requirements and use cases, at an early stage of the design process.

What is a Form?

A form is a representation of any window displayed in your application. Form can be used to create standard, borderless, floating, modal windows.

What is a multiple-document interface(MDI)? What is a single-document interface (SDI) ? What is BLOB ?

A user interface container that enables a user to work with more than one document at a time. E.g. Microsoft Excel. A user interface that is created to manage graphical user interfaces and controls into single windows. E.g. Microsoft Word A BLOB (binary large object) is a large item such as an image or an exe represented in binary form.

What is ClickOnce?
ClickOnce is a new deployment technology that allows you to create and publish selfupdating applications that can be installed and run with minimal user interaction.

What is object role modeling (ORM) ? What is a private assembly? What is a shared assembly?

It is a logical model for designing and querying database models. There are various ORM tools in the market like CaseTalk, Microsoft Visio for Enterprise Architects, Infagon etc. A private assembly is local to the installation directory of an application and is used only by that application. A shared assembly is kept in the global assembly cache (GAC) and can be used by one or more applications on a machine.

What is the difference between user and custom controls?

User controls are easier to create whereas custom controls require extra effort. User controls are used when the layout is static whereas custom controls are used in dynamic layouts. A user control cannot be added to the toolbox whereas a custom control can be. A separate copy of a user control is required in every application that uses it whereas since custom controls are stored in the GAC, only a single copy can be used by all applications.

Where do custom controls reside?


In the global assembly cache (GAC).

What is a third-party control ?

A third-party control is one that is not created by the owners of a project. They are usually used to save time and resources and reuse the functionality developed by others (thirdparty).

What is a binary formatter? What is Boxing/Unboxing?

Binary formatter is used to serialize and deserialize an object in binary format.

Boxing is used to convert value types to object. E.g. int x = 1; object obj = x ; Unboxing is used to convert the object back to the value type. E.g. int y = (int)obj; Boxing/unboxing is quiet an expensive operation.

What is a COM Callable Wrapper (CCW)?


CCW is a wrapper created by the common language runtime(CLR) that enables COM components to access .NET objects.

What is a Runtime Callable Wrapper (RCW)?


RCW is a wrapper created by the common language runtime(CLR) to enable .NET components to call COM components.

What is a digital signature?


A digital signature is an electronic signature used to verify/gurantee the identity of the individual who is sending the message.

What is garbage collection?


Garbage collection is the process of managing the allocation and release of memory in your applications. Read this article for more information.

What is globalization?
Globalization is the process of customizing applications that support multiple cultures and regions.

What is localization?
Localization is the process of customizing applications that support a given culture and regions.

What is MIME?
The definition of MIME or Multipurpose Internet Mail Extensions as stated in MSDN is MIME is a standard that can be used to include content of various types in a single message. MIME extends the Simple Mail Transfer Protocol (SMTP) format of mail messages to include multiple content, both textual and non-textual. Parts of the message may be images, audio, or text in different character sets. The MIME standard derives from RFCs such as 2821 and 2822. Quoted from here. What is the Microsoft.NET?

.NET is a set of technologies designed to transform the internet into a full scale distributed platform. It provides new ways of connecting systems, information and devices through a collection of web services. It also provides a language independent, consistent programming model across all tiers of an application. The goal of the .NET platform is to simplify web development by providing all of the tools and technologies that one needs to build distributed web applications. What is the .NET Framework? The .NET Framework is set of technologies that form an integral part of the .NET Platform. It is Microsoft's managed code programming model for building applications that have visually stunning user experiences, seamless and secure communication, and the ability to model a range of business processes. The .NET Framework has two main components: the common language runtime (CLR) and .NET Framework class library. The CLR is the foundation of the .NET framework and provides a common set of services for projects that act as building blocks to build up applications across all tiers. It simplifies development and provides a robust and simplified environment which provides common services to build application. The .NET framework class library is a collection of reusable types and exposes features of the runtime. It contains of a set of classes that is used to access common functionality. What is CLR? The .NET Framework provides a runtime environment called the Common Language Runtime or CLR. The CLR can be compared to the Java Virtual Machine or JVM in Java. CLR handles the execution of code and provides useful services for the implementation of the program. In addition to executing code, CLR provides services such as memory management, thread management, security management, code verification, compilation, and other system services. It enforces rules that in turn provide a robust and secure execution environment for .NET applications. What is CTS? Common Type System (CTS) describes the datatypes that can be used by managed code. CTS defines how these types are declared, used and managed in the runtime. It facilitates cross-language integration, type safety, and high performance code execution. The rules defined in CTS can be used to define your own classes and values. What is CLS? Common Language Specification (CLS) defines the rules and standards to which languages must adhere to in order to be compatible with other .NET languages. This enables C# developers to inherit from classes defined in VB.NET or other .NET compatible languages. What is managed code? The .NET Framework provides a run-time environment called the Common Language Runtime, which manages the execution of code and provides services that make the development process easier. Compilers and tools expose the runtime's functionality and enable you to write code that benefits from this managed execution environment. The code that runs within the common language runtime is called managed code. What is MSIL? When the code is compiled, the compiler translates your code into Microsoft intermediate language (MSIL). The common language runtime includes a JIT compiler for converting this MSIL then to native code.

MSIL contains metadata that is the key to cross language interoperability. Since this metadata is standardized across all .NET languages, a program written in one language can understand the metadata and execute code, written in a different language. MSIL includes instructions for loading, storing, initializing, and calling methods on objects, as well as instructions for arithmetic and logical operations, control flow, direct memory access, exception handling, and other operations. What is JIT? JIT is a compiler that converts MSIL to native code. The native code consists of hardware specific instructions that can be executed by the CPU. Rather than converting the entire MSIL (in a portable executable[PE]file) to native code, the JIT converts the MSIL as it is needed during execution. This converted native code is stored so that it is accessible for subsequent calls. What is portable executable (PE)? PE is the file format defining the structure that all executable files (EXE) and Dynamic Link Libraries (DLL) must use to allow them to be loaded and executed by Windows. PE is derived from the Microsoft Common Object File Format (COFF). The EXE and DLL files created using the .NET Framework obey the PE/COFF formats and also add additional header and data sections to the files that are only used by the CLR. What is an application domain? Application domain is the boundary within which an application runs. A process can contain multiple application domains. Application domains provide an isolated environment to applications that is similar to the isolation provided by processes. An application running inside one application domain cannot directly access the code running inside another application domain. To access the code running in another application domain, an application needs to use a proxy. How does an AppDomain get created? AppDomains are usually created by hosts. Examples of hosts are the Windows Shell, ASP.NET and IE. When you run a .NET application from the command-line, the host is the Shell. The Shell creates a new AppDomain for every application. AppDomains can also be explicitly created by .NET applications. What is an assembly? An assembly is a collection of one or more .exe or dlls. An assembly is the fundamental unit for application development and deployment in the .NET Framework. An assembly contains a collection of types and resources that are built to work together and form a logical unit of functionality. An assembly provides the CLR with the information it needs to be aware of type implementations. What are the contents of assembly? A static assembly can consist of four elements: Assembly manifest - Contains the assembly metadata. An assembly manifest contains the information about the identity and version of the assembly. It also contains the information required to resolve references to types and resources. Type metadata - Binary information that describes a program. Microsoft intermediate language (MSIL) code. A set of resources. What are the different types of assembly?

Assemblies can also be private or shared. A private assembly is installed in the installation directory of an application and is accessible to that application only. On the other hand, a shared assembly is shared by multiple applications. A shared assembly has a strong name and is installed in the GAC. We also have satellite assemblies that are often used to deploy language-specific resources for an application. What is a dynamic assembly? A dynamic assembly is created dynamically at run time when an application requires the types within these assemblies. What is a strong name? You need to assign a strong name to an assembly to place it in the GAC and make it globally accessible. A strong name consists of a name that consists of an assembly's identity (text name, version number, and culture information), a public key and a digital signature generated over the assembly. The .NET Framework provides a tool called the Strong Name Tool (Sn.exe), which allows verification and key pair and signature generation. What is GAC? What are the steps to create an assembly and add it to the GAC? The global assembly cache (GAC) is a machine-wide code cache that stores assemblies specifically designated to be shared by several applications on the computer. You should share assemblies by installing them into the global assembly cache only when you need to. Steps - Create a strong name using sn.exe tool eg: sn -k mykey.snk - in AssemblyInfo.cs, add the strong name eg: [assembly: AssemblyKeyFile("mykey.snk")] - recompile project, and then install it to GAC in two ways : drag & drop it to assembly folder (C:\WINDOWS\assembly OR C:\WINNT\assembly) (shfusion.dll tool) gacutil -i abc.dll What is the caspol.exe tool used for? The caspol tool grants and modifies permissions to code groups at the user policy, machine policy, and enterprise policy levels. What is a garbage collector? A garbage collector performs periodic checks on the managed heap to identify objects that are no longer required by the program and removes them from memory. What are generations and how are they used by the garbage collector? Generations are the division of objects on the managed heap used by the garbage collector. This mechanism allows the garbage collector to perform highly optimized garbage collection. The unreachable objects are placed in generation 0, the reachable objects are placed in generation 1, and the objects that survive the collection process are promoted to higher generations. What is Ilasm.exe used for? Ilasm.exe is a tool that generates PE files from MSIL code. You can run the resulting executable to determine whether the MSIL code performs as expected.

What is Ildasm.exe used for? Ildasm.exe is a tool that takes a PE file containing the MSIL code as a parameter and creates a text file that contains managed code. What is the ResGen.exe tool used for? ResGen.exe is a tool that is used to convert resource files in the form of .txt or .resx files to common language runtime binary .resources files that can be compiled into satellite assemblies. What is ASP.NET? Microsoft ASP.NET is a server side technology that enables programmers to build dynamic Web sites, web applications, and XML Web services. It is a part of the .NET based environment and is built on the Common Language Runtime (CLR) . So programmers can write ASP.NET code using any .NET compatible language. What are the differences between ASP.NET 1.1 and ASP.NET 2.0? A comparison chart containing the differences between ASP.NET 1.1 and ASP.NET 2.0 can be found over here. Which is the latest version of ASP.NET? What were the previous versions released? The latest version of ASP.NET is 2.0. There have been 3 versions of ASP.NET released as of date. They are as follows : ASP.NET 1.0 Released on January 16, 2002. ASP.NET 1.1 Released on April 24, 2003. ASP.NET 2.0 Released on November 7, 2005. Additionally, ASP.NET 3.5 is tentatively to be released by the end of the 2007. Explain the Event Life cycle of ASP.NET 2.0? The events occur in the following sequence. Its best to turn on tracing(<% @Page Trace=true%>) and track the flow of events : PreInit This event represents the entry point of the page life cycle. If you need to change the Master page or theme programmatically, then this would be the event to do so. Dynamic controls are created in this event. Init Each control in the control collection is initialized. Init Complete* - Page is initialized and the process is completed. PreLoad* - This event is called before the loading of the page is completed. Load This event is raised for the Page and then all child controls. The controls properties and view state can be accessed at this stage. This event indicates that the controls have been fully loaded. LoadComplete* - This event signals indicates that the page has been loaded in the memory. It also marks the beginning of the rendering stage. PreRender If you need to make any final updates to the contents of the controls or the page, then use this event. It first fires for the page and then for all the controls. PreRenderComplete* - Is called to explicitly state that the PreRender phase is completed.

SaveStateComplete* - In this event, the current state of the control is completely saved to the ViewState. Unload This event is typically used for closing files and database connections. At times, it is also used for logging some wrap-up tasks. The events marked with * have been introduced in ASP.NET 2.0. You have created an ASP.NET Application. How will you run it? With ASP.NET 2.0, Visual Studio comes with an inbuilt ASP.NET Development Server to test your pages. It functions as a local Web server. The only limitation is that remote machines cannot access pages running on this local server. The second option is to deploy a Web application to a computer running IIS version 5 or 6 or 7. Explain the AutoPostBack feature in ASP.NET? AutoPostBack allows a control to automatically postback when an event is fired. For eg: If we have a Button control and want the event to be posted to the server for processing, we can set AutoPostBack = True on the button. How do you disable AutoPostBack? Hence the AutoPostBack can be disabled on an ASP.NET page by disabling AutoPostBack on all the controls of a page. AutoPostBack is caused by a control on the page. What are the different code models available in ASP.NET 2.0? There are 2 code models available in ASP.NET 2.0. One is the single-file page and the other one is the code behind page. Which base class does the web form inherit from? Page class in the System.Web.UI namespace. Which are the new special folders that are introduced in ASP.NET 2.0? There are seven new folders introduced in ASP.NET 2.0 : \App_Browsers folder Holds browser definitions(.brower) files which identify the browser and their capabilities. \App_Code folder Contains source code (.cs, .vb) files which are automatically compiled when placed in this folder. Additionally placing web service files generates a proxy class(out of .wsdl) and a typed dataset (out of .xsd). \App_Data folder Contains data store files like .mdf (Sql Express files), .mdb, XML files etc. This folder also stores the local db to maintain membership and role information. \App_GlobalResources folder Contains assembly resource files (.resx) which when placed in this folder are compiled automatically. In earlier versions, we were required to manually use the resgen.exe tool to compile resource files. These files can be accessed globally in the application. \App_LocalResources folder Contains assembly resource files (.resx) which can be used by a specific page or control. \App_Themes folder This folder contains .css and .skin files that define the appearance of web pages and controls.

\App_WebReferences folder Replaces the previously used Web References folder. This folder contains the .disco, .wsdl, .xsd files that get generated when accessing remote web services. Explain the ViewState in ASP.NET? Http is a stateless protocol. Hence the state of controls is not saved between postbacks. Viewstate is the means of storing the state of server side controls between postbacks. The information is stored in HTML hidden fields. In other words, it is a snapshot of the contents of a page. You can disable viewstate by a control by setting the EnableViewState property to false. What does the EnableViewState property signify? EnableViewState saves the state of an object in a page between postbacks. Objects are saved in a Base64 encoded string. If you do not need to store the page, turn it off as it adds to the page size. There is an excellent article by Peter Bromberg to understand Viewstate in depth. Explain the ASP.NET Page Directives? Page directives configure the runtime environment that will execute the page. The complete list of directives is as follows: @ Assembly - Links an assembly to the current page or user control declaratively. @ Control - Defines control-specific attributes used by the ASP.NET page parser and compiler and can be included only in .ascx files (user controls). @ Implements - Indicates that a page or user control implements a specified .NET Framework interface declaratively. @ Import - Imports a namespace into a page or user control explicitly. @ Master - Identifies a page as a master page and defines attributes used by the ASP.NET page parser and compiler and can be included only in .master files. @ MasterType - Defines the class or virtual path used to type the Master property of a page. @ OutputCache - Controls the output caching policies of a page or user control declaratively. @ Page - Defines page-specific attributes used by the ASP.NET page parser and compiler and can be included only in .aspx files. @ PreviousPageType - Creates a strongly typed reference to the source page from the target of a cross-page posting. @ Reference - Links a page, user control, or COM control to the current page or user control declaratively. @ Register - Associates aliases with namespaces and classes, which allow user controls and custom server controls to be rendered when included in a requested page or user control. This list has been taken from here. Explain the Validation Controls used in ASP.NET 2.0?

Validation controls allows you to validate a control against a set of rules. There are 6 different validation controls used in ASP.NET 2.0. RequiredFieldValidator Checks if the control is not empty when the form is submitted. CompareValidator Compares the value of one control to another using a comparison operator (equal, less than, greater than etc). RangeValidator Checks whether a value falls within a given range of number, date or string. RegularExpressionValidator Confirms that the value of a control matches a pattern defined by a regular expression. Eg: Email validation. CustomValidator Calls your own custom validation logic to perform validations that cannot be handled by the built in validators. ValidationSummary Show a summary of errors raised by each control on the page on a specific spot or in a message box. How do you indentify that the page is post back? By checking the IsPostBack property. If IsPostBack is True, the page has been posted back. What are Master Pages? Master pages is a template that is used to create web pages with a consistent layout throughout your application. Master Pages contains content placeholders to hold page specific content. When a page is requested, the contents of a Master page are merged with the content page, thereby giving a consistent layout. How is a Master Page different from an ASP.NET page? The MasterPage has a @Master top directive and contains ContentPlaceHolder server controls. It is quiet similar to an ASP.NET page. How do you attach an exisiting page to a Master page? By using the MasterPageFile attribute in the @Page directive and removing some markup. How do you set the title of an ASP.NET page that is attached to a Master Page? By using the Title property of the @Page directive in the content page. Eg: <@Page MasterPageFile="Sample.master" Title="I hold content" %> What is a nested master page? How do you create them? A Nested master page is a master page associated with another master page. To create a nested master page, set the MasterPageFile attribute of the @Master directive to the name of the .master file of the base master page. What are Themes? Themes are a collection of CSS files, .skin files, and images. They are text based style definitions and are very similar to CSS, in that they provide a common look and feel throughout the website. What are skins? A theme contains one or more skin files. A skin is simply a text file with a .skin extension and contains definition of styles applied to server controls in an ASP.NET page. For eg:

<asp:button runat="server" BackColor="blue" BorderColor="Gray" Font-Bold ="true" ForeColor="white"/> Defines a skin that will be applied to all buttons throughout to give it a consistent look and feel. What is the difference between Skins and Css files? Css is applied to HTML controls whereas skins are applied to server controls. What is a User Control? User controls are reusable controls, similar to web pages. They cannot be accessed directly. Explain briefly the steps in creating a user control? Create a file with .ascx extension and place the @Control directive at top of the page. Included the user control in a Web Forms page using a @Register directive What is a Custom Control? Custom controls are compiled components that run on the server and that encapsulate user-interface and other related functionality into reusable packages. They can include all the design-time features of standard ASP.NET server controls, including full support for Visual Studio design features such as the Properties window, the visual designer, and the Toolbox. What are the differences between user and custom controls? User controls are easier to create in comparison to custom controls, however user controls can be less convenient to use in advanced scenarios. User controls have limited support for consumers who use a visual design tool whereas custom controls have full visual design tool support for consumers. A separate copy of the user control is required in each application that uses it whereas only a single copy of the custom control is required, in the global assembly cache, which makes maintenance easier. A user control cannot be added to the Toolbox in Visual Studio whereas custom controls can be added to the Toolbox in Visual Studio. User controls are good for static layout whereas custom controls are good for dynamic layout. Where do you store your connection string information? The connection string can be stored in configuration files (web.config). What is the difference between Web.config and Machine.config? Web.config files are used to apply configuration settings to a particular web application whereas machine.config file is used to apply configuration settings for all the websites on a web server. Web.config files are located in the application's root directory or inside a folder situated in a lower hierarchy. The machine.config is located in the Windows directory Microsoft.Net\Framework\Version\CONFIG. There can be multiple web.config files in an application nested at different hierarchies. However there can be only one machine.config file on a web server.

What is the difference between Server.Transfer and Response.Redirect? Response.Redirect involves a roundtrip to the server whereas Server.Transfer conserves server resources by avoiding the roundtrip. It just changes the focus of the webserver to a different page and transfers the page processing to a different page. Response.Redirect can be used for both .aspx and html pages whereas Server.Transfer can be used only for .aspx pages. Response.Redirect can be used to redirect a user to an external websites. Server.Transfer can be used only on sites running on the same server. You cannot use Server.Transfer to redirect the user to a page running on a different server. Response.Redirect changes the url in the browser. So they can be bookmarked. Whereas Server.Transfer retains the original url in the browser. It just replaces the contents of the previous page with the new one. What method do you use to explicitly kill a users session? Session.Abandon(). What is a webservice? Web Services are applications delivered as a service on the Web. Web services allow for programmatic access of business logic over the Web. Web services typically rely on XMLbased protocols, messages, and interface descriptions for communication and access. Web services are designed to be used by other programs or applications rather than directly by end user. Programs invoking a Web service are called clients. SOAP over HTTP is the most commonly used protocol for invoking Web services.

ASP.NET AJAX Interview Questions Part I


The ASP.NET AJAX Interview Questions contains the most frequently asked questions in ASP.NET AJAX. These lists of questions will gauge your familiarity with the ASP.NET AJAX platform.

What is Ajax?
The term Ajax was coined by Jesse James Garrett and is a short form for "Asynchronous Javascript and XML". Ajax represents a set of commonly used techniques, like HTML/XHTML, CSS, Document Object Model(DOM), XML/XSLT, Javascript and the XMLHttpRequest object, to create RIA's (Rich Internet Applications). Ajax gives the user, the ability to dynamically and asynchronously interact with a web server, without using a plug-in or without compromising on the users ability to interact with the page. This is possible due to an object found in browsers called the XMLHttpRequest object.

What is ASP.NET AJAX?


ASP.NET AJAX is a terminology coined by Microsoft for their implementation of AJAX, which is a set of extensions to ASP.NET. These components allow you to build rich AJAX enabled web applications, which consists of both server side and client side libraries.

Which is the current version of ASP.NET AJAX Control Toolkit?

As of this writing, the toolkit version is Version 1.0.20229 (if you are targeting Framework 2.0, ASP.NET AJAX 1.0 and Visual Studio 2005) and Version 3.0.20229 (if targeting .NET Framework 3.5 and Visual Studio 2008).

What role does the ScriptManager play?


The ScriptManager manages all ASP.NET AJAX resources on a page and renders the links for the ASP.NET AJAX client libraries, which lets you use AJAX functionality like PageMethods, UpdatePanels etc. It creates the PageRequestManager and Application objects, which are prominent in raising events during the client life cycle of an ASP.NET AJAX Web page. It also helps you create proxies to call web services asynchronously.

Can we use multiple ScriptManager on a page?


No. You can use only one ScriptManager on a page.

What is the role of a ScriptManagerProxy?


A page can contain only one ScriptManager control. If you have a Master-Content page scenario in your application and the MasterPage contains a ScriptManager control, then you can use the ScriptManagerProxy control to add scripts to content pages. Also, if you come across a scenario where only a few pages in your application need to register to a script or a web service, then its best to remove them from the ScriptManager control and add them to individual pages, by using the ScriptManagerProxy control. That is because if you added the scripts using the ScriptManager on the Master Page, then these items will be downloaded on each page that derives from the MasterPage, even if they are not needed, which would lead to a waste of resources.

What are the requirements to run ASP.NET AJAX applications on a server?


You would need to install ASP.NET AJAX Extensions on your server. If you are using the ASP.NET AJAX Control toolkit, then you would also need to add the AjaxControlToolkit.dll in the /Bin folder. Note: ASP.NET AJAX 1.0 was available as a separate downloadable add-on for ASP.NET 2.0. With ASP.NET 3.5, the AJAX components have been integrated into ASP.NET.

Explain the UpdatePanel?


The UpdatePanel enables you to add AJAX functionality to existing ASP.NET applications. It can be used to update content in a page by using Partial-page rendering. By using Partialpage rendering, you can refresh only a selected part of the page instead of refreshing the whole page with a postback.

Can I use ASP.NET AJAX with any other technology apart from ASP.NET?
To answer this question, check out this example of using ASP.NET AJAX with PHP, to demonstrate running ASP.NET AJAX outside of ASP.NET. Client-Side ASP.NET AJAX framework can be used with PHP and Coldfusion.

How can you cancel an Asynchronous postback?


Yes you can. Read my article over here.

Difference between Server-Side AJAX framework and Client-side AJAX framework?


ASP.NET AJAX contains both a server-side Ajax framework and a client-side Ajax framework. The server-side framework provides developers with an easy way to implement

Ajax functionality, without having to possess much knowledge of JavaScript. The framework includes server controls and components and the drag and drop functionality. This framework is usually preferred when you need to quickly ajaxify an asp.net application. The disadvantage is that you still need a round trip to the server to perform a client-side action. The Client-Side Framework allows you to build web applications with rich user-interactivity as that of a desktop application. It contains a set of JavaScript libraries, which is independent from ASP.NET. The library is getting rich in functionality with every new build released.

How can you debug ASP.NET AJAX applications?


Explain about two tools useful for debugging: Fiddler for IE and Firebug for Mozilla.

Can we call Server-Side code (C# or VB.NET code) from javascript?


Yes. You can do so using PageMethods in ASP.NET AJAX or using webservices.

Can you nest UpdatePanel within each other?


Yes, you can do that. You would want to nest update panels to basically have more control over the Page Refresh.

How can you to add JavaScript to a page when performing an asynchronous postback?
Use the ScriptManager class. This class contains several methods like the RegisterStartupScript(), RegisterClientScriptBlock(), RegisterClientScriptInclude(), RegisterArrayDeclaration(),RegisterClientScriptResource(), RegisterExpandoAttribute(), RegisterOnSubmitStatement() which helps to add javascript while performing an asynchronous postback.

Explain differences between the page execution lifecycle of an ASP.NET page and an ASP.NET AJAX page?
In an asynchronous model, all the server side events occur, as they do in a synchronous model. The Microsoft AJAX Library also raises client side events. However when the page is rendered, asynchronous postback renders only the contents of the update panel, where as in a synchronous postback, the entire page is recreated and sent back to the browser.

Explain the AJAX Client life-cycle events


Heres a good article about the same.

Is the ASP.NET AJAX Control Toolkit(AjaxControlToolkit.dll) installed in the Global Assembly Cache?
No. You must copy the AjaxControlToolkit.dll assembly to the /Bin folder in your application. Those were some frequently asked questions you should have knowledge about. In one of the coming articles, we will cover some more ASP.NET AJAX FAQs which were not covered in this article. I hope this article was useful and I thank you for viewing it.

Você também pode gostar