DISHA NIRDESHAN

Enlightens your career

Thursday, November 3, 2011

Dot Net Frame work video Tutorial

Adobe Dream Weaver Video Tutorial

ASP. Net Obective type Questions

1. Choose the form in which Postback occurs.

           

a          HTMLForms

b          Webforms

c          Winforms

           

2          Web.config file is used...

           

a          Configures the time that the server-side codebehind module is called

b          To store the global information and variable definitions for the application

c          To configure the web server

d          To configure the web browser

           

3          Which of the following object is not an ASP component?

           

a          LinkCounter

b          Counter

c          AdRotator

d          File Access

           

           

4          The first event triggers in an aspx page is.

           

a          Page_Init()

b          Page_Load()

c          Page_click()

 

 

           

5          Difference between Response.Write() andResponse.Output.Write().

           

a          Response.Output.Write() allows you to buffer output

b          Response.Output.Write() allows you to write formatted output

c          Response.Output.Write() allows you to flush output

d          Response.Output.Write() allows you to stream output

           

6          Which of the following method must be overridden in a custom control?

           

a          The Paint() method

b          The Control_Build() method

c          The default constructor

d          The Render() method

           

7          How do we create a FileSystemObject?

           

a          Server.CreateObject("Scripting.FileSystemObject")

b          Create("FileSystemObject")

c          Create Object:"Scripting.FileSystemObject"

d          Server.CreateObject("FileSystemObject")

           

8          Which of the following tool is used to manage the GAC?

           

a          RegSvr.exe

b          GacUtil.exe

c          GacSvr32.exe

d          GacMgr.exe

           

 

9          . What class does the ASP.NET Web Form class inherit from by default?

           

a          System.Web.UI.Page

b          System.Web.UI.Form

c          System.Web.GUI.Page

d          System.Web.Form

           

10        We can manage states in asp.net application using

           

a          Session Objects

b          Application Objects

c          Viewstate

d          All of the above

           

11        Attribute must be set on a validator control for the validation to work.

           

a          ControlToValidate

b          ControlToBind

c          ValidateControl

d          Validate

           

12        Caching type supported by ASP.Net

           

a          Output Caching

b          DataCaching

c          a and b

d          none of the above

           

 

13        What is used to validate complex string patterns like an e-mail address?

           

a          Extended expressions

b          Basic expressions

c          Regular expressions

d          Irregular expressions

           

14        File extension used for ASP.NET files.

           

a          .Web

b          .ASP

c          .ASPX

d          None of the above

           

15        An alternative way of displaying text on web page using

           

a          asp:label

b          asp:listitem

c          asp:button

           

16        Why is Global.asax is used?

           

a          Declare Global variables

b          Implement application and session level events

c          No use

           

17        Which of the following is not a member of ADODBCommand object?

           

a          ExecuteScalar

b          ExecuteStream

c          Open

e          ExecuteReader

           

18        Which DLL translate XML to SQL in IIS?

           

a          SQLISAPI.dll

b          SQLXML.dll

c          LISXML.dll

d          SQLIIS.dll

           

19        Default Session data is stored in ASP.Net.

           

a          StateServer

b          Session Object

c          InProcess

d          all of the above

           

20        Default scripting language in ASP.

           

a          EcmaScript

b          VBScript

c          PERL

d          JavaScript

           

21        How do you get information from a form that is submitted using the "post" method?

           

a          Request.QueryString

b          Request.Form

c          Response.write

d          Response.writeln

           

22        . Which object can help you maintain data across users?

           

a          Application object

b          Session object

c          Response object

d          Server object

           

           

23        Which of the following ASP.NET object encapsulates the state of the client?

           

a          Session object

b          Application object

c          Response object

d          Server object

           

24        Which of the following object is used along with application object in order to ensure that only one process accesses a variable at a time?

           

a          Synchronize

b          Synchronize()

c          ThreadLock

d          Lock()

           

           

 

 

 

25        Which of the following control is used to validate that two fields are equal?

           

a          RegularExpressionValidator

b          CompareValidator

c          equals() method

d          RequiredFieldValidator

           

26        Mode of storing ASP.NET session

           

a          InProc

b          StateServer

c          SQL Server

d          All of the above

           

27        Which of the following is not the way to maintain state?

           

a          View state

b          Cookies

c          Hidden fields

d          Request object

           

28        You can have only one Global.asax file per project.

           

a          Yes

b          No

           

29        ______________ element in the web.config file to run code using the permissions of a specific user

           

a          < credential> element

b          < authentication> element

c          < authorization> element

d          < identity> element

           

           

30        __________________ is a special subfolder within the windows folder that stores the shared .NET component.

           

a          /bin

b          GAC

c          Root

           

31        Which of the following is the performance attributes of processModel?

           

a          requestQueue limit

b          maxWorkerThreads

c          maxIdThreads

d          All

           

32        Which of the following is faster and consume lesser memory?

           

a          SQLDataReader

b          Data Set

           

33        Which of the following is the way to monitor the web application?

           

a          MMC Event viewers

b          Performance logs

c          Alerts Snap-ins

d          ALL

           

34        The ________________ property affects how the .Net Framework handles dates, currencies, sorting and formatting issues.

           

a          CurrentUICulture

b          CurrentCulture

           

35        Where do we include the user lists for windows authentication?

           

a          < Credential>

b          < authorization>

c          < identity>

d          < authentiation>

           

36        Where do we include the user lists for Form authentication?

           

a          < credential>

b          < authorization>

c          < Identity>

d          < authentication>

           

37        . Which of the following authentication is best suited for a corporate network?

           

a          Windows

b          Form

c          User

d          All

           

38        What attributes do you use to hide a public .Net class from COM?

           

a          DLLImport Attributes

b          ComVisible attributes

c          COM Interop

d          All

           

39        By default, code written with the Debug class is stripped out of release builds.

           

a          Yes

b          No

           

40        ___________________ tests make sure that new code does not break existing code.

           

a          Regression tests

b          Integration tests

c          Unit tests

d          Load test

           

41        Which of the following is used to cache multiple responses for a single web form based on HTTP POST parameter or query string?

           

a          VaryByParams

b          VaryByHeaders

c          SetCacheability

d          SetVaryByCustom



Tuesday, June 28, 2011

Questions on Inheritance & polymorphism

QUESTIONS ON INHERITANCE :

 

Why is multiple inheritance not allowed in java?

The reasons for omitting multiple inheritance from the Java language mostly stem from the "simple, object oriented, and familiar" goal. As a simple language, Java's creators wanted a language that most developers could grasp without extensive training. To that end, they worked to make the language as similar to C++ as possible (familiar) without carrying over C++'s unnecessary complexity (simple).

In the designers' opinion, multiple inheritance causes more problems and confusion than it solves. So they cut multiple inheritance from the language (just as they cut operator overloading). The designers' extensive C++ experience taught them that multiple inheritance just wasn't worth the headache.

Instead, Java's designers chose to allow multiple interface inheritance through the use of interfaces, an idea borrowed from Objective C's protocols. Multiple interface inheritance allows an object to inherit many different method signatures with the caveat that the inheriting object must implement those inherited methods.

 

Q: How can you do multiple inheritance in Java      

A: To achieve multiple Inheritances in java we must use Interface. We can create a class by extending one class or we can implement any number of interfaces for it. But the restriction is we have to implement / describe every method existing in the interfaces.

Q: Why java does not support inheritance of multiple superclasses?what is achieved by inheritance?

A: Handling the two classes always be a problem.Why we need to extends two classes at a time.If that required use two extends statements.Like this...

Class A extends B

{

......

}

class c extends A

{

}

problem cleared...

 

Q: How and when to prevent inheritance?

A:

By a class declared as final then that class cannot be inherited when preventing the inheritance: suppose if your class not required to be reused then only you can declare final.

 

Q: What are the types of Inheritance?

A:

Types of Inheritance supported by Java

Ø Single Inheritance &

Ø Multi level Inheritance.

    

Q: What are some alternatives to inheritance?

A:

Delegation is an alternative to inheritance. Delegation means that you include an instance of another class as an instance variable, and forward messages to the instance. It is often safer than inheritance because it forces you to think about each message you forward, because the instance is of a known class, rather than a new class, and because it doesn't force you to accept all the methods of the super class: you can provide only the methods that really make sense. On the other hand, it makes you write more code, and it is harder to re-use (because it is not a subclass).

 



 Questions on Polymorphism:


Q:What is polymorphism?

A:

Polymorphism means any forms. The word poly means more than one i.e many morphism means in different form, thus polymorphism comes to a conclusion with a meaning called in many forms.

Polymorphism can be implemented in the Java language in the form of multiple methods having the same name. Java code uses a late-binding technique to support polymorphism; the method to be invoked is decided at runtime.

 

Q:What is Method Overloading ?

A:

In a class, the concept of method overloading does not allow the external user to be aware about the internal processing of the system

ü  It just allows to user to use the different implementations of same name collected together and react appropriately to the supplied parameters to get the desired output.

ü  Method Overloading allows the user to achieve the compile time polymorphism.

ü  Overloaded methods are always the part of the same class. These  methods have the same name, but they may take different input parameters.

ü  The arguments passed to a overloaded method may differ in type or in number, or both. 

ü   Overloaded methods may have the same or different return types.

The important points to note:

ü  A difference in return type only is not sufficient to constitute an overload and is illegal.

ü  You should restrict your use of overloaded method names to situations where the methods really are performing the same basic function with different data.

ü  The language treats methods with overloaded names as totally different methods and as such they can have different return types. However, since overloaded methods perform the same job with different data sets, they should produce same return type normally. There is one particular condition, however, under which it is sensible to define different return types. This is the situation where the return type is derived from the argument type and is exactly parallel with the arithmetic operators.

ü  Overloaded methods may call one another simply by providing a normal method call with an appropriately formed argument list. 

 

Q:What is Method Overriding?

A:

 In a class hierarchy, when a method in a subclass has the same name and type signature as a method in its superclass, then the method in the subclass is said to override the method in the superclass. When an overridden method is called from within a subclass, it will always refer to the version of that method defined by the subclass. The version in the superclass will be hidden. If you wish to access the superclass' version of an overridden method, you can do so by using 'super'. 

 

In order for any particular method to override another correctly:

 

  • The return type, method name, type and order of arguments must be identical to those of a method in a parent class.
  • The accessibility must not be more restrictive than original method.

 The method must not throw checked exceptions of classes that are

 

Q:What is runtime polymorphism in Java?

A: The method overriding is an example of runtime polymorphism. You can have a method in subclass overrides the method in its super classes with the same name and signature. Java virtual machine determines the proper method to call at the runtime, not at the compile time.

Let's take a look at the following example:

class Bird {
  void whoAmI() {
    System.out.println("I am a generic Bird.");
  }
}
class Pigeon extends Bird {
  void whoAmI() {
    System.out.println("I am a pigeon.");
  }
}
class Parrot extends Bird {
  void whoAmI() {
    System.out.println("I am a Parrot.");
  }
}
class Crow extends Bird {
  void whoAmI() {
    System.out.println("I am a Crow.");
  }
}

class RuntimePolymorphismDemo {

  public static void main(String[] args) {
    Bird ref1 = new Bird();
    Bird ref2 = new Pigeon();
    Bird ref3 = new Parrot();
    Bird ref4 = new Crow();
    ref1.whoAmI();
    ref2.whoAmI();
    ref3.whoAmI();
    ref4.whoAmI();
  }
}

The output is

I am a generic Bird.
I am a Pigeon..
I am a Parrot.
I am a Crow.

Q: What is compile-time Polymorphism ?

A:

Overloading is called compile-time polymorphism because the compiler must decide how to select which method to run, based on the datatypes of the arguments.  For example, if the compiler were to compile the statement

        Address a = Address.get("www.Dishaeducation.com");

it could see that the argument was a String literal, and
generate code that called method #1.

public class Address {
        public static Address get(String a) { ... }  // #1
        public static Address get(byte [] b) { ... } // #2
    }

 

Questions on Exceptional Handling

Questions on  Exceptional Handling :


Q: What are the different ways to handle exceptions?

A:  There are two ways to handle exceptions,

1. By wrapping the desired code in a try block followed by a catch block to catch the exceptions. and

2. List the desired exceptions in the throws clause of the method and let the caller of the method hadle those exceptions.

 

Q: If I write return at the end of the try block, will the finally block still execute?

A: Yes even if you write return as the last statement in the try block and no exception occurs, the finally block will execute. The finally block will execute and then the control return.

Q: How to create custom exceptions?

A: Your class should extend class Exception, or some more specific type thereof.

 

Q: If I want an object of my class to be thrown as an exception object, what should I do?

A: The class should extend from Exception class. Or you can extend your class from some more precise exception type also.

 

 Q: If my class already extends from some other class what should I do if I want an instance of my class to be thrown as an exception object?

A: One can not do anytihng in this scenarion. Because Java does not allow multiple inheritance and does not provide any exception interface as well.

 

 

Q:How does an exception permeate through the code?

A:An unhandled exception moves up the method stack in search of a matching When an exception is thrown from a code which is wrapped in a try block followed by one or more catch blocks, a search is made for matching catch block. If a matching type is found then that block will be invoked. If a matching type is not found then the exception moves up the method stack and reaches the caller method. Same procedure is repeated if the caller method is included in a try catch block. This process continues until a catch block handling the appropriate type of exception is found. If it does not find such a block then finally the program terminates.

 

Q: What is the basic difference between the 2 approaches to exception handling.

1  try catch block and

2  specifying the candidate exceptions in the throws clause

 

When should you use which approach?

A:      In the first approach as a programmer of the method, you urself are dealing with the exception. This is fine if you are in a best position to decide should be done in case of an exception. Whereas if it is not the responsibility of the method to deal with it's own exceptions, then do not use this approach. In this case use the second approach. In the second approach we are forcing the caller of the method to catch the exceptions, that the method is likely to throw. This is often the approach library creators use. They list the exception in the throws clause and we must catch them. You will find the same approach throughout the java libraries we use.

 

 

Q: Is it necessary that each try block must be followed by a catch block?

A: It is not necessary that each try block must be followed by a catch block. It should be followed by either a catch block OR a finally block. And whatever exceptions are likely to be thrown should be declared in the throws clause of the method.

 

 

Q:What are Checked and UnChecked Exception?

A: 

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·


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


Q:     What are runtime exceptions?

A: Runtime exceptions are those exceptions that are thrown at runtime because of either wrong input data or because of wrong business logic etc. These are not checked by the compiler at compile time.

Questions on Threads


Questions on Threads:

 

Q: What is Thread ?

A :  Thread is a program's path of execution.

Every thread has a priority. Threads with higher priority are executed in preference to threads with lower priority. Each thread may or may not also be marked as a daemon. When code running in some thread creates a new Thread object, the new thread has its priority initially set equal to the priority of the creating thread, and is a daemon thread if and only if the creating thread is a daemon.

When a Java Virtual Machine starts up, there is usually a single non-daemon thread (which typically calls the method named main of some designated class). The Java Virtual Machine continues to execute threads until either of the following occurs:

  • The exit method of class Runtime has been called and the security manager has permitted the exit operation to take place.
  • All threads that are not daemon threads have died, either by returning from the call to the run method or by throwing an exception that propagates beyond the run method.

There are two ways to create a new thread of execution. One is to declare a class to be a subclass of Thread. This subclass should override the run method of class Thread. An instance of the subclass can then be allocated and started. For example, a thread that computes primes larger than a stated value could be written as follows:

 

     class PrimeThread extends Thread {

         long minPrime;

         PrimeThread(long minPrime) {

             this.minPrime = minPrime;

         }

 

         public void run() {

             // compute primes larger than minPrime

              . . .

         }

     }

 

 

The following code would then create a thread and start it running:

     PrimeThread p = new PrimeThread(143);

     p.start();

 

The other way to create a thread is to declare a class that implements the Runnable interface. That class then implements the run method. An instance of the class can then be allocated, passed as an argument when creating Thread, and started. The same example in this other style looks like the following:

 

     class PrimeRun implements Runnable {

         long minPrime;

         PrimeRun(long minPrime) {

             this.minPrime = minPrime;

         }

 

         public void run() {

             // compute primes larger than minPrime

              . . .

         }

     }

 

 

The following code would then create a thread and start it running:

     PrimeRun p = new PrimeRun(143);

     new Thread(p).start();

 

Every thread has a name for identification purposes. More than one thread may have the same name. If a name is not specified when a thread is created, a new name is generated for it.

 

 Q  : What are the advantages or usage of threads?

A :

Ø Threads support concurrent operations.

Ø Threads often result in simpler programs.

Ø  Threads provide a high degree of control.

Ø Threaded applications exploit parallelism.

 

Q : What are the two ways of creating thread?

A There are two ways to create a new thread.

1)Extend the Thread class and override the run() method in your class. Create an instance of the subclass and invoke the start() method on it, which will create a new thread of execution. e.g.

public class NewThread extends Thread{

public void run(){
// the code that has to be executed in a separate new thread goes here
}
public static void main(String         ] args){
NewThread c = new NewThread();
c.start();
}

}

2)Implements the Runnable interface.The class will have to implement the run() method in the Runnable interface. Create an instance of this class. Pass the reference of this instance to the Thread constructor a new thread of execution will be created. e.g. class

public class NewThread implements Runnable{

public void run(){
// the code that has to be executed in a separate new thread goes here
}
public static void main(String         ] args){
NewThread c = new NewThread();
Thread t = new Thread(c);
t.start();
}

}


Q:What are the different states of a thread's lifecycle?

A: The different states of threads are as follows:

 

1) New – When a thread is instantiated it is in New state until the start() method is called on the thread instance. In this state the thread is not considered to be alive.


2) Runnable – The thread enters into this state after the start method is called in the thread instance. The thread may enter into the Runnable state from Running state. In this state the thread is considered to be alive.

3) Running – When the thread scheduler picks up the thread from the Runnable thread's pool, the thread starts running and the thread is said to be in Running state.

 4) Waiting/Blocked/Sleeping – In these states the thread is said to be alive but not runnable. The thread switches to this state because of reasons like wait method called or sleep method has been called on the running thread or thread might be waiting for some i/o resource so blocked.


5)      Dead – When the thread finishes its execution i.e. the run() method execution completes, it is said to be in dead state. A dead state can not be started again. If a start() method is invoked on a dead thread a runtime exception will occur.

            

Q: What is use of synchronized keyword?

Ans) The Java programming language provides two basic synchronization idioms: synchronized methods and synchronized statements.

To make a method synchronized, simply add the synchronized keyword to its declaration:

public class SynchronizedCounter {

    private int a = 0;

 

    public synchronized void increment() {

        a++;

    }

 

    public synchronized void decrement() {

        a--;

    }

 

    public synchronized int value() {

        return a;

    }

}

If count is an instance of Synchronized Counter, then making these methods synchronized has two effects:

  • First, it is not possible for two invocations of synchronized methods on the same object to interleave. When one thread is executing a synchronized method for an object, all other threads that invoke synchronized methods for the same object block (suspend execution) until the first thread is done with the object.
  • Second, when a synchronized method exits, it automatically establishes a happens-before relationship with any subsequent invocation of a synchronized method for the same object. This guarantees that changes to the state of the object are visible to all threads.

Note:  constructors cannot be synchronized — using the synchronized keyword with a constructor is a syntax error. Synchronizing constructors doesn't make sense, because only the thread that creates an object should have access to it while it is being constructed.

 

Q  What all constructors are present in the Thread class?

A:

Ø Thread()

Ø  Thread(Runnable target)

Ø Thread(Runnable target, String name)

Ø Thread(String name)

Q : Can the variables or classes be Synchronized?

A : No. Only methods can be synchronized.

 

 

Q: What is the difference when the synchronized keyword is applied to a static method or to a non static method?


A: When Synchronization is applied on a static Member or a static block, the lock is performed on the Class and not on the Object, while in the case of a Non-static block/member, lock is applied on the Object and not on class.         Trail 2: There is a class called Class in Java whose object is associated with the object(s) of your class. All the static members declared in your class will have reference in this class(Class). As long as your class exists in memory this object of Class is also present. Thats how even if you create multiple objects of your class only one Class object is present and all your objects are linked to this Class object. Even though one of your object is Garbage Collected after some time, this object of Class is not GCed untill all the objects associated with it are Garbage Collected.


This means that whenever you call a "static synchronized" block, JVM locks access to this Class object and not any of your objects. Your client can till access the non-static members of your objects.

 

 Q  How many locks does an object have?

Ans) Each object has only one lock.


Q : Can a class have both Synchronized and non-synchronized methods?

A Yes a class can have both synchronized and non-synchronized methods.

 

 

Q12) What happens if a start method is not invoked and the run method is directly invoked?

A:

 After a thread is started, via its start() method or that of the Thread class, the JVMinvokes the thread's run() method when the thread is initially executed.

If a thread has been instantiated but not started its is said to be in new state. Unless until a start() method is invoked on the instance of the thread, it will not said to be alive. If you do not call a start() method on the newly created thread instance thread is not considered to be alive. If the start() method is not invoked and the run() method is directly called on the Thread instance, the code inside the run() method will not run in a separate new thread but it will start running in the existing thread.

Q What happens when start() is called?

A:  

Whenever a start is called the state of thread changes from new to runnable. When the thread gets chance to execute its target run() method starts to run.

 

Q If code running is a thread creates a new thread what will be the initial priority of the newly created thread?

A:  

It creates a new thread object and  the priority of the new thread is set equal to the priority of the thread which has created it.


Q :  When jvm starts up, which thread will be started up first?

A : When jvm starts up the thread executing main method is started.

 

Q :  What are the daemon threads?

A:

1.      A daemon thread is a background thread.

2.     It is subordinate to the thread that creates it.

3.     When the thread that created the daemon thread ends, the daemon thread dies with it.

Example : Garbage Collector


Q What is a volatile keyword?

A:

Ø  volatile is used to indicate that a variable's value will be modified by different threads.

Ø Declaring a volatile Java variable means:

The value of this variable will never be cached thread-locally: all reads and  writes will go straight to "main memory";

Access to the variable acts as though it is enclosed in a synchronized block, synchronized on itself.