Monday 4 January 2010

VB .Net Interview Questions with Answers

  


1) Explain about visual basic?
Ans:Visual basic is associated with the IDE of Microsoft. It is basically useful to implement RAD of GUI. Creation of Active X scripts are very easy and efficient through VB. Windows API can also be used to create application on windows desktop and its applications. This was primarily designed to create applications for windows platform.

2) Explain about .NET?
Ans: .NET is a Microsoft Framework and a software component. .NET has a large library of pre-coded solutions which provided developer significant help in developingapplications with solutions already present. It offers reliable security and cross platform compatibility.

3) Name some of the features present in VB 2005?
Ans:Some of the features present in VB 2005 are as follows: -
• Edit and continue: – It allows developers to modify and execute applications almost simultaneously.
• Namespace: – This provides access to various parts of the .NET framework and it also dynamically            generates classes.
• Data source binding function is very useful for client server development.

4) Explain and brief about rapid application development tool?
Ans:Rapid action development tool describes about the software development process. This tool gives flexibility in iterative development and prototype deployment. It enhances the speed of application development. It is also used for application maintenance.

5) Describe about Visual basic.NET?
Ans:This is used in conjunction with Microsoft .NET platform and is a successor to visual basic sixth version. Visual basic is used in conjunction with.NET Framework. This tool has a serious defect it is not compatible with Microsoft visual basic sixth version. It has a huge library which assists programmers.

6) What are the various open source tool available for VB.NET?
Ans:When compared with the rapid development of open source tools for other languages from Microsoft (C#, etc) we can say that development of tools for VB has been slow. Mono development platform is one which is implementing VB libraries and is working on a compiler.

7) Explain about the performance of Visual basic?
Ans:Visual basic 5 and 6 are efficient in coding the code to native or P-code depending upon the programmer. Portability is a major addition to the performance of VB.NET and the code is also small. Additional layer is provided which interprets the code and this can be avoided by using special algorithms and native code programming.

8) Compare C# and Visual basic.NET?
Ans: .NET Frame work includes two languages which are language to IL compilers and in this C# and VB.NET are provided. The importance and flexibility of these as better programming languages is still questionable.Visual basic has been updated and revised to make it object oriented whereas C# has concepts from many languages such as Delphi, Java, etc and syntax from C and Java.

9) Explain about Visual basic.NET culture?
Ans:VB was always a RAD tool and it was always user friendly for any type of user whether professional or not. It also provided many users with shortcuts and features which made this language popular among many users. It had its share of debugging and maintenance issues of course.

10) Name and explain some of the exclusive features which are present inVB?
Ans:Some of the features which are exclusive to VB are as follows: -
1) Name space can be hidden which can be disabled.
2) Certain project files can be hidden and a user can show them if he intends to do.
3) Lots and lots of shortcuts are present which ease the development of programs.
4) Using the AddressOf myObject function a delegate can be made.

11) Name a feature which is common to all .NET languages?
Ans:There is only one feature which is common to all languages and that is Garbage collection or GC. This feature is automated which relieves developers of much work. This garbage is disposed only when there is need of memory or stress for memory. GC feature halts the application for few seconds before restarting it.

12) Name some of the features of C# which are not present in VB.NET?
Ans:Some of the features which are not present in VB are as follows they are: -
1) It supports unsafe code blocks for improved performance.
2) Partial interfaces and anonymous methods.
3) Multi line comments and static classes. Etc

13) Explain about the keyword Must Inherit?
Ans:This keyword prevents a class from directly instantiated. This keyword forces users to create references to only derived classes. This keyword is present in C# as abstract and it is very useful in creatingapplications.

14) What would you do to remove Microsoft visual basic name space?
Ans: .NET has many new features and application supportive tools. To remove Microsoft visual basic name space all you have to do is to
1) Remove the import manually every time you start the project.
2) Creating a template which does not contain Microsoft Visual Basic namespace.
3) About new features and changes names you can refer to MSDN.

15) Which is the tool which can convert Visual basic old version to .NET compatibility version?
Ans:There is a tool available which can convert old visual basic functions into new .NET code. Artin soft Visual basic upgrade Companion is very useful in converting VB code into .NET code. This tool was developed by Artin. This tool is integrated in Visual studio.NET 2005. It handles programs such as structured handling, error handling, etc.

16) Explain about the feature Anonymous type?
Ans:Anonymous type is a feature of VB.NET and it allows data types to be created from the code which requires it. This feature is present in VB as well as C#. They should be stored in variables declared with the keyword VAR. Dynamic typing is different and shouldn’t be confused with Anonymous type.

17) Explain about the Ruby interface generator?
Ans:Ruby interface generator is primarily responsible for providing the visual part of the Visual basic and this was clubbed with “EB” designed for Omega database system. VBX interface was added to this feature which had the ability to load dynamic link libraries.




Sunday 3 January 2010

JAVA Interview Questions with Answer

JAVA Interview Questions with Answer








1.       What is a virtual function in C++?
Simply put, the virtual keyword enables a function to be ‘virtual’ which then gives possibility for that function to be overridden (redefined) in one or more descendant classes. It is a good feature since the specific function to call is determined at run-time. In other words, a virtual function allows derived classes to replace the implementation provided by the base class.


2.       What is the difference between private, protected, and public?
These keywords are for allowing privilages to components such as functions and variables.
Public: accessible to all classes
Private: accessible only to the class to which they belong
Protected: accessible to the class to which they belong and any subclasses.

3.       What is a cartesian product in PL/SQL?
When a Join condition is not specified by the programmer or is invalid(fails), PL/SQL forms a Cartesian product.
In a Cartesian product, all combinations of rows will be displayed.
For example, All rows in the first table are joined to all rows in the second table. It joins a bunch of rows and it’s result is rarely useful unless you have a need to combine all rows from all tables.

4.       What is mutual exclusion? How can you take care of mutual exclusion using Java threads?
Mutual exclusion is where no two processes can access critical regions of memory at the same time.
Java provides many utilities to deal with mutual exclusion with the use of threaded programming.
For mutual exclusion, you can simply use the synchronized keyword and explicitly or implicitly provide an Object, any Object, to synchronize on.
The runtime system/Java compiler takes care of the gruesome details for you. The synchronized keyword can be applied to a class, to a method, or to a block of code. There are several methods in Java used for communicating mutually exclusive threads such as wait( ), notify( ), or notifyAll( ). For example, the notifyAll( ) method wakes up all threads that are in the wait list of an object.

5.       What are some advantages and disadvantages of Java Sockets?
Some advantages of Java Sockets:
  • Sockets are flexible and sufficient. Efficient socket based programming can be easily implemented for general communications.
  • Sockets cause low network traffic. Unlike HTML forms and CGI scripts that generate and transfer whole web pages for each new request, Java applets can send only necessary updated information.
Some disadvantages of Java Sockets:
  • Security restrictions are sometimes overbearing because a Java applet running in a Web browser is only able to establish connections to the machine where it came from, and to nowhere else on the network
  • Despite all of the useful and helpful Java features, Socket based communications allows only to send packets of raw data between applications. Both the client-side and server-side have to provide mechanisms to make the data useful in any way.
  • Since the data formats and protocols remain application specific, the re-use of socket based implementations is limited.
1.       What is the difference between an Interface and an Abstract class?
An Abstract class declares have at least one instance method that is declared abstract which will be implemented by the subclasses. An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior.

2.       What is the purpose of garbage collection in Java, and when is it used?
The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused. A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used.

3.       Describe synchronization in respect to multithreading.?
With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchonization, it is possible for one thread to modify a shared variable while another thread is in the process of using or updating same shared variable. This usually leads to significant errors.

4.       Explain different way of using thread?
The thread could be implemented by using runnable interface or by inheriting from the Thread class. The former is more advantageous, ’cause when you are going for multiple inheritance..the only interface can help.

5.       What are pass by reference and passby value?
Pass By Reference means the passing the address itself rather than passing the value. Passby Value means passing a copy of the value to be passed.

6.       What is HashMap and Map?
Map is Interface and Hashmap is class that implements that.

7.       Difference between HashMap and HashTable?
The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls. (HashMap allows null values as key and value whereas Hashtable doesnt allow). HashMap does not guarantee that the order of the map will remain constant over time. HashMap is non synchronized and Hashtable is synchronized.

8.       Difference between Vector and ArrayList?
Vector is synchronized whereas arraylist is not.

9.       Difference between Swing and Awt?
AWT are heavy-weight componenets. Swings are light-weight components. Hence swing works faster than AWT.
10.    What is the difference between a constructor and a method?
A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself, has no return type, and is invoked using the new operator. A method is an ordinary member function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator.

11.    What is an Iterators?
Some of the collection classes provide traversal of their contents via a java.util.Iterator interface. This interface allows you to walk a collection of objects, operating on each object in turn. Remember when using Iterators that they contain a snapshot of the collection at the time the Iterator was obtained; generally it is not advisable to modify the collection itself while traversing an Iterator.

12.    State the significance of public, private, protected, default modifiers both singly and in combination and state the effect of package relationships on declared items qualified by these modifiers.?
public : Public class is visible in other packages, field is visible everywhere (class must be public too) private : Private variables or methods may be used only by an instance of the same class that declares the variable or method, A private feature may only be accessed by the class that owns the feature. protected : Is available to all classes in the same package and also available to all subclasses of the class that owns the protected feature.This access is provided even to subclasses that reside in a different package from the class that owns the protected feature. default :What you get by default ie, without any access modifier (ie, public private or protected).It means that it is visible to all within a particular package.

13.    What is an abstract class?
Abstract class must be extended/subclassed (to be useful). It serves as a template. A class that is abstract may not be instantiated (ie, you may not call its constructor), abstract class may contain static data. Any class with an abstract method is automatically abstract itself, and must be declared as such. A class may be declared abstract even if it has no abstract methods. This prevents it from being instantiated.

14.    What is static in java?
Static means one per class, not one for each object no matter how many instance of a class might exist. This means that you can use them without creating an instance of a class.Static methods are implicitly final, because overriding is done based on the type of the object, and static methods are attached to a class, not an object. A static method in a superclass can be shadowed by another static method in a subclass, as long as the original method was not declared final. However, you can’t override a static method with a nonstatic method. In other words, you can’t change a static method into an instance method in a subclass.

1.       What is final?
A final class can’t be extended ie., final class may not be subclassed. A final method can’t be overridden when its class is inherited. You can’t change value of a final variable (is a constant).

2.       Are the imports checked for validity at compile time? e.g. will the code containing an import such as java.lang.ABCD compile?
Yes the imports are checked for the semantic validity at compile time. The code containing above line of import will not compile. It will throw an error saying,can not resolve symbol symbol : class ABCD location: package io import java.io.ABCD;

3.       Does importing a package imports the subpackages as well?
e.g. Does importing com.MyTest.* also import com.MyTest.UnitTests.*?
No you will have to import the subpackages explicitly. Importing com.MyTest.* will import classes in the package MyTest only. It will not import any class in any of it’s subpackage.

4.       What is the difference between declaring a variable and defining a variable?
In declaration we just mention the type of the variable and it’s name. We do not initialize it. But defining means declaration + initialization. e.g String s; is just a declaration while String s = new String (“abcd”); Or String s = “abcd”; are both definitions.

5.       What is the default value of an object reference declared as an instance variable?
null unless we define it explicitly.

6.       Can a level class be private or protected?
No. A level class can not be private or protected. It can have either “public” or no modifier. If it does not have a modifier it is supposed to have a default access.If a level class is declared as private the compiler will complain that the “modifier private is not allowed here”. This means that a level class can not be private. Same is the case with protected.

7.       What type of parameter passing does Java support?
In Java the arguments are always passed by value .

8.       Primitive data types are passed by reference or pass by value?
Primitive data types are passed by value.

9.       Objects are passed by value or by reference?
Java only supports pass by value. With objects, the object reference itself is passed by value and so both the original reference and parameter copy both refer to the same object .

10.    What is serialization?
Serialization is a mechanism by which you can save the state of an object by converting it to a byte stream.

11.    How do I serialize an object to a file?
The class whose instances are to be serialized should implement an interface Serializable. Then you pass the instance to the ObjectOutputStream which is connected to a fileoutputstream. This will save the object to a file.

12.    Which methods of Serializable interface should I implement?
The serializable interface is an empty interface, it does not contain any methods. So we do not implement any methods.

13.    How can I customize the seralization process?
i.e. how can one have a control over the serialization process?
Yes it is possible to have control over serialization process. The class should implement Externalizable interface. This interface contains two methods namely readExternal and writeExternal. You should implement these methods and write the logic for customizing the serialization process.

14.    What is an abstract class?
Abstract class must be extended/subclassed (to be useful). It serves as a template. A class that is abstract may not be instantiated (ie, you may not call its constructor), abstract class may contain static data. Any class with an abstract method is automatically abstract itself, and must be declared as such. A class may be declared abstract even if it has no abstract methods. This prevents it from being instantiated.

1.       What is the common usage of serialization?
Whenever an object is to be sent over the network, objects need to be serialized. Moreover if the state of an object is to be saved, objects need to be serilazed.

2.       What is Externalizable interface?
Externalizable is an interface which contains two methods readExternal and writeExternal. These methods give you a control over the serialization mechanism. Thus if your class implements this interface, you can customize the serialization process by implementing these methods.

3.       What happens to the object references included in the object?
The serialization mechanism generates an object graph for serialization. Thus it determines whether the included object references are serializable or not. This is a recursive process. Thus when an object is serialized, all the included objects are also serialized alongwith the original obect.

4.       What one should take care of while serializing the object?
One should make sure that all the included objects are also serializable. If any of the objects is not serializable then it throws a NotSerializableException.

5.       What if the main method is declared as private?
The program compiles properly but at runtime it will give “Main method not public.” message.

6.       What if the static modifier is removed from the signature of the main method?
Program compiles. But at runtime throws an error “NoSuchMethodError”.

7.       What if I write static public void instead of public static void?
Program compiles and runs properly.

8.       What if I do not provide the String array as the argument to the method?
Program compiles but throws a runtime error “NoSuchMethodError”.

9.       What is the first argument of the String array in main method?
The String array is empty. It does not have any element. This is unlike C/C++ where the first element by default is the program name.

10.    If I do not provide any arguments on the command line, then the String array of Main method will be empty of null?
It is empty. But not null.

11.    How can one prove that the array is not null but empty?
Print args.length. It will print 0. That means it is empty. But if it would have been null then it would have thrown a NullPointerException on attempting to print args.length.

12.    What environment variables do I need to set on my machine in order to be able to run Java programs?
CLASSPATH and PATH are the two variables.

13.    Can an application have multiple classes having main method?
Yes it is possible. While starting the application we mention the class name to be run. The JVM will look for the Main method only in the class whose name you have mentioned. Hence there is not conflict amongst the multiple classes having main method.

14.    Can I have multiple main methods in the same class?
No the program fails to compile. The compiler says that the main method is already defined in the class.

15.    Do I need to import java.lang package any time? Why ?
No. It is by default loaded internally by the JVM.

16.    Can I import same package/class twice? Will the JVM load the package twice at runtime?
One can import the same package or same class multiple times. Neither compiler nor JVM complains abt it. And the JVM will internally load the class only once no matter how many times you import the same class.

17.    What are Checked and UnChecked Exception?
A checked exception is some subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses. Making an exception checked forces client programmers to deal with the possibility that the exception will be thrown. eg, IOException thrown by java.io.FileInputStream’s read() method
checked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also are unchecked. With an unchecked exception, however, the compiler doesn’t force client programmers either to catch the exception or declare it in a throws clause. In fact, client programmers may not even know that the exception could be thrown. eg, StringIndexOutOfBoundsException thrown by String’s charAt() method Checked exceptions must be caught at compile time. Runtime exceptions do not need to be. Errors often cannot be.

18.    What is Overriding?
When a class defines a method using the same name, return type, and arguments as a method in its superclass, the method in the class overrides the method in the superclass. When the method is invoked for an object of the class, it is the new definition of the method that is called, and not the method definition from superclass. Methods may be overridden to be more public, not more private.

19.    What are different types of inner classes?
They are Nested -level classes, Member classes, Local classes, Anonymous classes
Nested -level classes- If you declare a class within a class and specify the static modifier, the compiler treats the class just like any other -level class. Any class outside the declaring class accesses the nested class with the declaring class name acting similarly to a package. eg, outer.inner. -level inner classes implicitly have access only to static variables.There can also be inner interfaces. All of these are of the nested -level variety.
Member classes – Member inner classes are just like other member methods and member variables and access to the member class is restricted, just like methods and variables. This means a public member class acts similarly to a nested -level class. The primary difference between member classes and nested -level classes is that member classes have access to the specific instance of the enclosing class.
Local classes – Local classes are like local variables, specific to a block of code. Their visibility is only within the block of their declaration. In order for the class to be useful beyond the declaration block, it would need to implement a more publicly available interface.Because local classes are not members, the modifiers public, protected, private, and static are not usable.
Anonymous classes – Anonymous inner classes extend local inner classes one level further. As anonymous classes have no name, you cannot provide a constructor.

1.       Are the imports checked for validity at compile time? e.g. will the code containing an import such as java.lang.ABCD compile? Yes the imports are checked for the semantic validity at compile time. The code containing above line of import will not compile. It will throw an error saying,can not resolve symbol symbol : class ABCD location: package io import java.io.ABCD;

2.       Does importing a package imports the subpackages as well? e.g. Does importing com.MyTest.* also import com.MyTest.UnitTests.*? No you will have to import the subpackages explicitly. Importing com.MyTest.* will import classes in the package MyTest only. It will not import any class in any of it’s subpackage.

3.       What is the difference between declaring a variable and defining a variable? In declaration we just mention the type of the variable and it’s name. We do not initialize it. But defining means declaration + initialization. e.g String s; is just a declaration while String s = new String (“abcd”); Or String s = “abcd”; are both definitions.

4.       What is the default value of an object reference declared as an instance variable? null unless we define it explicitly.

5.       Can a level class be private or protected? No. A level class can not be private or protected. It can have either “public” or no modifier. If it does not have a modifier it is supposed to have a default access. If a level class is declared as private the compiler will complain that the “modifier private is not allowed here”. This means that a level class can not be private. Same is the case with protected.

6.       What type of parameter passing does Java support? In Java the arguments are always passed by value .

7.       Primitive data types are passed by reference or pass by value? Primitive data types are passed by value.

8.       Objects are passed by value or by reference? Java only supports pass by value. With objects, the object reference itself is passed by value and so both the original reference and parameter copy both refer to the same object .

9.       What is serialization? Serialization is a mechanism by which you can save the state of an object by converting it to a byte stream.

10.    How do I serialize an object to a file? The class whose instances are to be serialized should implement an interface Serializable. Then you pass the instance to the ObjectOutputStream which is connected to a fileoutputstream. This will save the object to a file.

11.    Which methods of Serializable interface should I implement? The serializable interface is an empty interface, it does not contain any methods. So we do not implement any methods.

12.    How can I customize the seralization process? i.e. how can one have a control over the serialization process? Yes it is possible to have control over serialization process. The class should implement Externalizable interface. This interface contains two methods namely readExternal and writeExternal. You should implement these methods and write the logic for customizing the serialization process.

13.    What is the common usage of serialization? Whenever an object is to be sent over the network, objects need to be serialized. Moreover if the state of an object is to be saved, objects need to be serilazed.

14.    What is Externalizable interface? Externalizable is an interface which contains two methods readExternal and writeExternal. These methods give you a control over the serialization mechanism. Thus if your class implements this interface, you can customize the serialization process by implementing these methods.

15.    What happens to the object references included in the object? The serialization mechanism generates an object graph for serialization. Thus it determines whether the included object references are serializable or not. This is a recursive process. Thus when an object is serialized, all the included objects are also serialized alongwith the original obect.

16.    What one should take care of while serializing the object? One should make sure that all the included objects are also serializable. If any of the objects is not serializable then it throws a NotSerializableException.

17.    What happens to the static fields of a class during serialization? Are these fields serialized as a part of each serialized object? Yes the static fields do get serialized. If the static field is an object then it must have implemented Serializable interface. The static fields are serialized as a part of every object. But the commonness of the static fields across all the instances is maintained even after serialization.

18.    How are Observer and Observable used? Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects. [Received from Venkateswara Manam]

19.    What is synchronization and why is it important? With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is possible for one thread to modify a shared object while another thread is in the process of using or updating that object’s value. This often leads to significant errors.

20.    How does Java handle integer overflows and underflows? It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.

21.    Does garbage collection guarantee that a program will not run out of memory? Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection .

22.    What is the difference between preemptive scheduling and time slicing? Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing, a task executes for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors.

23.    When a thread is created and started, what is its initial state? A thread is in the ready state after it has been created and started.

24.    What is the purpose of finalization? The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected.

25.    What is the Locale class? The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region.

26.    What is the difference between a while statement and a do statement? A while statement checks at the beginning of a loop to see whether the next loop iteration should occur. A do statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the body of a loop at least once.

27.    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.

28.    How are this() and super() used with constructors? this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.

1.       Explain the life cycle methods of a Servlet.
The javax.servlet.Servlet interface defines the three methods known as life-cycle method. public void init(ServletConfig config) throws ServletException public void service( ServletRequest req, ServletResponse res) throws ServletException, IOException public void destroy() First the servlet is constructed, then initialized wih the init() method. Any request from client are handled initially by the service() method before delegating to the doXxx() methods in the case of HttpServlet. The servlet is removed from service, destroyed with the destroy() methid, then garbaged collected and finalized.

2.       What is the difference between the getRequestDispatcher(String path) method of javax.servlet.ServletRequest interface and javax.servlet.ServletContext interface?
The getRequestDispatcher(String path) method of javax.servlet.ServletRequest interface accepts parameter the path to the resource to be included or forwarded to, which can be relative to the request of the calling servlet. If the path begins with a “/” it is interpreted as relative to the current context root.
The getRequestDispatcher(String path) method of javax.servlet.ServletContext interface cannot accepts relative paths. All path must sart with a “/” and are interpreted as relative to curent context root.

3.       Explain the directory structure of a web application.
The directory structure of a web application consists of two parts. A private directory called WEB-INF A public resource directory which contains public resource folder. WEB-INF folder consists of 1. web.xml
2. classes directory
3. lib directory

4.       What are the common mechanisms used for session tracking?
Cookies SSL sessions URL- rewriting

5.       Explain ServletContext.
ServletContext interface is a window for a servlet to view it’s environment. A servlet can use this interface to get information such as initialization parameters for the web applicationor servlet container’s version. Every web application has one and only one ServletContext and is accessible to all active resource of that application.
6.       What is preinitialization of a servlet?
A container doesnot initialize the servlets ass soon as it starts up, it initializes a servlet when it receives a request for that servlet first time. This is called lazy loading. The servlet specification defines the element, which can be specified in the deployment descriptor to make the servlet container load and initialize the servlet as soon as it starts up. The process of loading a servlet before any request comes in is called preloading or preinitializing a servlet.

7.       What is the difference between Difference between doGet() and doPost()?
A doGet() method is limited with 2k of data to be sent, and doPost() method doesn’t have this limitation. A request string for doGet() looks like the following: http://www.allapplabs.com/svt1?p1=v1&p2=v2&…&pN=vN

doPost() method call doesn’t need a long text tail after a servlet name in a request. All parameters are stored in a request itself, not in a request string, and it’s impossible to guess the data transmitted to a servlet only looking at a request string.

8.       What is the difference between HttpServlet and GenericServlet?
A GenericServlet has a service() method aimed to handle requests.
HttpServlet extends GenericServlet and adds support for doGet(), doPost(), doHead() methods (HTTP 1.0) plus doPut(), doOptions(), doDelete(), doTrace() methods (HTTP 1.1). Both these classes are abstract.

1.       What is a output comment?
A comment that is sent to the client in the viewable page source.The JSP engine handles an output comment as uninterpreted HTML text, returning the comment in the HTML output sent to the client. You can see the comment by viewing the page source from your Web browser. JSP Syntax Example 1 Displays in the page source:

2.       What is a Hidden Comment?
A comments that documents the JSP page but is not sent to the client. The JSP engine ignores a hidden comment, and does not process any code within hidden comment tags. A hidden comment is not sent to the client, either in the displayed JSP page or the HTML page source. The hidden comment is useful when you want to hide or “comment out” part of your JSP page. You can use any characters in the body of the comment except the closing –%> combination. If you need to use –%> in your comment, you can escape it by typing –%\>. JSP Syntax Examples

3.       What is a _Expression?
An _expression tag contains a scripting language _expression that is evaluated, converted to a String, and inserted where the _expression appears in the JSP file. Because the value of an _expression is converted to a String, you can use an _expression within text in a JSP file. Like You cannot use a semicolon to end an _expression

4.       What is a Declaration?
A declaration declares one or more variables or methods for use later in the JSP source file. A declaration must contain at least one complete declarative statement. You can declare any number of variables or methods within one declaration tag, as long as they are separated by semicolons. The declaration must be valid in the scripting language used in the JSP file.

5.       What is a Scriptlet?
A scriptlet can contain any number of language statements, variable or method declarations, or expressions that are valid in the page scripting language.Within scriptlet tags, you can
1.Declare variables or methods to use later in the file (see also Declaration).
2.Write expressions valid in the page scripting language (see also _Expression).
3.Use any of the JSP implicit objects or any object declared with a tag.
You must write plain text, HTML-encoded text, or other JSP tags outside the scriptlet. Scriptlets are executed at request time, when the JSP engine processes the client request. If the scriptlet produces output, the output is stored in the out object, from which you can display it.

6.       What are implicit objects? List them?
Certain objects that are available for the use in JSP documents without being declared first. These objects are parsed by the JSP engine and inserted into the generated servlet. The implicit objects re listed below request response pageContext session application out config page exception

7.       Difference between forward and sendRedirect?
When you invoke a forward request, the request is sent to another resource on the server, without the client being informed that a different resource is going to process the request. This process occurs completly with in the web container. When a sendRedirtect method is invoked, it causes the web container to return to the browser indicating that a new URL should be requested. Because the browser issues a completly new request any object that are stored as request attributes before the redirect occurs will be lost. This extra round trip a redirect is slower than forward.

8.       What are the different scope valiues for the ?
The different scope values for are
1. page
2. request
3.session
4.application

9.       Explain the life-cycle mehtods in JSP?
THe generated servlet class for a JSP page implements the HttpJspPage interface of the javax.servlet.jsp package. Hte HttpJspPage interface extends the JspPage interface which inturn extends the Servlet interface of the javax.servlet package. the generated servlet class thus implements all the methods of the these three interfaces.
The JspPage interface declares only two mehtods – jspInit() and jspDestroy() that must be implemented by all JSP pages regardless of the client-server protocol.
However the JSP specification has provided the HttpJspPage interfaec specifically for the JSp pages serving HTTP requests.
This interface declares one method _jspService(). The jspInit()- The container calls the jspInit() to initialize te servlet instance.It is called before any other method, and is called only once for a servlet instance.
The _jspservice()- The container calls the _jspservice() for each request, passing it the request and the response objects.
The jspDestroy()- The container calls this when it decides take the instance out of service. It is the last method called n the servlet instance.






JAVA Interview Questions with Answer

Saturday 2 January 2010

C# Interview Questions with Answer




1. What’s the implicit name of the parameter that gets passed into the class’ set method? 
Value, and its datatype depends on whatever variable we’re changing.

2. How do you inherit from a class in C#? 
Place a colon and then the name of the base class. Notice that it’s double colon in C++.

3. Does C# support multiple inheritance?
 No, use interfaces instead.

4. When you inherit a protected class-level variable, who is it available to? 
Classes in the same namespace.

5. Are private class-level variables inherited? 
Yes, but they are not accessible, so looking at it you can honestly say that they are not inherited. But they are.

6. Describe the accessibility modifier protected internal. 
It’s available to derived classes and classes within the same Assembly (and naturally from the base class it’s declared in).

7. C# provides a default constructor for me. I write a constructor that takes a string as a parameter, but want to keep the no parameter one. How many constructors should I write? 
Two. Once you write at least one constructor, C# cancels the freebie constructor, and now you have to write one yourself, even if there’s no implementation in it.

8. What’s the top .NET class that everything is derived from?  
System.Object.

9. How’s method overriding different from overloading? 
 When overriding, you change the method behavior for a derived class. Overloading simply involves having a method with the same name within the class.

10. What does the keyword virtual mean in the method definition? 
The method can be over-ridden.

11. Can you declare the override method static while the original method is non-static? No, you can’t, the signature of the virtual method must remain the same, only the keyword virtual is changed to keyword override.

12. Can you override private virtual methods? 
No, moreover, you cannot access private methods in inherited classes, have to be protected in the base class to allow any sort of access.

13. Can you prevent your class from being inherited and becoming a base class for some other classes? 
 Yes, that’s what keyword sealed in the class definition is for. The developer trying to derive from your class will get a message: cannot inherit from Sealed class WhateverBaseClassName. It’s the same concept as final class in Java.

14. Can you allow class to be inherited, but prevent the method from being over-ridden?  
Yes, just leave the class public and make the method sealed.

15. What’s an abstract class? 
 A class that cannot be instantiated. A concept in C++ known as pure virtual method. A class that must be inherited and have the methods over-ridden. Essentially, it’s a blueprint for a class without any implementation.

16. When do you absolutely have to declare a class as abstract (as opposed to free-willed educated choice or decision based on UML diagram)? 
When at least one of the methods in the class is abstract. When the class itself is inherited from an abstract class, but not all base abstract methods have been over-ridden.

17. What’s an interface class?
  It’s an abstract class with public abstract methods all of which must be implemented in the inherited classes.

18. Why can’t you specify the accessibility modifier for methods inside the interface? They all must be public. Therefore, to prevent you from getting the false impression that you have any freedom of choice, you are not allowed to specify any accessibility, it’s public by default.

19. Can you inherit multiple interfaces? 
 Yes, why not.

20. And if they have conflicting method names? 
 It’s up to you to implement the method inside your own class, so implementation is left entirely up to you. This might cause a problem on a higher-level scale if similarly named methods from different interfaces expect different data, but as far as compiler cares you’re okay.

21. What’s the difference between an interface and abstract class? 
 In the interface all methods must be abstract; in the abstract class some methods can be concrete. In the interface no accessibility modifiers are allowed, which is ok in abstract classes.

22. How can you overload a method? 
Different parameter data types, different number of parameters, different order of parameters.

23. If a base class has a bunch of overloaded constructors, and an inherited class has another bunch of overloaded constructors, can you enforce a call from an inherited constructor to an arbitrary base constructor? 
Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class.

24. What’s the difference between System.String and System.StringBuilder classes? System.String is immutable; System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.

25. What’s the advantage of using System.Text.StringBuilder over System.String? StringBuilder is more efficient in the cases, where a lot of manipulation is done to the text. Strings are immutable, so each time it’s being operated on, a new instance is created.

26. Can you store multiple data types in System.Array? 
 No.

27. What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?
The first one performs a deep copy of the array, the second one is shallow.

28. How can you sort the elements of the array in descending order?  
By calling Sort() and then Reverse() methods.

29. What’s the .NET datatype that allows the retrieval of data by a unique key? HashTable.

30. What’s class SortedList underneath? 
A sorted HashTable.

31. Will finally block get executed if the exception had not occurred? 
 Yes.

32. What’s the C# equivalent of C++ catch (…), which was a catch-all statement for any possible exception? 
A catch block that catches the exception of type System.Exception. You can also omit the parameter data type in this case and just write catch {}.

33. Can multiple catch blocks be executed? 
No, once the proper catch code fires off, the control is transferred to the finally block (if there are any), and then whatever follows the finally block.

34. Why is it a bad idea to throw your own exceptions?
 Well, if at that point you know that an error has occurred, then why not write the proper code to handle that error instead of passing a new Exception object to the catch block? Throwing your own exceptions signifies some design flaws in the project.

35. What’s a delegate? 
A delegate object encapsulates a reference to a method. In C++ they were referred to as function pointers.

36. What’s a multicast delegate? 
It’s a delegate that points to and eventually fires off several methods.

37. How’s the DLL Hell problem solved in .NET? 
Assembly versioning allows the application to specify not only the library it needs to run (which was available under Win32), but also the version of the assembly.

38. What are the ways to deploy an assembly?
 An MSI installer, a CAB archive, and XCOPY command.

39. What’s a satellite assembly? 
 When you write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies.

40. What namespaces are necessary to create a localized application? System.Globalization, System.Resources.

41. What’s the difference between // comments, /* */ comments and /// comments? Single-line, multi-line and XML documentation comments.

42. How do you generate documentation from the C# file commented properly with a command-line compiler?
Compile it with a /doc switch.

43. What’s the difference between and XML documentation tag?
 Single line code example and multiple-line code example.

44. Is XML case-sensitive? 
Yes, so and are different elements.

45. What debugging tools come with the .NET SDK? 
CorDBG – command-line debugger, and DbgCLR – graphic debugger. Visual Studio .NET uses the DbgCLR. To use CorDbg, you must compile the original C# file using the /debug switch.

46. What does the This window show in the debugger? 
It points to the object that’s pointed to by this reference. Object’s instance data is shown.

47. What does assert() do? 
In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true.

48. What’s the difference between the Debug class and Trace class? 
Documentation looks the same. Use Debug class for debug builds, use Trace class for both debug and release builds.

49. Why are there five tracing levels in System.Diagnostics.TraceSwitcher? 
The tracing dumps can be quite verbose and for some applications that are constantly running you run the risk of overloading the machine and the hard drive there. Five levels range from None to Verbose, allowing to fine-tune the tracing activities.

50. Where is the output of TextWriterTraceListener redirected? 
To the Console or a text file depending on the parameter passed to the constructor.

51. How do you debug an ASP.NET Web application?
Attach the aspnet_wp.exe process to the DbgClr debugger.

52. What are three test cases you should go through in unit testing? 
Positive test cases (correct data, correct output), negative test cases (broken or missing data, proper handling), exception test cases (exceptions are thrown and caught properly).

53. Can you change the value of a variable while debugging a C# application?
Yes, if you are debugging via Visual Studio.NET, just go to Immediate window.

54. Explain the three services model (three-tier application). 
Presentation (UI), business (logic and underlying code) and data (from storage or other sources).

55. What are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET? 
SQLServer.NET data provider is high-speed and robust, but requires SQL Server license purchased from Microsoft. OLE-DB.NET is universal for accessing other sources, like Oracle, DB2, Microsoft Access and Informix, but it’s a .NET layer on top of OLE layer, so not the fastest thing in the world. ODBC.NET is a deprecated layer provided for backward compatibility to ODBC engines.

56. What’s the role of the DataReader class in ADO.NET connections? 
It returns a read-only dataset from the data source when the command is executed.

57. What is the wildcard character in SQL? 
Let’s say you want to query database with LIKE for all employees whose name starts with La. The wildcard character is %, the proper query with LIKE would involve ‘La%’.

58. Explain ACID rule of thumb for transactions. 
Transaction must be Atomic (it is one unit of work and does not dependent on previous and following transactions), Consistent (data is either committed or roll back, no “in-between” case where something has been updated and something hasn’t), Isolated (no transaction sees the intermediate results of the current transaction), Durable (the values persist if the data had been committed even if the system crashes right after).

59. What connections does Microsoft SQL Server support? 
Windows Authentication (via Active Directory) and SQL Server authentication (via Microsoft SQL Server username and passwords).

60. Which one is trusted and which one is untrusted? 
Windows Authentication is trusted because the username and password are checked with the Active Directory, the SQL Server authentication is untrusted, since SQL Server is the only verifier participating in the transaction.

61. Why would you use untrusted verificaion? 
Web Services might use it, as well as non-Windows applications.

62. What does the parameter Initial Catalog define inside Connection String? 
The database name to connect to.

63. What’s the data provider name to connect to Access database? 
Microsoft.Access.

64. What does Dispose method do with the connection object? 
Deletes it from the memory.

65. What is a pre-requisite for connection pooling? 
Multiple processes must agree that they will share the same connection, where every parameter is the same, including the security settings.