Tuesday, January 31, 2017

C Lanaguage Interview Questions

In this post i am sharing C Language Interview Questions and answers. These questions very helpful who are attending written test also. Since You can expect C language programming questions also in written Test. These question also helpful for technical interviews as well. specially who are attending off-campus interviews and for freshers helpful these questions.

1) What is C?

Ans: C is a Structured oriented programming language that was developed in the year 1970's. It was originally used for writing UNIX programs,but now used to write applications for nearly every available platform. C is easier to read,more flexible and more efficient at using memory.

2) Who Developed C programming?

Ans: The inventors of the C programming languages are Ken thompson and Dennis Ritche. The main purpose to develop C programming language is to the development of UNIX Operating System.

3) What is difference Between C and C++?

Ans: Even though C and C+ programming Languages are belonging to middle level languages.
  1. C is a Structured/procedural Orient Programming Language whereas C++ is Object Oriented Programming Language.
  2. C language program design is top-down approach whereas C++ is Bottom-up approach.
  3. Inheritance,virtual function,polymorphism,name space concepts are not avilable in C whereas C++ language supports all these concepts and fetures.
  4. C language gives importance to functions rather than data whereas C++ gives importance to the data rather than functions.
  5. C language does not support user define data types whereas C++ supports user define data types.
  6. Exception Handling is not present in the C language whereas C++ contains Exceptioin Handling concept.
4) Where we used exactly C language in real time?

Ans: C language is used to develop system applications that forms major portions of operating systems such as windows,UNIX and Linux. And also Compiler and all Unix application programs are written In C.

Fallowing are the few examples where we used exactly C language:

  • Database systems
  • word processors
  • spread sheets
  • OS
  • Network Drivers
  • Compilers and Assemblers
  • Interpreters
 5) What are the Characteristics of C language?

Ans: 
The Following are the Characteristics.
  • portability
  • Reliability
  • Flexibility
  • Efficiency
  • Modularity


6)What is difference between compiler,interpreter and Assembler?

Ans:  Assembler is a program that coverts assembly level language into machine level language. Compiler compiles entire C source code into Machine code whereas interpreter converts source code into intermediate code and then this intermediate code is executed line by line.

7) What are the applications of C?

Ans: This language is also called Middle level programming language. C programming can be used to do variety of tasks such as networking related and Operating System related.

8) What are the two forms of #include?

Ans: 
1. #include"file name"
2. #include



9) what are the data types in C?

Ans:  There are five basic data types associated with variables
1.Integer data type
2.float data type
3.double data type
4.char data type
5.void data type

10) What are input() and output() functions in C?

Ans: The input() function is scanf() function. It is used to read character,string,numeric data from the keyboard. scanf() function is an inbuilt library function which is available in stdio.h header file. The output() function is printf() function. It is used to to print the character,string,float,integer values onto the output screen.This function is also inbuilt library function which is available in stdio.h header file.

11) What is the structure of C Program?

Ans:  There are many sections in C program Structure. They are,
Document Section
Link Section
Definition Section
Global Declaration Section
Main function
User defined function section

12) What is IDE?

Ans: IDE stands for Integrated Development Environment. It is a tool that provides user interface with compiler to create,compile and execute C programs. Example: Turbo C++,Borland C++.

13) Is C language is case sensitive?

Ans: YES. C language instructions/functions everything used in c programs are case sensitive.

14) Can you define which header file to include at compiler time?

Ans: This can be done by using the #if,#else,and #endif preprocessor directives.

15) What is Data type in C?

Ans: Data types are defined as the data storage format that a variable can store a data to perform a specific operation. Data types are used to define a variable before to use in a program.

16) How can you tell whether a program was compiled using C  or C++?

Ans: The ANSI standard for the C language defines a symbol named _cplusplus that is defined only when you are compiling C++ program. When you are compiling a C program,the _cplusplus symblo is undefined.

17) What is modifier in C?

Ans:  The amount of memory space to be allocated for a variable is derived by modifiers. Modifiers are prefixed with basic data types to modify the amount of storage space allocated to a variable.

18)  What are the different types of modifiers in C?

Ans:  There are 5 modifiers available in C language. They are,

short
long
signed
unsigend
long  long

19) What is void in C?

Ans: Void is an empty data type that has no value. We use void data type in functions when we don't want to return any value to the calling function.

Example: void add(int x,int y); this function won't return any value to the calling function
                 int add( int x,int y); this function return value to the calling function

20) What is token in C?

Ans:  C tokens are basic buildings blocks in C language which are constructed together to write a C program. Each and every smallest individual unit in a c program are known as C tokens.

21) What is the use of sizeof() function in C?

Ans:  This functions is used to find the memory space allocated for each data type in C.

22) What is static memory allocation and dynamic memory allocation?

Ans: 
Static Memory allocation: The compiler allocates the required memory space for a declared variable. By using the address of operator,the reserved address is obtained and this address may be assigned to a pointer variable. Since most of the declared variable have static memory,this way of assigning pointer value to a pointer variable is known as static memory allocation. Memory is assigned during compilation time.

Dynamic memory allocation:It uses functions such as malloc() or calloc() to get memory dynamically. If these functions are used to get memory dynamically and the values returned by these functions are assigned to pointer variables such assignments are known as dynamic memory allocation.

23) How are pointer variables initialized?

Ans: Pointer variable are initialized by one of the fallowing two ways:
Static memory allocation
Dynamic memory allocation

24) Difference Between arrays and pointers?

Ans: Pointers are used to manipulate data using the address. Pointers use * operator to access the data pointed to by them. Arrays use sub-scripted variables to access and manipulate data. Array variables can be equivalently written using pointer expression.

25) What is pointer variable?

Ans: A pointer variable is a variable that may contain the address of another variable or any valid address in the memory.

26)Can static variables be declared in a header file?

Ans: You can't declare a static variable without defining it as well. A static  variable can be defined in a header file,but this would cause each source file that included the header file to have its own private copy of the variable,which is probably not what was intended.

27) How can you determine the size of an allocated portion of memory?

Ans: You can't,really. free() can,but there's no way for your program to know the trick free() uses. Even if you disassemble the library and discover the trick,there's no guarantee the trick won't change with the next release of the compiler.

28) What is difference between strings and character arrays?

Ans:  String will have static storage duration,whereas as a character array will not,unless it is explicitly specified by using the static keyword. 

29) what is difference between malloc() and calloc()?

Ans: There are two differences, First,is in the number of arguments. malloc() takes a single argument(memory required in bytes),while calloc()needs 2 arguments(number of variables to allocate memory,size in bytes of a single variable). Secondly,malloc() does not initialize the memory allocated,while calloc() initializes the allocated memory to ZERO.

30) What is exit() function in C?

Ans:  exit() function terminates the program normally and returns the status code to the parent program.

Syntax: void exit(int status)

Monday, January 30, 2017

TOP 10 Exceptions In Java

In this Post I am sharing Top Java Exceptions which are raised frequently while developing Java Source code. Now we will learn one by one with examples.

All Exceptions are divided into two categories. They are

a) JVM Exceptions:

 Raised automatically by the JVM when ever a particular condition occurs.

Ex: ArithmeticException, NullPointerException.

b) ProgramaticExceptions: 

These are raised programmatically because of programmers code or API’s developers Code.

Ex: IllegalArgumentException, NumberFormatException

JVM  Exceptions with example:
1) ArrayIndexOutOfBoundsException:- 

It is the child class of RuntimeException and it is unchecked thrown automatically by the JVM when ever we are accessing an array element with invalid int index.(Out of range index)

Ex:
int [] a = {10, 20, 30};
System.out.println(a[0]);
System.out.println(a[20]); // ArrayIndexOutOfBoundsException

2) NullPointerException:-
It is the direct child class of Runtime Exception and it is unchecked. Thrown automatically by the JVM when ever we are performing any operation on null.
            
Ex: 
String s = null;
System.out.println(s.length());  //NullPointerException

3)ClassCastException:- 

It is the child class of RuntimeException and it is unchecked. Thrown automatically by the JVM when ever we are trying to typecast parent class object to the child type.

Ex:

String s = "raju";
Object o = (Object)s;
Object o = new Object();
String s = (String)o;

 R.E: ClassCastException



4)IllegalArgumentException:- 

It is the child class of RuntimeException and it is unchecked thrown explicitly by the programmer or API developer when ever we are invoking a method with inappropriate or invalid argument.

Ex:

The valid range of Thread priority is 1 – 10 , if we are trying to invoke setpriority method with 100 as argument we will get IllegalArgumentException.

public void setPriority(int i){
if (i>10 || i<11)
{
throw new IllegalArgumentException();
}
}

5)NumberFormatException:- 

It is the child class of Illegal Argument and it is unchecked. Thrown programmatically when ever we are attempting to convert String to Number type but the String is not formatted properly

Ex:

String s = 10;
int i = Integer.parseInt(s);
String s = "ten";
int i = Integer.parseInt(s); // NullPointerException

6)IlleaglStateExcepiton:- 

It is the child class of Runtime Exception and it is unchecked. Thrown programmatically to indicate that a method has invoked at an inappropriate time

 Ex:
 After invalidating a session object we are not allowed to call any method on that object other wise IllegalStateException.
After comiting the response we are not allowed to redirect or forward otherwise IlleagalStateException
After starting a thread we are not allowed to start the same thread once again otherwise IlleagalStateException.
   
MyThread t = new MyThread();
t.start();
t.start(); // IllegalThreadStateException

Now Programatic Exception In Java:

7)NoClassDefFoundError:- 

It is the child class of Error and it is unchecked. Thrown automatically by the JVM if the required .class file is not available.

Ex:  java Test

 if Test.class file is not available we will get NoClassDefFoundError.


8) StackOverFlowError:- 

It is the child class of Error and it is unchecked. Raised automatically by the JVM when ever we are performing recursive method invocation.

Ex:
class Test
{
public static void m1();
{
 m1();
 }
public static void main(String arg[])
{
m1();
}
}
9) ExceptionInInitializerError:- 

It is child class of Error and it is unchecked. Raised automatically by the JVM when ever an Exception occur during initialization of static variables or execution of static blocks.

Ex:
class Test{
static int i = 10/0;
}
                                 

class Test{
static{
String s = null;
System.out.println(s.length());
 }
}

10) Assertion Error:-

It is the child class of Error and it is unchecked thrown programmatically to indicate
Assertion fails.

Ex:
Assert(false); // AssertionError




              

Resume Tips for freshers

Here are the Keys to Successfully Preparing and Writing a Strong and focused a job search resume. Following these simple rules and guidelines should help job seekers achieve success in this important phase of job hunting.

DO'S and DON'T in Resume Preparation:



  1. Do try building your own resume
  2. It is good to keep your resume in single page,if possible,but if you have lot of experience two pages may be more appropriate 
  3. Don't ever lie on your resume
  4. Do include ways to contact you- Website address/URL if possible,city and state only no street address, a single phone number and a single email address
  5. Do give your resume as sharp a focus as possible. 
  6. Don't use personal pronouns like I,my,me in a resume
  7. In listing your job, what's generally most important is your title/position. So list in preferred  order.
  8. Do list your jobs in reverse  chronological  order
  9. Do think in terms of accomplishments when preparing your resume.
  10. Don't Mention The Locations of your past jobs(city and state).
  11. Do list your jobs in reverse chronological  Order 
  12. Don't mix noun and Verb Phrases while describing your job. Preferably use concrete action verbs Consistently.
  13. Do avoid the verb"WORK"because it's a weak verb.Be more specific."Collaborate(d)"is often a substitute.
  14.  Don't emphasize transferable skills , especially if you do not have much experience or seek to change career
  15. Don't emphasize skills and job activities you don't want to do in feature.Even if they represent great strength for you. In fact,you may even want to mention these activities.
  16. Don't list your high school(Unless you are teenager)
  17. Don't include on your resume height,weight,age,date of birth,place of birth,marital status,sex,reasons for leaving previous job(s),salary information,picture of yourself and the title"Resume".
  18. Don't include hobbies or other irrelevant information on your resume.An arguments can be made that hobbies are interview conversation starters, or that make you seem well-rounded.But they are generally see you filler.
  19. Do however,list sports if you are a college student or new graduate.
  20. Don't list  references right on  resume.References belong in the later stage of job search.Keep references on a separate sheet and provide them only when they are specially requested




String Interview Questions

In this article we are going to discuss about String Interview Questions in java.These questions frequently asked from the String topic in java specially for beginners.

1.  What is String in java? Is String is  a data type?

Ans: String is a class in java and defined in java.lang.package. String class represents character Strings. String is used almost in almost all the java applications and there are some interesting facts we should know about it.

String is immutable and final in java
JVM uses String pool to store all the String Objects
we can initiate String Object using double quotes

2.What are the different ways to create String Object?

Ans: We can create String Object using new operator just like any normal java class or create a String Object.

Ex:  
String st=new String("abc");
String st1="abc";

     When we create  a String using double quotes, JVM looks in the String Pool to find if any other String is stored with same value. If found,it just returns the reference to that String Object else it creates a new String object with given value and stores it in the String pool.

               When we use new operator, JVM creates the String object but don not store it into the String Pool. We can use use intern() method to store the String object into the String pool or return the reference if there is already a String with equal value present in the pool.


3. Why String is immutable in Java?

Ans: String is one of the most used classes in any programming language. As we know that String is immutable and final in java and java runtime maintains a String pool that makes it a special class. Immutable in the sense of memory. It creates string or assign a new String/change the value.
               If several references point to same String without even knowing it, it would be bad if one of the references modified that string value. That's why string objects are immutable. And what if someone  overrides the functionality of string class? That's the reason that the string class is marked final so that nobody can override the behavior of its methods.

4. What are the benefits of String immutability?

Ans: At a high level, benefits would be security, Thread Safety and memory efficiency.

 String pool is possible  only because String is immutable in java, this way java Runtime saves lot of java heap space because different String  variables in the pool. If String would not have been immutable , then String interning would not have been possible because if any variable would have changed that value, it would have been reflected to other variable also.
5. What is String  Pool in Java?

Ans:   String pool is a pool of Strings stored in java Heap Memory. We know that String is special class in java and we can create String Object using new operator as well as providing value in double quotes. String pool is possible  only because String is immutable in java and it's implementation of String interning concept.

                String pool is also example of Flyweight  design pattern. String pool helps in saving a lot of space for java Runtime although it takes more time to create the String. 

                When we use double quotes to create a String, it first looks for String with same value in the String Pool , if found it just returns the reference else it creates a new String in the pool and then returns the reference. However, using new operator, we force string class to create new String  object and then we can use intern()method to put it into the pool or refer to other string object from pool having same value. 



6. Why char array is preferred over String for storing password?

Ans:  String is immutable in java and stored in String pool. Once it is created it stays in the pool until unless garbage collected, so even though we done with password it is available in the memory for longer duration and there is no way to avoid it. It is a security risk because anyone having access to memory dump can find the password as clear text.
  
               If we use char array to store password,we can set it to blank once we are done with it. So we can control for how long it is available in memory that avoids the security threat with String.

7. How do you check if two Strings equal in java or not?

Ans :  There are two ways to check if two Strings are equal or not

using "==" operator or using equals() method. when we use "==" operator , it checks for value of string as well as reference  but in our programming,most of the time we are checking equality of string for value only. So we should use equals() method to check if two string are equal or not. 

Ex:   
String s1="abc"
String s2="abc";
String s3=new String("abc");
System.out.println("s1==s1?"+(s1==s2));//true
System.out.println("s1==s3?"+(s1==s3));//false
System.out.println("s1 equals s3?"+(s1.equals(s3));//true

8. Does String is thread-safe in java?

Ans:  String are immutable, so we can't change it's value in program. Hence it's thread-safe and can be safely used in multi-threaded environment.

9. Why String is popular HashMap key in java?


Ans:  Since String is immutable, it's hash code is cached at the time of creation and it doesn't need to be calculated again. This makes it a great candidate for key in a Map and it's processing is fast than other  HashMap Key objects. This is why String is mostly used Object as HashMap keys.

10) What is difference Between StringBuffer and String Builder?

Ans: 

  1. StringBuffer is synchronized and StringBuilder is not
  2. StringBuffer is thread-safe and StringBuilder is not
  3. StringBuilder is faster than StringBuffer because of no overhead of acquiring and releasing locks associated with synchronized methods.

Sunday, January 29, 2017

Java MultiThreading Interview Questions

Multi Threading in java is a process of executing multiple threads simultaneously. But we use Multi Threading than multi processing because threads share a common memory area. In this post,we will learn multi threading interview questions and answers. These interview questions are frequently asked by interviewer.

1. What is Thread in java?

Ans: Thread is an Independent sequential path of execution within a process. Threads are light weight process. Threads are exists in common memory space and can share resources data and code.Threads can run parallel. In java, Thread  is represented and controlled by an object of class Java.lang.Thread.


2. What is difference between Thread and Process?

Ans:  A Thread is lightweight compared to process.Threads are subdivision of process.Threads exists within a process and shares the process resources like memory whereas Process is self contained execution environment. Each process has its own memory space.
Threads have direct access  to the data segment of its process whereas process  has own copy of the data segment.
Context-switching between threads in the same process is very fast whereas context-switching between process is slower.
Threads can easily communicate within the process whereas  process communicate only system provided inter process communication mechanism.

3. How many ways you can create Thread in java?

Ans:  You can create a Thread in two ways in java. They are

    a) Extending a Thread class

    b)  Implementing a Runnable interface

4. What is Multitasking? How it can be achieved?

Ans: Multitasking is a process of executing multiple tasks simultaneously. We use multitasking to utilize the CPU power. 

Multitasking can be achieved by two ways: 

1. Process-based Multitasking(Multiprocessing)
2.Thread-based Multitasking(Multithreading)

5. What is Multiprocessing ?

Ans: Multiprocessing is nothing but process-based Multitasking. Each process have its own address in memory i.e. each process allocates separate memory area.Process is heavy weight. Cost of communication between the process is high. Switching from one process to another require some time for saving and loading registers,memory maps,updating lists etc..

6. What are the benefits of Multithreaded Programming?

Ans: In multi-threaded programming,multiple threads are executing concurrently that improves the performance because CPU is not idle in case some thread is waiting to get some resources. Multiple threads share the heap memory. So, it is good to create multiple threads to execute some task rather than creating multiple processing.


Example: Servlets are better in performance than CGI because servlet support multi-threading but CGI does not. It does not block the user because threads are independent and you can perform multiple operations at same time. Threads are independent so it doesn't affect other threads if exception occur in a single thread.

7. Difference between user Thread and daemon Thread?

Ans: When  we create a Thread in java program,it's known as user Thread. A daemon thread runs in background and doesn't prevent JVM from terminating. When there are no user threads running. JVM shutdown the program and quits.



8. How can we pause the execution of a Thread for specific time?

Ans: we can use Thread class sleep() method to pause the execution of Thread for certain time. Note that this will not stop the processing of thread for specific time,once the thread awake from sleep,it's state get changed to runnable and based on thread scheduling,it gets executed.

9.  What is Context-switching in multi-threading?

Ans: Context-switching is the process of storing and restoring of CPU state so that Thread execution can be resumed from the same point at a later point of time.It is essential feature for multitasking operating system and support for multi-threaded environment.

10.  How can you make sure main() is the last thread to finish in java program?

Ans: we can use Thread join() method to make sure all the threads created by the program is dead before finishing the main function.

11. Why thread communication methods wait(),notify(),notifyAll() are in Object class?

Ans: In java every object has a monitor and wait,notify methods are used to wait for the Object monitor or to notify other threads that Object monitor is free now. There is no monitor on threads in java and synchronization can be used with any Object,that's why it's part of Object class so that every class in java has these essential methods for inter thread communication

12What is Difference between Wait() and sleep() in java?


Ans:  Firstly you must aware of where these methods are exists. wait() method exist in Object class whereas sleep() method available in the Thread class. sleep() method is used the currently executing thread to sleep for specific period of time(in milliseconds)  whereas wait() method causes the current thread to wait until another thread invokes notify() or notifyall() for this object. Here thread releases the lock as soon as wait is called,but in case of sleep() method the Thread does not release the lock.

13. How can we achieve thread safety in Java?

Ans: There are several ways to achieve thread safety in java-Synchronization,atomic concurrent classes,implementing concurrent Lock interface,using volatile keyword,using immutable classes and Thread safe classes.

14. Which is more preferred Synchronized method or Synchronized block?

Ans: Synchronized block is more preferred way because it does not lock the Object,synchronized methods lock the Object and if there are multiple synchronization blocks in the class,even  though they are not related,it will stop them from execution and put them in wait state to get the lock on Object.


15) What is the use of Synchronized in java?

Ans: Synchronized keyword is used  in java to control the access of multiple threads on shared resources. Synchronized keyword can be applied to static and instance methods and synchronized block in java of  the code. If you apply synchronized keyword for method only one thread can access the same thread then other threads have to wait for the execution of method by one thread. Synchronized keyword provides a lock on the object.

16)  What is the internal process when start() method is called?

Ans:  A new Thread of execution with a new call stack starts. And then the state of thread change from new to Runnable. When  thread gets chance to execute its target run() method start to run.

17) What will happen if you do not override run()method?

Ans:  This is basic question on thread , interviewer want to know your knowledge on thread api and you really have knowledge how to create and run a thread.

When we call start() method it internally calls run() method  with newly created thread.So if we do not override run() method a newly created thread will not called and nothing happen. that run() method executes just like normal method.

18) What is difference between notify() and notifyall() method in java?


Ans: Their might be several threads waiting for this object and only one of them is chosen.notify() method  is main work is wake up a single thread  that is waiting on this object whereas notifyall() methods wakes up all the threads that are waiting on this object's monitor.


Design Pattern Interview Questions

In this Page, we will learn frequently asked Design Patterns Interview Questions, which are most managers expect from their developers to have depth knowledge on important patterns. These Interview questions are asked in various java interview. 

Fallowing are the Java Design Pattern Interview Questions:

1) What is Design Pattern?

Ans:

Design Pattern is a general resolution to a commonly occurring problem with in a specific context when designing an application or system . These are tried and tested way to solve particular design issues by various programmers. 


2) What are the elements in Design Pattern?

Ans: There are 3 main elements in Design Pattern . They are

a) Context
b) Problem
c) Solution

a) Context:

It is a recurring situation in which a problem to be solved is found. 

b) Problem:

The problem describes when to apply the pattern. It might describe a specific design problem such as how represent  algorithms as objects. 

c) Solution:

In this pattern provides abstract description of a design problem and how the arrangements of classes and objects to solve it. It works as a template which can be fulfilled with the code.

Note:  The design pattern contains not only above three elements, The relationship between three and formal language that describe the whole business.

3) Can you name few Design Pattern used in Standard JDK library?

Ans:

In JDK library few of the design patterns were used, they are Decorator design pattern which is used in various Java I/O classes,Singleton Pattern which is used in Runtime,Calendar and various other classes,Factory pattern which is used along with various immutable classes like Boolean  and Observer pattern which is used in Swing and many event listener frameworks.

4) What is MVC Design Pattern?

Ans:

MVC means Model-View-Controller, It is a clear functional separation of roles. That means it separate the application logic from the user interface and control between the user interface and the application logic. 

Model: The model represents data and the rules that govern access to and updates of this data. In java program language usually model is Java Beans. The main responsibility of model is to interact with persistence storage to store,retrieve and manipulate data.

View: The view renders the contents of a model. That means it is responsible for displaying results back to the user.This is usually implemented by using JSP.

Controller:  It translates the user's request and select appropriate view to return. The controller job is done by Servelts

5) What is Singleton Design Pattern ?

Ans:  A Singleton is a class which only allows a single instance of itself to be created,and usually gives simple access to that instance. It focus on sharing of expensive object in whole system. Only one instance of of a particular class is maintained in whole application which is shared by all modules.



6) What is factory Design Pattern? where do you use it?

Ans:  The factory Pattern gives us a way to encapsulate the incantations of concrete types. That means it increased level of encapsulation while creating objects. If you use Factory to create object you can later replace original implementation of Products or classes with more advanced and high performance implementation without any change on client layer. 

7) What Front Controller Pattern? Explain?

Ans:  The Front Controller is a entry point to a website. It provides a centralized entry point that controls and manages the web request handling. It is a presentation controller that allows the resources to change without breaking all the bookmarks to a given resource. For Example, Microsoft often changes the contents in it library. The main purpose of this pattern is to isolates the actual resources from direct access by the user. This controller must delegate the request to the proper resource and view.

8)  What is Observer Design Pattern?

Ans:  This pattern is based on communicating changes in state of object to observers so that they can take there action. For example, A whether system where change in weather must be reflected in views to show to public. Here weather object is Subject while different views are Observers. The other way to understand Observer pattern is publisher-subscriber relationship works. Whenever a new issue is published,it gets delivered to you ,but the publisher continues to work as before, since there are other people also subscribed to that particular Magazine.

9) Give example of Decorator Design Pattern in Java?

Ans: The Decorator Design Pattern is to attach the additional responsibilities to an object dynamically. That means enhances capability of individual object. Java IO uses decorator pattern extensively. For example, Buffered classes like BufferedReader and BufferedWriter which enhances Reader and Writer objects to perform Buffer level reading and writing for improved performance. The main purpose of this pattern is adds the responsibility to the components.

10) What is DAO Pattern?

Ans:  DAO means Data Access Object, it provides a connection between the business logic and the resource usually a database tier. It is a general interface to the resource layer. JDBC or Hibernate most commonly used examples for this. It is an object that encapsulates a set of behaviors for accessing a databases,files and other resources. This way you have only one API to deal with rather than a different one for every type of resource.This pattern proved a uniform API to any persistent data storage.