Search This Blog

Friday 23 May 2014

IOS INTERVIEW Questions

Q1.What  is property?

Ans:Properties are used  to  access  the  instance  variables  from  outside  of  class.

Q2. What  is synthesized?

Ans:After  you  declare  the  property  in objective-c .  we  have  tell  the  copiler instantly  by  using  synthize  directive.Actuvally  this  tells  to compiler  generate  a  getter&setter  message.

Q3.What  is nonatomic?

Ans:To avoid  conflict  the  multithreading.

Q4. What  is retain?

Ans:It is reference count of the object.

Q5. What  is webservice?

Ans:Main  purpose is  to expose the data  in  form  of xml  format  ,by  using  this  we  can  getting  the  data  from  server.

Q6. What  is parsing?

Ans:To  access the data  in the  xml  element  is called  parsing.

Q7.Which class  we  can  use  for  passing  of xml  in  iphone?

Ans:By  “NSXML” Parser.
Q8.Which  type of  parse  we  have  use  in  iphone?
Ans:”SAX” parser.

Q9.Which  class are used to establish  connection  b/w application to webserver?

Ans:(a)NSURL
         (b)NSURL REQUEST
         (c)NSURL CONNECTION.

Q10.What  is difference between DOM&SAX?

Ans:(a)Dom is a documents based parser.
When we will work with these parser all the data of xml is stored in RAM.                                                          In this parser  “memory consumption” is more. 
(b)SAX  is  a  event  driven parser.
When we will work with these parser,take only  reference  from  xml file  and  generate  the        oneevent  for  every element.

Q11.After  parsing  if  you  want  to  get your data in  view  which  delegation  methods  are  did  you use?

Ans:(a)did  start  element
         (b)did  end  element
          (c)found  character.

Q12.How many  methods  are  used  in  NSURLConnection?

Ans:I  have 4 types methods
(a)Connection  did  receive  Response
(b)Connection  did  recevice  Datat
(c)Connection  fail  with error
(d)Connection  did  finish loading.

Q13.Tell  me  about  json-parser?

Ans:”JSON” Means  “Java script object notation”.
           It is a one  type  of  parser (or)test-based  and  hightweight  parser.

Q14.By  default application which  things  contain?

Ans:In ipone applications  by  default  having 3 things
1.mainIt is  entry  point of  application.
2.AppdelegateIt is  perform  the  basic application  &  functionality.
3.WindowIt  is  provide  uiinterface.
Q15.What is  uiviewcontroller?
Ans:   uiview controller  is base class for all the controller.

Q16. What is the navigation controller?  
                                                                                        
Ans: Navigation  controller contains the stack of controllers every navigation controller
         must be having root view controller by default these controllers contain 2 methods   
         (a) push view 
         (b) pop view
      By default navigation controller contain “table view”.

Q17. What is tab bar controller? 
  
 Ans: Tab bar is used to common way to display the data on iphone.

Q18. What is the table view controller?

Ans: Table view controller contains the number of rows and columns visible in the 
         application  and makes a cell editable or not as a response to key press

Q19. Which protocols are did used in table view?

Ans: Table view contain 2 delegate protocols

               (a). Ui table view data source
               (b). Ui table view delegate.

         In ui view table view data source contain these methods

               (a). No of sections.
               (b). No of rows in sections.
               (c). Cell for row index path row.

        In ui table view delegate contain these methods

               (a). Did select row at index path row

Q20. By default table view which controller contain?

Ans: Detail view controller that is present is ui table view delegate

Q21.  What is the split view controller?

Ans: This control is used for ipad application and it contain proper controllers by default 
         split view controller contain root view controller  and detail view controller.

Q22.  What are data base are used in iphone?

Ans: (a). Sql lite  
          (b). Plist
          (c). Xml 

Q23. Tell me about the MVC architecture?

Ans: M-model, V-view, C-controller

         Main advantage of MVC architecture is to provide “reusability and security”
         by separating the layer by using MVC architecture.

         Model it is a class model is interact with database.
         controller  controller is used for by getting the data from model and controls the views.
         view display the information in views.

Q24. What are frame works are used in iphone?

Ans:       (a). Ui kit framework
               (b). Map kit framework
               (c). ADI kit framework
               (d). Core data framework
               (e).core foundation framework

Q25. What is the instance methods?

Ans: Instance methods are essentially code routines that perform tasks so instances 
        of clases we create methods to get and set the instance variables and to display
         the current values of these variables.

         Declaration of instance method : 

                    - (void)click me: (id)sender;       

         Void is return type which does not giving any thing here.
          Click me is method name.
          Id is data type which returns any type of object.

Q26. What is the class method?

Ans: Class methods work at the class level and are common to all instance of a 
         class these methods are specific to the class overall as opposed to working 
         on different instance data encapsulated in each class instance.

        @interface class name :ns object
         {
          }

        +(class name *)new alloc:
-(int)total open

Q27. What is data encapsulation?

Ans: Data is contained with in objects and is not accessible by any other than
         via methods defined on the class is called data encapsulation.

Q28. What is accessor  methods?

Ans: Accessor methods are methods belonging to a class that allow to get and set 
         the values of instance valuables contained with in the class.

Q29. What is synthesized accessor methods?

Ans: Objective-c provides a mechanism that automates the creation of accessor
         methods that are called synthesized accessor methods that are
    1.             implemented through use of the @property and @synthesized.

Q30. How to access the encapsulated data in objective-c?

Ans:(a) Data encapsulation encourages the use of methods to +get and set the values 
              of instance variables in a class.
        (b)But the developer to want to directly access an instance variable with out 
             having to go through an accessor method. 
        (c) In objective-c syntax for an instance variable is as follow 

                   [class instance variable name]

Q31. What is dot notation?

Ans: Dot notation features introduced into version 2.0 of objective-c
         Dot notation involves accessing an instance variable by specifying 
         a class “instance” followed by a “dot” followed in  turn by the name of
         instance variable or property to be accessed.

Q32. What is single inheritance in objective-c?

Ans: Objective-c subclass can only be derived from a single direct parent class this
         concept is called as “single inheritance”.

Q33. Ns object is parent class or derived class?

Ans: Ns object is parent class and contains a number of instance variables and
         instance methods.

Q34. How to call function in objective-c?

Ans:   [account display account info]
           Account-> object name
           Display account info-> method name
-------------------------------------------------------------------------------------------------------------------------

1.What is iphone?
Iphone is a combination of internet and multimedia enabled smart phone developed by apple.

2.what is iphone os?
Iphone os runs on iphone and ipod touch devices.hardware devices are managed by iphone os and provide the technologies needed for implementing native applications on the phone.the os ships with system application such as mail, safari, phone, which provided standard services to the user.

3.what is iphone sdk?
Iphone sdk is available with tools and interface needed for developing, installing and running custom native appllications.native applications are built using the iphone os’s system frameworks and objective-c language and run directly on iphone os. Native applications are installed physically on a device and run in presence or absence of network connection.

4. What is iphone architecture?  
It is similar to MacOS X architecture 
It acts as an intermediary between the iPhone and iPod hardware an the appearing applications on the screen
The user created applications never interact directly with the appropriate drivers, which protects the user applications from changes to the hardware.

5. What is iphone reference library?  
iPhone reference library is a set of reference documents for iPhone OS . 
It can be downloaded by subscribing to the iPhone OS Library doc set.
Select Help>Documentation from Xcode, and click the subscribe button next to the iPhone OS Library doc set, which appears in the left column.  
6. Question:-Swap the two variable values without taking third variable?
Ans:-
int x=10;
int y=5;
x=x+y;
NSLog(@”x==> %d”,x);
y=x-y;
NSLog(@”Y Value==> %d”,y);
x=x-y;
NSLog(@”x Value==> %d”,x);

7. Difference between shallow copy and deep copy?
What is advantage of categories? What is difference between implementing a category and inheritance?
Difference between categories and extensions?
Difference between protocol in objective c and interfaces in java?
What are KVO and KVC?
What is purpose of delegates?
What are mutable and immutable types in Objective C?
When we call objective c is runtime language what does it mean?
what is difference between NSNotification and protocol?
What is push notification?
Polymorphism?
Singleton?
What is responder chain?
Difference between frame and bounds?
Difference between method and selector?
Is there any garbage collection mechanism in Objective C.?
NSOperation queue?
What is lazy loading?
 Can we use two tableview controllers on one viewcontroller?
Can we use one tableview with two different datasources? How you will achieve this?
What is advantage of using RESTful webservices?
 When to use NSMutableArray and when to use NSArray?
What is the difference between REST and SOAP?
Give us example of what are delegate methods and what are data source methods of uitableview.
How many autorelease you can create in your application? Is there any limit?
If we don’t create any autorelease pool in our application then is there any autorelease pool already provided to us?
When you will create an autorelease pool in your application?
When retain count increase?
Difference between copy and assign in objective c?
What are commonly used NSObject class methods?
What is convenience constructor?
How to design universal application in Xcode?
What is keyword atomic in Objective C?
What are UIView animations?
How can you store data in iPhone applications?
What is coredata?
What is NSManagedObject model?
What is NSManagedobjectContext?
What is predicate?
What kind of persistence store we can use with coredata?

.
8. What is advantage of categories? What is difference between implementing a category and inheritance?
You can add method to existing class even to that class whose source is not available to you. You can extend functionality of a class without sub classing. You can split implementation in multiple classes.
While in Inheritance you subclass from parent class and extend its functionality.
Difference between categories and extensions?
Class extensions are similar to categories.
The main difference is that with an extension, the compiler will expect you to implement the methods within your main @implementation, whereas with a category you have a separate @implementation block. So you should pretty much only use an extension at the top of your main .m file (the only place you should care about ivars, incidentally) — it’s meant to be just that, an extension.

9. What is purpose of Delegates?
Ans: A delegate allows one object to send messages to another object when an event happens.
For example, if you’re downloading data from a web site “asynchronously” using the NSURLConnection class. NSURLConnection has three common delegates
– (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
– (void)connectionDidFinishLoading:(NSURLConnection *)connection
– (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
One or more of these delegates will get called when NSURLConnection encounters a failure, finishes successfully, or received a response from the web site, respectively.

10. iPhone interview questions 

1) What is Xcode and iPhone SDK?
2) What is the difference between retain and release?
3) Difference between retain and copy ?
4) Difference between delegate and datasource?
5) Any five delegate and datasource method of UITableView with their explanation ?
6) Explain delegation, categories, and subclassing. What are their pros/cons? Can you give examples where you would use one over the other?
7) Difference between sax parser and dom parser ?
8) What is atomic and non atomic ?
9) XML parsing procedure (NSXMLParser).
10) What is @synthesize?
11) Explain deep copy and shallow copy ?
12) Difference between pass by value and pass by reference ?
13) Write a simple prog to add data using SQLITE?
14) Write a simple prog to parse an xml file (xml file structure will be provided by the company)
15) What is a class difference between a class and a structure ?
16) Difference between table view and picker view?
17) Write a program, if u have two classes A and B. A contain some class and instance method and you have to invoke this method in B. Do it without using inheritance?
18) Difference between UIView and UIViewController ?
19) Steps to deploy an app into the device ?
20) Difference between protocol and delegate ?
21) Difference between C++ and Objective C ? (link to my another blog on iPhone)
22) Explain stack and heap?
23) Why dynamic memory allocation is required?
24) Explain the types of Notification in iPhone ? and how to use them ?
25) Few Questions on your iPhone Project (if any)
26) Given an object of an unknown type, how would you determine its class? How would you check to see if it conforms to a given protocol? How would you check to see if it responds to a given message/selector?
27) Difference between frames and bounds ?
28) what is the difference between a synchronous and an asynchronous request ?
29) How to display different image from the server inside the table view ?
30) Difference between release and autorelease ?

Few other links to iPhone interview questions


1) http://www.moszi.net/dev/?p=17
2) http://www.applausible.com/blog/?p=654
3) http://www.techipost.com/2011/08/11/iphone-interview-questions/
4) http://anujbansal1810.blogspot.com/2011/08/c-is-sea.html
5) http://yoursiphone.blogspot.com/2010/08/interview-questions-part-2.html
6) http://placementpapers.net/helpingroot/Oops/Important-Interview-Questions-On-Object-Oriented-Programming-Concepts


I hope the above interview questions for iPhone help you to crack the interview and if they do then please let me know via comments or via mails, until then happy iCoding and have a great Day. 

11. I’ve been interviewing alot of people recently for iPhone and iPad developer positions. Asides from algorithm runtime problems, I ask some general iOS questions. So being the kind person I am, i’m posting some questions based on difficulty and expected answers.
NOTE: If you want to test your iOS skills before you read the answers, here’s a text file just with questions – iOS Interview questions
BEGINNER
    •    Q: How would you create your own custom view?
A: Subclass the UIView class. 
    •    Q: Whats fast enumeration?
A: Fast enumeration is a language feature that allows you to enumerate over the contents of a collection. (Your code will also run faster because the internal implementation reduces message send overhead and increases pipelining potential.) 
    •    Q: Whats a struct?
A: A struct is a special C data type that encapsulates other pieces of data into a single cohesive unit. Like an object, but built into C. 
    •    Q: Whats the difference between a NSArray and a NSMutableArray?
A: A NSArray’s contents can not be modified once it’s been created whereas a NSMutableArray can be modified as needed, i.e items can be added/removed from it. 
    •    Q: Explain retain counts.
A: Retain counts are the way in which memory is managed in Objective-C. When you create an object, it has a retain count of 1. When you send an object a retain message, its retain count is incremented by 1.
When you send an object a release message, its retain count is decremented by 1. When you send an object a autorelease message, its retain count is decremented by 1 at some stage in the future. If an object’s retain count is reduced to 0, it is deallocated.
    •    Q: Whats the difference between frame and bounds?
A: The frame of a view is the rectangle, expressed as a location (x,y) and size (width,height) relative to the superview it is contained within.
The bounds of a view is the rectangle, expressed as a location (x,y) and size (width,height) relative to its own coordinate system (0,0).
    •    Q: Is a delegate retained?
A: No, the delegate is never retained! Ever!
INTERMEDIATE
    •    Q: If I call performSelector:withObject:afterDelay: – is the object retained?
A: Yes the object is retained. It creates a timer that calls a selector on the current threads run loop. It may not be 100% precise time-wise as it attempts to dequeue the message from the run loop and perform the selector. 
    •    Q: Can you explain what happens when you call autorelease on an object?
A: When you send an object a autorelease message, its retain count is decremented by 1 at some stage in the future. The object is added to an autorelease pool on the current thread. The main thread loop creates an autorelease pool at the beginning of the function, and release it at the end. This establishes a pool for the lifetime of the task. However, this also means that any autoreleased objects created during the lifetime of the task are not disposed of until the task completes. This may lead to the task’s memory footprint increasing unnecessarily. You can also consider creating pools with a narrower scope or use NSOperationQueue with it’s own autorelease pool. (Also important – You only release or autorelease objects you own.)
    •    Q: Whats the NSCoder class used for?
A: NSCoder is an abstractClass which represents a stream of data. They are used in Archiving and Unarchiving objects. NSCoder objects are usually used in a method that is being implemented so that the class conforms to the protocol. (which has something like encodeObject and decodeObject methods in them). 
    •    Q: Whats an NSOperationQueue and how/would you use it?
A: The NSOperationQueue class regulates the execution of a set of NSOperation objects. An operation queue is generally used to perform some asynchronous operations on a background thread so as not to block the main thread. 
    •    Q: Explain the correct way to manage Outlets memory
A: Create them as properties in the header that are retained. In the viewDidUnload set the outlets to nil(i.e self.outlet = nil). Finally in dealloc make sure to release the outlet.
ADVANCED
    •    Q: Is the delegate for a CAAnimation retained?
A: Yes it is!! This is one of the rare exceptions to memory management rules.
    •    Q: What happens when the following code executes? 
1
Ball *ball = [[[[Ball alloc] init] autorelease] autorelease];
    •    A: It will crash because it’s added twice to the autorelease pool and when it it dequeued the autorelease pool calls release more than once. 
    •    Q: Outline the class hierarchy for a UIButton until NSObject.
A: UIButton inherits from UIControl, UIControl inherits from UIView, UIView inherits from UIResponder, UIResponder inherits from the root class NSObject
    •    Q: Explain the difference between NSOperationQueue concurrent and non-concurrent.
A: In the context of an NSOperation object, which runs in an NSOperationQueue, the terms concurrent and non-concurrent do not necessarily refer to the side-by-side execution of threads. Instead, a non-concurrent operation is one that executes using the environment that is provided for it while a concurrent operation is responsible for setting up its own execution environment.
    •    Q: Implement your own synthesized methods for the property NSString *title.
A: Well you would want to implement the getter and setter for the title object. Something like this:
1
- (NSString*) title {
2
  return title;
    •    
3
}
4
- (void) setTitle: (NSString*) newTitle {
    •    
5
 if (newTitle != title) {
6
     [title release];
    •    
7
     title = [newTitle retain]; // Or copy, depending on your needs.
8
 }
    •    
9
}
    •    Q: Implement the following methods: retain, release, autorelease.
A: 
01
-(id)retain {
02
  NSIncrementExtraRefCount(self);
    •    
03

04
  return self;
    •    
05
}
06

    •    
07
-(void)release {
08

    •    
09
  if(NSDecrementExtraRefCountWasZero(self)) {
10
    NSDeallocateObject(self);
    •    
11
  }
12
}
    •    
13

14
-(id)autorelease {
    •    
15
  // Add the object to the autorelease pool
16
  [NSAutoreleasePool addObject:self];
    •    
17

18
  return self;
    •    
19
}
..12. iOS Questions for Beginers

* Q: How would you create your own custom view?
A:
By Subclassing the UIView class.

* Q: Whats fast enumeration?
A:
Fast enumeration is a language feature that allows you to enumerate over the contents of a collection. (Your code will also run faster because the internal implementation reduces
message send overhead and increases pipelining potential.)

* Q: Whats a struct?
A:
A struct is a special C data type that encapsulates other pieces of data into a single cohesive unit. Like an object, but built into C.

* Q: Whats the difference between  NSArray and  NSMutableArray?
A:
A NSArrayʼs contents can not be modified once itʼs been created whereas a NSMutableArray can be modified as needed, i.e items can be added/removed from it.

* Q: Explain retain counts.
A:
Retain counts are the way in which memory is managed in Objective-C. When you create an object, it has a retain count of 1. When you send an object a retain message, its retain
count is incremented by 1. When you send an object a release message, its retain count is decremented by 1. When you send an object a autorelease message, its retain count is decremented by 1 at some
stage in the future. If an objectʼs retain count is reduced to 0, it is deallocated.

* Q: Whats the difference between frame and bounds?
A:
The frame of a view is the rectangle, expressed as a location (x,y) and size (width,height) relative to the superview it is contained within. The bounds of a view is the rectangle, expressed as a location (x,y) and size (width,height) relative to its own coordinate system (0,0).

* Q: Is a delegate retained?
A:
No, the delegate is never retained! Ever!

iOS Questions  for Intermediate level

* Q: If I call performSelector:withObject:afterDelay: – is the object retained?
A:
Yes, the object is retained. It creates a timer that calls a selector on the current threads run loop. It may not be 100% precise time-wise as it attempts to dequeue the message from
the run loop and perform the selector.

* Q: Can you explain what happens when you call autorelease on an object?
A:
When you send an object a autorelease message, its retain count is decremented by 1 at some stage in the future. The object is added to an autorelease pool on the current
thread. The main thread loop creates an autorelease pool at the beginning of the function, and release it at the end. This establishes a pool for the lifetime of the task. However, this also means that any autoreleased objects created during the lifetime of the task are not disposed of until the task completes. This may lead to the taskʼs memory footprint increasing unnecessarily. You can also consider creating pools with a narrower scope or use NSOperationQueue with itʼs own autorelease pool. (Also important – You only release or autorelease objects you own.)

* Q: Whats the NSCoder class used for?
A:
NSCoder is an abstractClass which represents a stream of data. They are used in Archiving and Unarchiving objects. NSCoder objects are usually used in a method that is being
implemented so that the class conforms to the protocol. (which has something like encodeObject and decodeObject methods in them).

* Q: Whats an NSOperationQueue and how/would you use it?
A:
The NSOperationQueue class regulates the execution of a set of NSOperation objects. An operation queue is generally used to perform some asynchronous operations on a
background thread so as not to block the main thread.

* Q: Explain the correct way to manage Outlets memory
A:
Create them as properties in the header that are retained. In the viewDidUnload set the outlets to nil(i.e self.outlet = nil). Finally in dealloc make sure to release the outlet.

iOS Questions Expert level

* Q: Is the delegate for a CAAnimation retained?
A:
Yes it is!! This is one of the rare exceptions to memory management rules.

* Q: What happens when the following code executes?
 Ball *ball = [[[[Ball alloc] init] autorelease] autorelease];
A:
It will crash because itʼs added twice to the autorelease pool and when it it dequeued the autorelease pool calls release more than once.

* Q: Outline the class hierarchy for a UIButton until NSObject.

A:
UIButton inherits from UIControl, UIControl inherits from UIView, UIView inherits from UIResponder, UIResponder inherits from the root class NSObject

* Q: Explain the difference between NSOperationQueue concurrent and non-concurrent.
A:
In the context of an NSOperation object, which runs in an NSOperationQueue, the terms concurrent and non-concurrent do not necessarily refer to the side-by-side execution of threads. Instead, a non-concurrent operation is one that executes using the environment that is provided for it while a concurrent operation is responsible for setting up its own execution environment.

* Q: Implement your own synthesized methods for the property NSString *title.
A:
Well you would want to implement the getter and setter for the title object. Something like this: view source print?
 - (NSString*) title
{
     return title;
}
- (void) setTitle: (NSString*) newTitle
{
  if (newTitle != title)
  {
     [title release];
    title = [newTitle retain]; // Or copy, depending on your needs.
  }
}
* Q: Implement the following methods: retain, release, autorelease.
A:
-(id)retain
{
    NSIncrementExtraRefCount(self);
    return self;
}

-(void)release
 {
    if(NSDecrementExtraRefCountWasZero(self))
    {
         NSDeallocateObject(self);
    }
}

-(id)autorelease
 {  // Add the object to the autorelease pool
    [NSAutoreleasePool addObject:self];
    return self;
}
*Q: Explain the steps involved in submitting the App to App-Store.
A:
Ref: https://developer.apple.com/appstore/resources/approval/guidelines.html

*Q: What are all  the newly added frameworks iOS 4.3 to iOS 5.0?
A:
    •    • Accounts
    •    • CoreBluetooth
    •    • CoreImage
    •    • GLKit
    •    • GSS
    •    • NewsstandKit
    •    • Twitter

  *Q: What are the App states. Explain them?
A:
    •    Not running State:  The app has not been launched or was running but was terminated by the system.
    •    Inactive state: The app is running in the foreground but is currently not receiving events. (It may be executing other code though.) An app usually stays in this state only briefly as it transitions to a different state. The only time it stays inactive for any period of time is when the user locks the screen or the system prompts the user to respond to some event, such as an incoming phone call or SMS message.
    •    Active state: The app is running in the foreground and is receiving events. This is the normal mode for foreground apps.
    •    Background state:  The app is in the background and executing code. Most apps enter this state briefly on their way to being suspended. However, an app that requests extra execution time may remain in this state for a period of time. In addition, an app being launched directly into the background enters this state instead of the inactive state. For information about how to execute code while in the background, see “Background Execution and Multitasking.”
    •    Suspended state:The app is in the background but is not executing code. The system moves apps to this state automatically and does not notify them before doing so. While suspended, an app remains in memory but does not execute any code. When a low-memory condition occurs, the system may purge suspended apps without notice to make more space for the foreground app.
    •    
*Q:  Explain the options and bars available in xcode 4.2/4.0 workspace window ?
A:

*Q: What is Automatic Reference Counting (ARC) ?
A:
is a compiler-level feature that simplifies the process of managing the lifetimes of Objective-C objects. Instead of you having to remember when to retain or release an object, ARC evaluates the lifetime requirements of your objects and automatically inserts the appropriate method calls at compile time.

*Q: Multitasking support is available from which version?
A:
iOS 4.0
*Q: How many bytes we can send to apple push notification server.
A:
256bytes.

*Q: Can you just explain about memory management in iOS?
A:
Refer: iOS Memory Management

*Q: What is the difference between retain & assign?
A:
Assign creates a reference from one object to another without increasing the source’s retain count.
if (_variable != object) {     [_variable release];     _variable = nil;     _variable = object;   }
Retain creates a reference from one object to another and increases the retain count of the source object.
 if (_variable != object) {     [_variable release];     _variable = nil;     _variable = [object retain];   }

*Q: Why do we need to use @Synthesize?
A:
We can use generated code like nonatomic, atmoic, retain without writing any lines of code. We also have getter and setter methods. To use this, you have 2 other ways: @synthesize or @dynamic: @synthesize, compiler will generate the getter and setter automatically for you, @dynamic: you have to write them yourself.
@property is really good for memory management, for example: retain.
How can you do retain without @property?
  if (_variable != object) {     [_variable release];     _variable = nil;     _variable = [object retain];   } 
How can you use it with @property?
self.variable = object; 
When we are calling the above line, we actually call the setter like [self setVariable:object] and then the generated setter will do its job

*Q: What is categories in iOS?
A:
A Category is a feature of the Objective-C language that enables you to add methods (interface and implementation) to a class without having to make a subclass. There is no runtime difference—within the scope of your program—between the original methods of the class and the methods added by the category. The methods in the category become part of the class type and are inherited by all the class’s subclasses.
As with delegation, categories are not a strict adaptation of the Decorator pattern, fulfilling the intent but taking a different path to implementing that intent. The behavior added by categories is a compile-time artifact, and is not something dynamically acquired. Moreover, categories do not encapsulate an instance of the class being extended.
Refer: Categories and Extensions

*Q: What is Delegation in iOS?
A:
Delegation is a design pattern in which one object sends messages to another object—specified as its delegate—to ask for input or to notify it that an event is occurring. Delegation is often used as an alternative to class inheritance to extend the functionality of reusable objects. For example, before a window changes size, it asks its delegate whether the new size is ok. The delegate replies to the window, telling it that the suggested size is acceptable or suggesting a better size. (For more details on window resizing, see the windowWillResize:toSize: message.)
Delegate methods are typically grouped into a protocol. A protocol is basically just a list of methods. The delegate protocol specifies all the messages an object might send to its delegate. If a class conforms to (or adopts) a protocol, it guarantees that it implements the required methods of a protocol. (Protocols may also include optional methods).
In this application, the application object tells its delegate that the main startup routines have finished by sending it the applicationDidFinishLaunching: message. The delegate is then able to perform additional tasks if it wants.

*Q: How can we achieve singleton pattern in iOS?
A:
The Singleton design pattern ensures a class only has one instance, and provides a global point of access to it. The class keeps track of its sole instance and ensures that no other instance can be created. Singleton classes are appropriate for situations where it makes sense for a single object to provide access to a global resource.
Several Cocoa framework classes are singletons. They include NSFileManager, NSWorkspace, NSApplication, and, in UIKit, UIApplication. A process is limited to one instance of these classes. When a client asks the class for an instance, it gets a shared instance, which is lazily created upon the first request.
Refer: Singleton Pattren

*Q: What is delegate pattern in iOS?
A:
Delegation is a mechanism by which a host object embeds a weak reference (weak in the sense that it’s a simple pointer reference, unretained) to another object—its delegate—and periodically sends messages to the delegate when it requires its input for a task. The host object is generally an “off-the-shelf” framework object (such as an NSWindow or NSXMLParser object) that is seeking to accomplish something, but can only do so in a generic fashion. The delegate, which is almost always an instance of a custom class, acts in coordination with the host object, supplying program-specific behavior at certain points in the task (see Figure 4-3). Thus delegation makes it possible to modify or extend the behavior of another object without the need for subclassing.
Refer: delegate pattern

*Q: What are all the difference between categories and subclasses? Why should we go to subclasses?
A:
Category is a feature of the Objective-C language that enables you to add methods (interface and implementation) to a class without having to make a subclass. There is no runtime difference—within the scope of your program—between the original methods of the class and the methods added by the category. The methods in the category become part of the class type and are inherited by all the class’s subclasses.
As with delegation, categories are not a strict adaptation of the Decorator pattern, fulfilling the intent but taking a different path to implementing that intent. The behavior added by categories is a compile-time artifact, and is not something dynamically acquired. Moreover, categories do not encapsulate an instance of the class being extended.
The Cocoa frameworks define numerous categories, most of them informal protocols . Often they use categories to group related methods. You may implement categories in your code to extend classes without subclassing or to group related methods. However, you should be aware of these caveats:
    •    You cannot add instance variables to the class.
    •    If you override existing methods of the class, your application may behave unpredictably.

*Q: What is notification in iOS?
A:
The notification mechanism of Cocoa implements one-to-many broadcast of messages based on the Observer pattern. Objects in a program add themselves or other objects to a list of observers of one or more notifications, each of which is identified by a global string (the notification name). The object that wants to notify other objects—the observed object—creates a notification object and posts it to a notification center. The notification center determines the observers of a particular notification and sends the notification to them via a message. The methods invoked by the notification message must conform to a certain single-parameter signature. The parameter of the method is the notification object, which contains the notification name, the observed object, and a dictionary containing any supplemental information.
Posting a notification is a synchronous procedure. The posting object doesn’t regain control until the notification center has broadcast the notification to all observers. For asynchronous behavior, you can put the notification in a notification queue; control returns immediately to the posting object and the notification center broadcasts the notification when it reaches the top of the queue.
Regular notifications—that is, those broadcast by the notification center—are intraprocess only. If you want to broadcast notifications to other processes, you can use the istributed notification center and its related API.

*Q: What is the difference between delegates and notifications?
A:
We can use notifications for a variety of reasons. For example, you could broadcast a notification to change how user-interface elements display information based on a certain event elsewhere in the program. Or you could use notifications as a way to ensure that objects in a document save their state before the document window is closed. The general purpose of notifications is to inform other objects of program events so they can respond appropriately.
But objects receiving notifications can react only after the event has occurred. This is a significant difference from delegation. The delegate is given a chance to reject or modify the operation proposed by the delegating object. Observing objects, on the other hand, cannot directly affect an impending operation.

*Q: What is push notification?How it works?
A:

*Q: What is the configuration file name in iOS explain in brief ? (Or) What is plist file and explain about it is usage?
A:

*Q: What is atomic and nonatomic? Which one is safer? Which one is default?
A:

*Q: When will be the autorelease object released?
A:

*Q: What is the difference between copy & retain? When can we go for copy and when can we go for retain?
A:

*Q: Consider we are implementing our own thread with lot of autoreleased object. Is it mandatory to use autorelease pool on this scenario if yes/no why?
A:

*Q:  Have you ever used automated unit test framework in iOS? Explain in short?
A:
*Q: What are all the difference between iOS3, iOS4 and iOS5?
A:

*Q: What is posing in iOS?
A:

*Q: Is there any garbage collector concept available in iOS?
A:

*Q: What is difference between synchronous and asynchronous in web request?
A:

*Q: What are all the instruments available in Xcode?
A:

-----------------------------------------------------------------------------------------------------------------------------

1.What is the RAM size in iPhone 4?
512MB

2.Current device resolution?
   320X480 for iPhone
1024X720 for iPad

3.what compiler we have used in Objective c?

Compiler for objective c GCC version 4.0


4.SDK:
      
     SDK means software development kit. It contains Xcode IDE,instruments, iPhone simulator,Interface Builder,Frameworks…

5.What are SDK tools in iPhone?
XCode
IB
Simulator
Instruments


6.What is Xcode?
Xcode is an Intigrated Development Environment IDE
it acts like an Editor of Objective c loang
We can write,run,build our code in xcode


7.What is the simulator?

it is a demo to check our applications if we didn't have the original device



8.what are Instruments:

               The instrument enables you to dynamically trace and profile the performance of the Macos,iPhone, iPad applications.
Bu using Instruments we can test the performance of the application.


9.what is Interface Builder:

                  Interface builder is developed in 1988.It is a visual tool that allows you to design your interfaces for iphone.By using interface builder we can drag and drop the views on interface.


10.Explain about Inspector

      It is mainly used for setting the properties of view elements. It contains four sections.
1)Attribute inspector 
2)Connection  
3)Size of inspector   
4)Identity


11.Groups and File sections:

 Classes:
         In class folder actual coding will be their.
for window based application we have two files.

1)appdelegate.h   
2)appdelegate.m
                 

For view based applications we have four files.
1)appdelegate.h  
2)appdelegate.m                          
3)viewcontrol.h    
4)viewcontrol.m


12.what are different Layers of iOS
Cocoa Touch Layer
Media Layer
Core Services Layer
Core Services Layer


13.What is optimization?
Optimaisation is nothing but
Making our application more attractively even after complition of the coding


14.What happend if array release?
As such, when the NSArray is released your object will still have a retain count of one and will therefore still be around after the autorelease pool is emptied. (Until of course you release it.


15.How can we use multiple class inheritance in objective c?
In Objective c Multiple inheritance is not supported
for this porpous we use "categories" in Objective c


16.How can u use object for abstract class?
(or) What is Shared Obj?
We  can't create object for abstract class
to call abstract class we use Shared obj


17.Garbage collection:

         Garbage collection means a memory management system that automatically release memory used by unreferenced variable.

Modern computer langs uses Garbage collection [GC]
Gc is a runtime algorithm that scans the allocated objects in our prog
and deallocates the obj that we have loss contact

    cocoa under the iphone os does not use GC so cocoa apps must use managed memory

applications running on this platform sh'd b clean up after use.
since iphone apps run in a memory constraint environment  



18.Retain:
It indicates that we can putting the Ownership climb on the object

it increases the Retain count by 1
if the caller releases the object it doesn't deallocated if it is retained

19.Release:

it decreases the retain count by 1
when we call release we r no longer the owner of the obj

if the the reference count is 0
    the object will b Deallocated

The memory is freed it will be used by another obj

20.AUTORELEASEPOOL:
    all the released objects are added to 
the Pool, that pool is nothing but AutoReleasePool

the pool objects are released by keywords release/Drain


21.What is the difference between the dot notation and using the square brackets?
The Dot Syntax only for Setter & Getters
button for the Methods


22.reference counting. 
Objective-C's memory management system is called reference counting. 

23.How can we deallocates all objects in AutoReleasepool?
difference b/n Drain & Release..?

By Using DRAIN keyword we can deallocate all objects from autoReleasePool

By using Release We can't Deallocate all the objects 


24.memory management:
Dealloc
 The dealloc method is called on an object when it is being removed from memory. This is usually the best time to release references to all of your child instance variables:
 - (void) dealloc
{
    [caption release];
    [photographer release];
    [super dealloc];
}
On the first two lines, we just send release to each of the instance variables. We don't need to use autorelease here, and the standard release is a bit faster. 

memory leak.

The last line is very important. We have to send the message
[super dealloc] to ask the superclass to do its cleanup. If we don't do this, the object will not be removed, which is a memory leak. 

reference counting. 
Objective-C's memory management system is called reference counting. 
All you have to do is keep track of your references, and the runtime does the actual freeing of memory. 

In simplest terms, you alloc an object, maybe retain it at some point, then send one release for each alloc/retain you sent. So if you used alloc once and then retain once, you need to release twice.

you create an object with alloc or copy, send it a release or autorelease message at the end of the function. If you create an object any other way, do nothing. 



Dealloc
        it is called when the viewcontroller object is deallocated, which it will be when the retain count drops to zero.

25.What is Framework?

Collection of classes is nothing but a Frame Work
    Frame work is a library.It contains all collection of predefined classes,functions,protocols....




26.What is Protocol?

      A protocol is a collection of methods that any class can choose to implement. This can be useful when you are creating family of similar classes that all need to communicate with a common control class.

27.What is Category?
            A category is a way of adding new methods to the all instances of existing class with out modifying the class.The use of category is extending the NSString class to add functionality.

28.What is Property:

       By using property what ever the data are stored in array,string,… that values are used in any where in that program.Property contains the data and synthesize retrieve the data.

29.what are the property declarations/attributes?
atomic,
nonatomic, 
readonly,
retain, 
copy.


30.What are the types of accessory methods?
we have 2 types of ac…. methods:

i.Getter method:
    Getter method is an accessor method that retrieves the value of an instance variable.

ii.Setter method:
    Setter method is an accessor method that Sets the value of an instance variable.

31.what is a Selector?
        Selector can either be a name of method Or message to an object. 


32.What is Delegate?
    it is an object that usually read to some events in another object
    
       A Delegate allows one object to send messages to another object when an Event happens.
       An object directly to carryout an action by another object.

33.What is an App Delegate..?
it is necessary in any app.
it is a controller which takes care critical events
while Starting Running and Editing applications

34.iPhone Paths:

   iPhone contains two paths.

    1.Resource path:
                                       
             By using this path we can retrieve the data from resource path.But we can not add the data.

    2.Modify path

          By using this path we can add,modify,delete,retrieve the data.


35.Accelerometer:
    

                      The accelerometer allows the device to detect the orientation of the device and adapts the content to suit the new orientation.



36.Header file:
    
    Header files are preprocessor directories.
         in Obj c By using #include,#import we can import the header files.


37.Diff between self and super:

Self:
     self is a variable that refers to the object of present class.

Super:
    Super referes to the same variable.


38.Resources:

                  In resources we can add the outside contents like images,videos,audio files.
                  It contains info.plist file.plist file having entire project information.

39.Products:

              The final output present in product folder and extension is .app
              Intiallu .app is in red color.once if you can build the  app then the .app is created.

40.Files owner window:

           It contains copy of nib files.
           It is always 1st icon in any .nib file.


41.What Enum?

          It is a user defined data type.it improves speed of execution.
         By default it assigns range from 0,1……


42.Forward declarations:

        @class,@protocals these are forward declarations to avoid cyclic dependencies.

@class:
        This directive to make a forward reference to another class and improve the .h file.

@protocals:
        These are two types. 
1)Formal protocol  2)Informal protocol

 Formal protocal:
    It is a set of methods that must be implemented in any conformic class.

Informal protocal:
    In informal protocol developer group methods by app fields.


43.Foundation framework
    It provides foundation classes for objective-c. 
such as NSobject,basic data types.

44.UIKit framework:
    It provides fundamental objects for managing the UI applications.

45.core location framework:
      It provides location based information using combination of GPS,cell ID,hi-fi networks.


46.Mapkit framework:
    It provides an Embedded map interface for your application.

47.Media player framework:
    It provides facilities for playing audio and video files.

48.core graphics framework:
        It provides c-based APIS for 2d rendering based on quartz drawing engine.

49.AVFoundation framework:
        It provides low level c APIS for audio recording and playback as well as managing audio hardware.
50.Interface:
     In interface section that declares the methods and instance variables of class.

51.Implementation:
     In implementation section that actuvally defines the class.


52.What kind of design pattern we are using?
    We are using model view controller

 Model:
         This layer manipulates the coding part of the application.

 View:
         This layer manipulates the design part of the application.

Controller:
        This layer acts as bridge between model and view controller.

53.What is Id?
        It is a datatype.
   Id is a generic c-type used by obj-c to reffer to any object.
   

54.NSFile manager:

                        By using NSfile manager we can compare,add,delete and update the data in database.
                    
SQLite

55.SQLIte
    It is one of the database to store the large number of data.
KeySQLite methods:
1)SQLite3_open():
        This function opens specific database file.if the database file does not already exists it is created.

2)SQLite3_close():
        This function closes if previously opened database file.

3)SQLite3_prepare_v2():
        This function prepares a SQL statement ready for execution.

4)SQLite3_step():    
        This function executes a SQL statement previously prepared by using sqlite_prepare_v2.

5)SQLite_column_<type>():
        This function returns a datafield from the results of a SQL retrieval operation. where <type> is replaced by datatype of the data to be extractes.        

6)SQLite3_finalize():
        This function deletes a previously prepared SQL statement from memory.

7)SQLite3_exec():
This function combines the functionality of  SQLite3_prepare_v2(), SQLite3_step(),SQLite3_finalize(). into a single function call.

56.NSBundle mainbundle:

     It is used to pick the data from resources.

57.UI application:

     Every iPhone has UI application.it is the starting point of the every application.
     It is responsible for initializing and display your application on UI Window and also responsible for loading your application.

58.Controllers in iPhone:

      By using controllers we can move from one view to another view.
ex:    pushviewcontroller, 
    popviewcontroller, 
    presentmodelviewcontroller,
    Dismissmodelviewcontroller.

59.How can we deploy our app?
By using standard edition worths 99$ we we can deploy our app

60.How can we Localize our app?
or localization have to use current language
For exam to make a delete button
in English: Delete
in Japannish lan: Aurem
in spanish: Delat

in this way we can localize our app

61.Why We use Authentication?
for the security purpose we use authentication

62.When keyboard appears, hides some part of UI for that what shall we do?

     keyboard will appear only in some views like "Textfield","Textviews" etc
but not in all the views

for display the keyboard we have to use "becomeFirstResponder"..
for hides the keyboard we have to use "resignFirstResponder"
ex:
[textField becomeFirstResponder];
[textField resignFirstResponder];




63.becomeFirstResponder?
   For display the keyboard we have to use "becomeFirstResponder"..
ex:[textField becomeFirstResponder];

64.What is awakeFromNib, becomeFirstResponder?
        Activity should be allocated from loading xib file, it should be not nil in awakeFromNib
And awakeFromNib is called when all file owners outlets and properties are set (including view property). 
So it makes sense that viewDidLoad is called earlier than awakeFromNib.

65.What is Context?
           Context refers to the conditions in which something exists or occurs.

one is connected with databases, persistence layers, graphics and such beasts 
where you need some notion of a ‘scope’, ‘connection’ or a ‘state’. 
For example when saving data into a database 
you usually need to open the database and then save some DB ‘handle’
 you will refer to in subsequent operations.
 There can be many different connections and thus many different ‘handles’. 
In other words there can be many DB contexts



66.Difference Between nil & NiL
both nil, Nil return a NULL pointer (Zero pointer)

but
nil is specific to objects (e.g., id)
and Nil is specific to class pointers.

X [for the NULL pointers in Objective c We have to use :nil

in the same way
for the NULL pointers in C,C++ We have to use :NiL
NiL is just like NULL]


67.what happens when we invoke a method on a nil pointer

It returns 0, nil, a structure filled with 0s,

68.Multiple class inheritance in objective c?
   In Objective c Multiple inheritance is not supported
for this purpose we use "categories" in Objective c

Categories: A category allows you to add methods to an existing class… Categories are a powerful feature that allows you to extend the functionality of existing classes without subclassing.
The declaration of a category interface looks very much like a class interface declaration
      Except the category name is listed within parentheses after the class name and the superclass isn’t mentioned. 
      Unless its methods don’t access any instance variables of the class, 
      The category must import the interface file for the class it extends:
#import "ClassName.h"



@interface ClassName ( CategoryName )

//  method declarations

@end





Extensions:
Class extensions are like anonymous categories,
except that the methods they declare must be implemented in the
main @implementation block for the corresponding class.

extensions allow you to declare additional required methods for a class
 in locations other than within the primary class @interface block, 
as illustrated in the following example:
@interface MyObject : NSObject

{

    NSNumber *number;

}

- (NSNumber *)number;

@end



@interface MyObject ()

- (void)setNumber:(NSNumber *)newNumber;

@end





@implementation MyObject



- (NSNumber *)number {

    return number;

}

- (void)setNumber:(NSNumber *)newNumber {

    number = newNumber;

}


69.What is Pushnotifications?
  [Push Notoification is Receiving the Message or applications with out interaction of the user from the server...
       since server[sender] and receiver are not in simultaneous process.. it is an asynchronous process ]

       Rather than having your device check to see if there are any new items at set intervals, 
the central host of updates will phone you when you have updates. This is the "push" described. 
When you've got something new, they tell you. You no longer need to "ask" for it. 
       This benefits you in many ways, including the obvious saving of battery life and bandwidth usage.


       Apple's just announced a push notification service for the iPhone that it'll provide to all developers.
 It'll maintain a persistent IP connection to the phone and let a 3rd party server ping Apple's notification service 
in order to push out notifications your device, which can be in the form of badges, sounds or custom textual alerts. According to Apple, the service will preserve battery life and maintain performance, 
not to mention work over WiFi or cellular
70.Web services:
  "Web service" as "a software system designed to support interoperable machine-to-machine interaction over a network
Web services are typically application programming interfaces (API) or web APIs that are accessed via                         Hypertext Transfer Protocol and executed on a remote system hosting the requested services


Web Services delegate Methods
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error



71.Parsers:

----------
SAX vs. DOM

 Before we begin, I wanted to make sure everyone is aware of the most important difference between XML parsers:
whether the parser is a SAX or a DOM parser.

    * A SAX parser is one where your code is notified as the parser walks through the XML tree,
      and you are responsible for keeping track of state and constructing any objects you might want to keep track of the data as the parser marches through.

    * A  DOM parser reads the entire document and builds up an in-memory representation that you can query for different elements. 
      Often, you can even construct XPath queries to pull out particular pieces.


72.What is XML parsing?
xml parsing is the trancfer of data from xml page to our application
the data which is in term of elements
73.The Most Popular XML Parsers for the iPhone

In my research, here ís what seemed to me to be the most popular XML Parsers for the iPhone, and a brief description of each one:

    * NSXMLParser is a SAX parser included by default with the iPhone SDK. Itís written in Objective-C and is quite straightforward to use,
     but perhaps not quite as easy as the DOM model.

    * libxml2 is an Open Source library that is included by default with the iPhone SDK.
      It is a C-based API, so is a bit more work to use than NSXML. The library supports both DOM and SAX processing.
      The libxml2 SAX processor is especially cool, as it has a unique feature of being able to parse the data as itís being read. 
      For example, you could be reading a large XML document from the network and displaying data that youíre reading for it to the user while youíre still downloading.
    
    * TBXML is a lightweight DOM XML parser designed to be as quick as possible while consuming few memory resources.
     It saves time by not performing validation, not supporting XPath, and by being read-only ñ
     i.e. you can read XML with it, but you canít then modify the XML and write it back out again.

    
* TouchXML is an NSXML style DOM XML parser for the iPhone. Like TBXML, it is also read-only, but unlike TBXML it does support XPath.
   
    * KissXML is another NSSXML style DOM XML parser for the iPhone, actually based on TouchXML. 
       The main difference is KissXML also supports editing and writing XML as well as reading.


    * TinyXML is a small C-based DOM XML parser that consists of just four C files and two headers.
      It supports both reading and writing XML documents, but it does not support XPath on its own. However, you can use a related library ñ TinyXPath ñ for that.
   
    * GDataXML is yet another NSXML style DOM XML parser for the iPhone, developed by Google as part of their Objective-C client library.
      Consisting of just a M file and a header, it supports both reading and writing XML documents and XPath queries.

Ok, now lets start comparing all these libraries!


74.What r the Delegate Methods for XML Parsing?
There are mainly 3Types of Delegate methods for XML Parsing
 i. did start element 
ii. did end element
iii. found characters


75.What is Picker view..?
Picker view lets the user select an item from a list.

76.What is Table view?
It is commonly used to show list of data in the form of Records

77.WEb Services?
Web services are application programing interfaces [API]
or Web API's that are acecced via Hyper Text protocol and excited on a remote system
hosting the requested services

78.Difference between HTML & XML?
XML was designed to transfer and store the data
XML was to carry data not to display the data
XML is designed to be self description

HTML was designed to Display the data


79.Core DATA:
The ways to persist data on the iPhone, 
Core Data is the best one to use for non-trivial data storage.
It can reduce the memory overhead of your app,
 increase responsiveness, and save you from writing a lot of boilerplate code.

Apple has finally ported Core Data to the iPhone which means using SQLite in an application

80.FILE SHARING:
The Data in Plists is existed in the form of Files..
Retrive these file from plist to out application
is nothing but a File Sharing


81.Threads:
Threads are one of several technologies that make it possible to execute multiple code paths concurrently inside a single application.

82.iPhone SDK tools:
Xcode
Interface Builder
iphone/iPad Simulator
Instrument
83.Shallow copy , Deep Copy:
Shallow copies duplicate as little as possible. 
A shallow copy of a collection is a copy of the collection structure, not the elements.
With a shallow copy, two collections now share the individual elements.

Deep copies duplicate everything. A deep copy of a collection is two collections with all of the elements in the original collection duplicated.
Shallow copy: Copies the member values from one object into another.
Deep Copy:    Copies the member values from one object into another.
                     Any pointer objects are duplicated and Deep Copied.

84.what happens if you remove the object from the array, and you try to use it?
our application crashes


85.Diff b/w viewWillAppear & viewDidLoad

viewWillAPpear is called each time the view becomes visible.

    viewDidLoad is only called when the view is initialized.

    viewDidLoad being called once when the view is loaded (actually it may be called more than once if it was released and  created again)
    ViewWillAppear is called each time the view is going to appear (so put state updates here)

     viewDidLoad is things you have to do once. viewWillAppear gets called every time the view appears.
     You should do things that you only have to do once in viewDidLoad - like setting your UILabel texts. However, you may want to        
      modify a specific part of the view   every time the user gets to view it, e.g. the iPod application scrolls the lyrics back to
      the top every time you go to the "Now Playing" view.


86.When didReceiveMemory  gets called
     it is called when the system is low on memory.
    didReceiveMemoryWarning will be called before an out-of-memory crash. Not other crashes. 
        If you handle the warning properly and free up memory, then you can avoid the out-of-memory condition and not crash.
    
The purpose of didReceiveMemoryWarning is to give you a chance to free memory or pop views to avoid a crash.

    You can manually trigger a memory warning in the simulator under the Hardware menu. Highly recommend doing this
         to flush out problems.
    Instruments helps you debug leaks (though not all of them) - it's not really that useful for crashes.



87.KVC
Objects have certain "properties". For example, a Person object may have an name property
 and an address property. 
In KVC parlance, the Person object has a value for the name key, and for the address key. 

"Keys" are just strings, and "values" can be any type of object
 At it’s most fundamental level, 

KVC is just two methods: 
mutator:a method to change the value for a given key
accessor:a method to retrieve the value for a given key
 Here is an example:
void ChangeName(Person* p, NSString* newName)
{
    //using the KVC accessor (getter) method
    NSString* originalName = [p valueForKey:@"name"];

    //using the KVC mutator (setter) method.
    [p setValue:newName forKey:@"name"];

    NSLog(@"Changed %@'s name to: %@", originalName, newName);
}
Now let’s say the Person object has a third key: a spouse key. The value for the spouse key is another Person object. KVC allows you to do things like this:
void LogMarriage(Person* p)
{
    //just using the accessor again, same as example above
    NSString* personsName = [p valueForKey:@"name"];

    //this line is different, because it is using
    //a "key path" instead of a normal "key"
    NSString* spousesName = [p valueForKeyPath:@"spouse.name"];

    NSLog(@"%@ is happily married to %@", personsName, spousesName);
}
Cocoa makes a distinction between "keys" and "key paths". 
A "key" allows you to get a value on an object. 
A "key path" allows you to chain multiple keys together, separated by dots. For example, this…
[p valueForKeyPath:@"spouse.name"];
… is exactly the same as this…
[[p valueForKey:@"spouse"] valueForKey:@"name"];
That’s all you need to know about KVC for now.
Let’s move on to KVO.
88.Key-Value Observing (KVO)
Key-Value Observing (KVO) is built on top of KVC. It allows you to observe (i.e. watch)
 a KVC key path on an object to see when the value changes.
 For example, let’s write some code that watches to see if a person’s address changes. 

There are three methods of interest in the following code:
•    •    watchPersonForChangeOfAddress: begins the observing
•    •    observeValueForKeyPath:ofObject:change:context: is called every time there is a change in the value of the observed key path
•    •    dealloc: stops the observing
static NSString* const KVO_CONTEXT_ADDRESS_CHANGED = @"KVO_CONTEXT_ADDRESS_CHANGED"

@implementation PersonWatcher 

-(void) watchPersonForChangeOfAddress:(Person*)p;
{
    //this begins the observing
    [p addObserver:self 
        forKeyPath:@"address" 
           options:0 
           context:KVO_CONTEXT_ADDRESS_CHANGED];

    //keep a record of all the people being observed,
    //because we need to stop observing them in dealloc
    [m_observedPeople addObject:p];
}

//whenever an observed key path changes, this method will be called
- (void)observeValueForKeyPath:(NSString *)keyPath 
                      ofObject:(id)object 
                        change:(NSDictionary *)change 
                       context:(void *)context;
{
    //use the context to make sure this is a change in the address,
    //because we may also be observing other things 
    if(context == KVO_CONTEXT_ADDRESS_CHANGED){
        NSString* name = [object valueForKey:@"name"];
        NSString* address = [object valueForKey:@"address"];
        NSLog(@"%@ has a new address: %@", name, address);
    }    
}

-(void) dealloc;
{
    //must stop observing everything before this object is
    //deallocated, otherwise it will cause crashes
    for(Person* p in m_observedPeople){
        [p removeObserver:self forKeyPath:@"address"];
    }
    [m_observedPeople release]; m_observedPeople = nil;
    [super dealloc];
}

-(id) init;
{
    if(self = [super init]){
        m_observedPeople = [NSMutableArray new];
    }
    return self;
}

@end
This is all that KVO does. It allows you to observe a key path on an object to get notified whenever the value changes.

89.Cocoa Bindings
Now that you understand the concepts behind KVC and KVO, Cocoa bindings won’t be too mysterious.
Cocoa bindings allow you to synchronise two key paths. so they have the same value. When one key path is updated, so is the other one.
For example, let’s say you have a Person object and an NSTextField to edit the person’s address. We know that every Person object has an address key, and thanks to the Cocoa Bindings Reference, we also know that every NSTextField object has a value key that works with bindings. What we want is for those two key paths to be synchronised (i.e. bound). This means that if the user types in the NSTextField, it automatically updates the address on the Person object. Also, if we programmatically change the the address of the Person object, we want it to automatically appear in the NSTextField. This can be achieved like so:
void BindTextFieldToPersonsAddress(NSTextField* tf, Person* p)
{
    //This synchronises/binds these two together:
    //The `value` key on the object `tf`
    //The `address` key on the object `p`
    [tf bind:@"value" toObject:p withKeyPath:@"address" options:nil];
}


What happens under the hood is that the NSTextField starts observing the address key on the Person object via KVO. 
If the address changes on the Person object, the NSTextField gets notified of this change, and it will update itself with the new value. In this situation, the NSTextField does something similar to this:
- (void)observeValueForKeyPath:(NSString *)keyPath 
                      ofObject:(id)object 
                        change:(NSDictionary *)change 
                       context:(void *)context;
{
    if(context == KVO_CONTEXT_VALUE_BINDING_CHANGED){
        [self setStringValue:[object valueForKeyPath:keyPath]];
    }    
}
When the user starts typing into the NSTextField, the NSTextField uses KVC to update the Person object. In this situation, the NSTextField does something similar to this:
- (void)insertText:(id)aString;
{
    NSString* newValue = [[self stringValue] stringByAppendingString:aString];
    [self setStringValue:newValue];

    //if "value" is bound, then propagate the change to the bound object
    if([self infoForBinding:@"value"]){
        id boundObj = ...; //omitted for brevity
        NSString* boundKeyPath = ...; //omitted for brevity
        [boundObj setValue:newValue forKeyPath:boundKeyPath];
    }
}
For a more complete look at how views propagate changes back to the bound object, see my article: Implementing Your Own Cocoa Bindings.
90.What is the difference between KVO & KVC
     The views use KVC to update the model, 
and they use KVO to watch for changes in the model.


91.What is an abstract class? 

    A class that’s defined solely so that other classes can inherit from it. Programs don’t use instances of an abstract class, only of its sub classes


92.what is Application Kit    ?
        A Cocoa framework that implements an application's user interface. The Application Kit provides a basic program structure for applications that draw on the screen and respond to events.


93.what is asynchronous message?
         A remote message that returns immediately, without waiting for the application that receives the message to respond. The sending application and the receiving application act independently, and are therefore not “in sync.



94.What is synchronous message?
         A remote message that doesn’t return until the receiving application finishes responding to the message. Because the application that sends the message waits for an acknowledgment or return information from the receiving application, the two applications are kept “in sync.” 

95.delegate 
    An object that acts on behalf of another object.







96.Class
        In the Objective-C language, a prototype for a particular kind of object. 
A class definition declares instance variables and defines methods for all members of the class. 
Objects that have the same types of instance variables and have access to the same methods belong to the same class.



97.object    
        A programming unit that groups together a data structure (instance variables) and the operations (methods) that can use or affect that data. Objects are the principal building blocks of object-oriented programs.

98.Class method
        In the Objective-C language, a method that can operate on class objects rather than instances of the class.

99.class object    
        In the Objective-C language, an object that represents a class and knows how to create new instances of the class is called class object.

100.what are distributed objects?
         Architecture that facilitates communication between objects in different address spaces.
101what is dynamic allocation? 
        Technique used in C-based languages where the operating system provides memory to a running application as it needs it, instead of when it launches.

102.what is dynamic binding ?
        Binding a method to a message—that is, finding the method implementation to invoke in response to the message—at runtime, rather than at compile time.


103.what is encapsulation 
    Programming techniquethathides the implementation of an operation from its users behind an abstract interface. This allows the implementation to be updated or changed without impacting the users of the interface.

104.Cocoa 
    An advanced object-orientedd evelopment platform on Mac OS X. Cocoa is a set of frameworks with its primary programming interfaces in Objective-C.


105.Formal protocol vs inFormal protocols
    Formal protocols are the protocols
these are two type
@optional
@required

InFormal protocols are Categories defined on NSObject
106.How formal protocol declares?
    In the Objective-C language, a protocol that’s declared with the @protocol directive.

107.How to informal protocol declares?
    informal protocol declares with keyword @interface
@interface NSObject(NSApplicationNotifications)
- (void)applicationWillFinishLaunching:(NSNotification *)notification

108.Implementation    
        Part of an Objective-C class specification that defines its implementation. 
This section defines both public methods as well as private methods-methods that are not declared in the class’s interface.

109.Interface
        that declares its public interface, which include its superclass name, instances variables, and public-method prototypes.


110.Instance    
        In the Objective-C language, an object that belongs to (is a member of) a particular class.




111.message    
        In object-oriented programming, the method selector (name) and accompanying arguments that tell the receiving object in a message expression what to do.

112.method 
        In object-oriented programming,a procedure that can be executed by an object.

113.what is multiple inheritance does objective c supports for it?

        In object-oriented programming, the ability of a class to have more than one superclass—to inherit from different sources and thus combine separately-defined behaviors in a single class. Objective-C doesn’t support multiple inheritance.

114.What is nil?
        In the Objective-C language, an object id with a value of 0.

115.isKindOfClass vs IsMemberOfClass:
        isKindOfClass is tells that wether a class is inherited from the class or not
isMemberOfClass is tells that wether an obj is instance of that class or not
isKindofClass:it will tells us whether it is a class r nor
isMemberofClass:it tells us whether it is a member of that class r not...both returns bool values YES/NO
 Objective-C Compiler Commands

(A) What's the file suffix for Objective-C source ?
It's .m for implementation files, and .h for header files. Objective-C compilers 
usually also accept .c as a suffix, but compile those files in plain C mode.

(B) How do I compile .m files with the Stepstone compiler ?

objcc -c class.m
objcc -o class class.o
See http://www.stepstn.com for more information.

(C)How do I compile .m files with the Apple compiler ?

cc -c class.m
cc -o class class.o
See http://www.apple.com for more information.
(D) How do I compile .m files with the GNU C compiler ?
gcc -c class.m
gcc -o class class.o -lobjc -lpthread
See http://www.gnu.org for more information.
(E) How do I compile .m files with the POC ?
objc -c class.m
objc -o class class.o
See http://metalab.unc.edu/pub/Linux/devel/lang/objc/ for more information.

(F) Objective-C preprocessor issues


(G) What's the syntax for comments ?
The Objective-C preprocessor usually supports two styles of comments :
// this is a BCPL-style comment (extends to end of line)
and
/* this is a C-style comment */ 9for multiple lines0


(H) How do I include the root class ?
On Stepstone and the POC, the header file to include is :
<Object.h>
On GNU cc and Apple cc, it's :
<objc/Object.h>
The root class is located in a directory called runtime for the Stepstone compiler, and in a directory called objcrt for the POC, but because of implicit -I options passed on to the preprocessor, these locations are automatically searched.
(I) What is #import ?
It's a C preprocessor construct to avoid multiple inclusions of the same file.
#import <Object.h>
is an alternative to

#include <Object.h>
where the .h file is protected itself against multiple inclusions :
#ifndef _OBJECT_H_
...
#define _OBJECT_H_
#endif

116.Why am I lectured about using #import ?
The GNU Objective-C compiler emits a warning when you use #import because some people find using #import poor style. You can turn off the warning by using the -Wno-import option, you could modify the compiler source code and set the variable warn_import (in the file cccp.c) or you could convert your code to use pairs of #ifndef and #endif, as shown above, which makes your code work with all compilers.
117. What is id ?
It's a generic C type that Objective-C uses for an arbitrary object. For example, a static function that takes one object as argument and returns an object, could be declared as :
static id myfunction(id argument) { ... }
118. What is @defs() ?
It's a compiler directive to get access to the internal memory layout of instances of a particular class.

typedef struct { @defs(MyClass) } *TMyClass;
defines a C-type TMyClass with a memory layout that is the same as that of MyClass instances.


119.What is the difference between self , super ?
self is a variable that refers to the object that received a message in a method implementation. super refers to the same variable, but directs the compiler to use a method implementation from the superclass.
Using pseudo-code, where copy (from super) is the syntax for the copy implementation of the superclass, the following are equivalent :
myObject = [super copy];
and,
myObject = [self copy (from super)]; // pseudo-code









 Message selectors (SEL)

120.What is a SEL ?
It's the C type of a message selector; it's often defined as a (uniqued) string of characters (the name of the method, including colons), but not all compilers define the type as such.
121. What is perform: doing ?
perform: is a message to send a message, identified by its message selector (SEL), to an object.
122. How do I know the SEL of a given method ?
If the name of the method is known at compile time, use @selector :
[myObject perform:@selector(close)];
At runtime, you can lookup the selector by a runtime function that takes the name of the message as argument, as in :
SEL mySel = selUid(name); // for Stepstone
SEL mySel = sel_getUid(name); // for Apple
SEL mySel = sel_get_any_uid(name); // for GNU Objective C
SEL mySel = selUid(name); // for POC

Implementation pointers (IMP)
123.What is an IMP ?
It's the C type of a method implementation pointer, a function pointer to the function that implements an Objective-C method. It is defined to return id and takes two hidden arguments, self and _cmd :
typedef id (*IMP)(id self,SEL _cmd,...);
124. How do I get an IMP given a SEL ?
This can be done by sending a methodFor: message :
IMP myImp = [myObject methodFor:mySel];
125. How do I send a message given an IMP ?
By dereferencing the function pointer. The following are all equivalent :
[myObject myMessage];
or
IMP myImp = [myObject methodFor:@selector(myMessage)];
myImp(myObject,@selector(myMessage));
or
[myObject perform:@selector(myMessage)];



126. How can I use IMP for methods returning double ?
For methods that return a C type such as double instead of id, the IMP function pointer is casted from pointer to a function returning id to pointer to a function returning double :
double aDouble = ((double (*) (id,SEL))myImp)(self,_cmd);

127. Can I use perform: for a message returning double ?
No. The method perform: is for sending messages returning id without any other argument. Use perform:with: if the message returns id and takes one argument. Use methodFor: for the general case of any number of arguments and any return type.
128. What's the difference between copy and deepCopy ?
copy is intented to make a bytecopy of the object, sharing pointers with the original, and can be overridden to copy additional memory. deepCopy is intented to make a copy that doesn't share pointers with the original. A deep copy of an object contains copies of its instance variables, while a plain copy is normally just a copy at the first level.
129. How can I link a C++ library into an Objective-C program ?
You have two options : either use the Apple compiler or use the POC. The former accepts a mix of C++ and Objective-C syntax (called Objective-C++), the latter compiles Objective-C into C and then compiles the intermediate code with a C++ compiler. See the compiler specific questions for more information.
130. How do I make a static method ?
Methods are always implemented in Objective-C as static functions. The only way to obtain the IMP (implementation pointer) of a method is through the runtime (via methodFor: and friends), because the function itself is static to the file that implements the method.
131. How do I prevent an object from sending a given message ?
You can't. If your object responds to a message, any other class can send this message. You could add an extra argument sender and check, as in :
- mymethod:sender
{
  if ([sender isKindOf:..]) ...
}
But this still requires cooperation of the sender, to use a correct argument :          [anObject mymethod:self];

132. Do I have to recompile everything if I change the implementation of a method ?
No, you only have to recompile the implementation of the method itself. Files that only send that particular messages do not have to be recompiled because Objective-C has dynamic binding.
133. Do I have to recompile everything if I change instance variables of a class ?
You have to recompile that class, all of its subclasses, and those files that use @defs() or use direct access to the instance variables of that class. In short, using @defs() to access instance variables, or accessing instance variables through subclassing, breaks the encapsulation that the Objective-C runtime normally provides for all other files (the files that you do not have to recompile).
134. Objective-C and X-Windows





135. How do I include X Intrinsics headers into an Objective-C file ?
To avoid a conflict between Objective-C's Object and the X11/Object, do the following :

#include <Object.h>
#define Object XtObject
#include <X11/Intrinsic.h>
#include <X11/IntrinsicP.h>
#undef Object
135. How do I allocate an object on the stack ?
To allocate an instance of 'MyClass' on the stack :
MyClass aClass = [MyClass new];








GNU Objective-C Specific Questions

137. Why do I get a 'floating point exception' ?
This used to happen on some platforms and is described at ftp://ftp.ics.ele.tue.nl/pub/users/tiggr/objc/README.387. A solution was to add -lieee to the command line, so that an invalid floating point operation in the runtime did not send a signal. DJGPP users can consult http://www.delorie.com/djgpp/v2faq/. AIX users may want to consult http://world.std.com/~gsk/oc-rs6000-problems.html. In some cases, you can fix the problem by upgrading to a more recent version of the GNU Objective-C runtime and/or compiler.
138. What's the class of a constant string ?
It's an NXConstantString.
NXConstantString *myString = @"my string";

139. How can I link a C++ library into an Objective-C program ?
c++ -c file.m
c++ file.o -lcpluslib -o myprogram

140. What's the syntax for class variables ?
List the class variables after the instance variables, and group them together in the same way as instance variables, as follows :

@implementation MyClass : Object { id ivar1; int ivar2; } : { id cvar1; }
@end

141. How do I forward messages ?
You have to implement doesNotUnderstand: to send a sentTo: message.
- doesNotUnderstand:aMsg
{
  return [aMsg sentTo:aProxy];
}


        




C interview questions and answers

1.PASCAL TRIANGLE
#include<stdio.h>
#include<conio.h>
#include<math.h>

long fact(int);

main()
{
   int i, n, c;

   printf("Enter the number of rows you wish to see     in pascal triangle\n");
   scanf("%d",&n);

   for ( i=0 ; i<n ; i++ )
   {
      for ( c=0 ; c<=( n-i-2 ) ; c++ )
         printf(" ");

      for( c = 0 ; c <= i ; c++ )
  printf("%ld",factorial(i)/(fact(c)*fact(i-c)));

      printf("\n");
   }

   getch();
   return 0;
}

long factorial(int n)
{
   int c;
   long result = 1;

   for( c = 1 ; c <= n ; c++ )
         result = result*c;

   return ( result );
}





2.Reverse a string. Write a C/C++ program.

void ReverseString (char *String) 
{
 char *Begin = String; 
 char *End = String + strlen(String) - 1; 
char TempChar = '\0'; 
while (Begin < End) 
TempChar = *Begin; 
*Begin = *End; 
*End = TempChar; 
Begin++; 
End--; 
}




 3.Fibonacci series:
# include<stdio.h>
void main()
 {
   int i,f1=0,f=1,fib,n;
   clrscr();
   printf("Enter Any Number:");
   scanf("%d",&n);
   printf("\n.......FIBONACCI SERIES.......\n");
   printf("0 \t");
   for(i=1;i<=n;i++)
     {
       fib=f+f1;
       printf("%d\t",fib);
       f=f1;
       f1=fib;
     }
  getch();
 }_

4.Palindrom:
#include<stdio.h>
void main()
{
  int n,i,r=0,a,t;
  clrscr();
  printf("\n enter any no:");
  scanf("%d",&n);
  t=n;
    while(n>0)
     {
       a=n%10;
       r=r*10+a;
       n=n/10;
     }
    if(r==t)
    printf("\n given no is pallindrome");
    else
    printf(" not pallindrome");
    getch();}
5.Tables:
# include<stdio.h>
# include<math.h>
void main()
 {
      int a[10],b[10],i,j,n;
      clrscr();
      printf("\n enter any no:");
      scanf("%d",& a[i]);
      for(b[j]=1;b[j]<=10;b[j]++)
      {
             n=a[i]*b[j];
         printf("%d*%d=%d \n ",a[i],b[j],n);
   }
  getch();
 }




   6.Largest Number:
# include<stdio.h>
void main()
{
      int a[10],t,i,j,n;
      clrscr();
      printf("\n enter size of array:");
      scanf("%d",&n);
      printf("\n array elements are:");
  for(i=0;i<n;i++)
 scanf("%d",&a[i]);
      for(i=0;i<n-1;i++)
       {
             for(j=i+1;j<n;j++)
          {
        if(a[i]>a[j])
        {
             t=a[i];
             a[i]=a[j];
             a[j]=t;
        }
       }
    }
           printf("%d %d",a[n-2],a[n-1]);     getch();  }
7.What will be printed as the result of the operation below?
main()
{
    int x=20,y=35;
   
 x=y++ + x++;
   
 y= ++y + ++x;
    
printf(“%d%dn”,x,y); 
Answer : 5794 
10.What will print out? 
main()
{
     
     char *p1=“name”;
       
char *p2;
      
  p2=(char*)malloc(20);
       
 memset (p2, 0, 20);
     
   while(*p2++ = *p1++);
        printf(“%sn”,p2); 
Answer:empty string. 
10.What will be printed as the result of the operation below?
#define swap(a,b) 
a=a+b;
b=a-b;
a=a-b; 
void main()
{
  int x=5, y=10;
    
swap (x,y);
    
printf(“%d %dn”,x,y);
    
swap2(x,y);
    
printf(“%d %dn”,x,y);
int swap2(int a, int b)
{
    
int temp;
    
temp=a;
    
b=a;
    
a=temp;
    
return 0; } 
Answer: 10, 5
10, 5 
13.What will be printed as the result of the operation below?
main()
{
    
int x=5;
    printf(“%d,%d,%dn”,x,x< <2,x>>2); 
}
Answer: 5,20,1 

14.What will be printed as the result of the operation below?
main()
{

    char *ptr = ” Cisco Systems”;

    *ptr++; printf(“%sn”,ptr);

    ptr++;

    printf(“%sn”,ptr); 
Answer:Cisco Systems
isco systems 


15.What will be printed as the result of the operation below?
main()
{

    char s1[]=“Cisco”;

    char s2[]= “systems”;

    printf(“%s”,s1);

Answer: Cisco 
16.What will be the result of the following code?
#define TRUE 0 // some code 
while(TRUE)
 { 
    // some code 
Answer: This will not go into the loop as TRUE is defined as 0. 



17.What will be printed as the result of the operation below?
main()
{

    int x=10, y=15;

    x = x++; 

     y = ++y;

    printf(“%d %dn”,x,y); 
Answer: 11, 16 

18.What will be printed as the result of the operation below?
main()

{

    int a=0;

    if(a==0)

        printf(“Cisco Systemsn”);
        printf(“Cisco Systemsn”); 
Ans: Two lines with “Cisco Systems” will be printed. 

                 BOOKS TO REFER

Object-Oriented Programming : An Evolutionary Approach, 2nd Ed.
Brad Cox & Andy Novobilski, ISBN 0201548348.

An Introduction To Object-Oriented Programming, 2nd Ed.
Timothy Budd, ISBN 0201824191

Objective-C : Object-Oriented Programming Techniques
Pinson, Lewis J. / Wiener, Richard S., ISBN 0201508281

Applications of Object-Oriented Programming; C++ SmallTalk Actor Objective-C Object PASCAL
Pinson, Lewis J. / Wiener, Richard S., ISBN 0201503697
a