Sunday, September 8, 2013

what is main different XL and JSON goal?

19 down vote accepted

What is JSON?

JSON (JavaScript Object Notation) is a lightweight text-based open standard designed for human-readable data interchange. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers.
Borrowing a JSON sample from Wikipedia, a JSON representation of a person might look like:
{
    "firstName" : "John",
    "lastName"  : "Smith",
    "address"   :
    {
        "street": "21 2nd Street",
        "city"  : "New York",
        "state" : "NY",
        "zip"   : "10021"
    },
    "phoneNumber":
    [
        {
            "type"  : "home",
            "number": "212 555-1234"
        },
        {
            "type"  : "fax",
            "number": "646 555-4567"
        }
    ]
}

What is XML?

XML (eXtensible Markup Language) is a simple, very flexible text format derived from SGML. According to Wikipedia, XML is a set of rules for encoding documents in machine-readable form. [... It's goals] emphasize simplicity, generality, and usability over the Internet. It is a textual data format[...].
Again borrowing a XML sample from Wikipedia, an XML representation of a person might look like:
<person firstName="John" lastName="Smith">
    <address street="21 2nd Street" city="New York" state="NY" zip="10021" />
    <phoneNumber type="home" number="212 555-1234" />
    <phoneNumber type="fax"  number="646 555-4567" />
</person>

Comparison

Based on these simple definitions, it's understandable that one could conclude that JSON and XML are comparable. If your goal is to use one or the other for simple data interchange over the Internet,
 as exhibited by the simple examples above, that goal is surely attainable and JSON and XML are, indeed, mostly comparable.
However, as you dig deeper into the specifications of each you begin to realize they are completely different standards with similar goals; each with overlapping use cases where one is much better
suited than the other and where they are equivalent solutions (where the choice is a matter of the specific use case).
Though it may be just a bit biased, The Fat-Free Alternative to XML from the JSON site
 lists some good points of comparison. There are also the XML vs JSON !!! Dont compare.
 and JSON Pros and Cons blog entries with some bullet points for comparison.

Similarities

  • May be used for textual data interchange; no obscure format that is not easily readable by humans.
  • Allows data to be represented in a structured manner, providing a level of data relationships.
  • Internationalization using Unicode.
  • Programming language agnostic; may be used in many programming languages.
  • May be used to interface heterogeneous systems; as long as all systems use an agreed data representation contract, communication between heterogeneous systems is possible.
  • Open standards; membership to any governing body is not required to acquire the 
  • specifications (JSON is defined in the IETF RFC #4627 and XML is defined as a W3C specification) and there are no restrictive licenses (JSON, XML).

Differences

  • JSON has a simple notation that may be quickly adopted by developers.
  • JSON's lightweight nature lends it towards improved Internet user experience by decreasing performance bottlenecks.
  • JSON's simple notation, borrowed from JavaScript, makes it easier and more performant to de/serialize the data representation to common data structures.
  • JSON is available in ECMAScript, 5th edition, making it available to all applications (most notably, web browsers) with an integrated ECMAScript engine.
  • XML is a document markup language, providing semantics that gives additional meaning to data; JSON does not have this ability.
  • XML has a broader range of specifications that cover such things as schemas for data 
  • definition and validation, namespaces, stylesheets, transformations, data expressions and
  •  many others.
  • XML has been around longer and is widely adopted by many businesses; affording it greater documentation, programming language support, tooling support, community experience, off-the-shelf product support, etc.
  • XML's robust standards makes it a better solution for flexible (or sometimes, rigid ... in 
  • a beneficial way) business-to-business communication.

Thursday, September 5, 2013

top core php technical interview question and answer

I've been given many interviewed by many companies for PHP development positions, every company has a slightly different interview process, but there seems to be a lot of commonalities among them. I've outlined below the main areas that companies look for knowledge in, 
  • What is Object Oriented Programming?
  • likelihood high
    This is usually a pretty open ended question. You should understand classes (objects are instantiated classes), abstract classes, interfaces, methods, properties,inheritance, multiple inheritance as well as why OOP is helpful as compared to procedural programming.
  • In PHP what is the difference between a Class and an Interface?
  • likelihood high
    Interfaces do not contain business logic, only method signatures that define a template that any classes implementing the interface must contain. Lets take an auto mobile for example. If we were to create and interface for a car we would want to define a few methods like drive, stop, turn left , turn right. This mean that any vehicle that is a car (aka implements the interface car) must have methods for these things, If they do not PHP will throw an error. So if your car is an BMW , Honda or Ford it must be able to stop. How it stops is up to each car (or PHP class) but it must be able to stop. Technically we can decided not to use an interface for cars, but then some types of cars are not forced to have a "stop" method.
  • What is MVC?
  • likelihood high
    Most programmers know this, but interviewers will likely look for a deep understanding of MVC, and some explanation or examples on how/why/ when you used it.

    MVC- Model, View, Controller - is simply a way of organizing your code into 3 separate layers each with there own jobs.

    Model - Usually contains data access code and all of you business logic code.
    View - Contains markup/design code, generally html,xml, json.
    Controller - Usually contains very little code, just whatever is needed to call the Model code and render the View code.
  • Explain how a PHP session works?
  • likelihood high
    A PHP session cookie is set in the clients browser, on every request the client sends that cookie to the server. PHP then uses that cookie to select the corresponding session information. By default PHP session_start() will store session data in files, you can also store sessions in a database.
  • What are some of the big changes PHP has gone through in the past few years?
  • likelihood high
    There are a number, but the big ones people are looking for are:
    a. PHP 5.0 realised the object model (AKA OOP).
    b. 5.1 added PDO - for accessing databases.
    c. 5.3 - added namespace support and late static bindings.
  • What is the difference between $_GET and $_POST
  • likelihood high
    This is a great question because an interviewer can tell how deeply you understand HTTP and the request/response. If you don't have good understanding of HTTP protocol, google around and get a grasp on it.
    Good answer
    Explain the HTTP protocol and how every request contains a method, generally(GET,POST,PUT,DELETE) and what each method signifies.
    Bad answer
    $_GET stores variables passed in url as query strings. $_POST stores variables past from using method = $_POST
  • In a PHP class what are the three visibility keywords of a property or method?
  • likelihood medium
    public, private and protected. The default is public.
    Public -> Any class may instantiate the class and call the method or property.
    Protected -> Only the class itself or inherited (children) classes may call a method or property.
    Private -> Only the class itself may call a method or property.
  • What is Polymorphism?
  • likelihood medium
    Don't get scared by the big word. It's simply the idea that one object can can take on many forms. So in PHP OOP one class "cars" may have two classes that extend it, for example a "Honda" class and a "BMW" class.
  • How do you load classes in PHP?
  • likelihood medium
    They are trying to gauge your understanding of how class auto loading works. Review the "autoload" and "spl_autoload_register" function (note:you should us the later). The autoload function basically triggers a function when a class is instantiated, you can put whatever logic you like in it but generally you want to include the class file based on some sort of naming convention.
  • What is the value of "$day" in the below code?
  • likelihood medium
    $wed= 1;    
    $day = ($wed==1) ? 'today' : 'tommorrow';
    // $day is now set to 'today'
    
    Companies often ask about the ternary operator (?). which is simply a shorthand for if else statements.
  • What is the Scope Resolution Operator?
  • likelihood medium
    "::" double colons is the scope operator it is used to call methods of a class that has not been instantiated. You should also understand static methods and how they differ from regular methods.
  • What are some PHP Design patterns you have worked with?
  • likelihood medium
    Design patterns are simply commonly used techniques within your code, they often are implemented in different ways so they can be a bit tricky to grasp without writing them yourself. If you are unfamiliar with them I would start by learning the Singleton Pattern and the Strategy Pattern.
  • What is the difference between single quotes and double quotes?
  • likelihood medium
    Great answer at below link.
  • What does ob_start do?
  • likelihood medium
    Makes it so PHP does not output anything. Companies ask this because many large frameworks wrap a bunch of code in ob_start() and ob_get_clean(). So understanding how that function works is pretty important.
  • What does "&" mean in '&$var' ?
  • likelihood medium
    '&' indicates a reference
  • What is the meaning of a final class and a final method?
  • likelihood medium
    Final keywords indicates that the class or method cannot be extended.
  • Does PHP support multiple inheritance?
  • likelihood medium
    No. You should understand what multiple inheritance is.
  • What are some magic methods in PHP, how might you use them?
  • likelihood medium
    Magic methods are basically triggers that occur when particular events happen in your coding. __GET, __SET are magic methods that are called (behind the seen) when you get or set a class property.
  • Are objects in PHP 5 passed by value or reference?
  • likelihood medium
    This is basically a trick questions. To understand how they are passed you need to understand how objects are instantiated. Study the below link:
  • What is the difference between $var and $$var?
  • likelihood medium
    $$var sets the value of $var as a variable.
                $day='monday';
                $$day='first day of week';
                echo $monday; //outputs 'first day of week'