Wednesday 4 February 2015

Top 20 Programming Questions for Telephonic Interviews

Top 20 Programming Questions for Telephonic Interviews

1.     How much time it take to retrieve an element if stored in HashMap, Binary tree and a Linked list? how it change if you have millions of records?
In HashMap it takes O(1) time, in binary tree it takes O(logN) where N is number of nodes in tree and in linked list it takes O(n) time where n is number of element in list. Millions of records doesn't affect the performance if data structure are working as expected e.g. HashMap has no or relatively less number of collision or binary tree is balanced. If that's not the case then their performance degrades as number of records grows.


2. What is the difference between Overriding and Overloading? (detailed answer)
Overriding is resolved at runtime while overloading is compile time. Also rules of overriding and overloading is different, for example in Java, method signature of overloaded method must be different than original method, but in case of overriding it must be exactly same as overriding method.


3. What is difference between forking a process and spawning a thread?
When you fork a process, the new process will run same code as parent process but in different memory space, but when you spawn a new thread in existing process, it just creates another independent path of execution but share same memory space.


4. What is a critical section? (answer)
critical section is the part of a code, which is very important and in multi-threading must be exclusively modified by any thread. Semaphore or mutex is used to protect critical section. In Java you can use synchronized keyword or ReentrantLock to protect a critical section.


5. What is the difference between a value type and a reference type? (answer)
A value type is more optimized type and always immutable e.g. primitive int, long, double and float in Java, while a reference type points to a object, which can be mutable or Immutable. You can also say that value type points to a value while reference type points to an object.


6. What is heap and stack in a process? (detailed answer)
They are two separate areas of memory in same process. Talking about Java, stack is used to store primitive values and reference type to object but actual object is always created in heap. One critical difference between heap and stack is that, heap memory is shared by all threads but each thread has their own stack.


7. What is revision/version control? (answer)
Version control are software which is used to store code and manage versions of codebase e.g. SVN, CVS, Git, Perforce and ClearCase. They are very effective while comparing code, reviewing code and creating build from previous stable version. All professional development use some sort of revision or version control tool, without it you cannot mange code effectively, especially if 20 developers are working in same code base at same time. Version control tool plays very important role to keep code base consistent and resolving code conflicts.


8. What is a strongly typed programming language? (answer)
In a strongly typed language compiler ensure type correctness, for example you can not store number in String or vice-versa. Java is a strongly typed language, that's why you have different data types e.g. int, float, String, char, boolean etc. You can only store compatible values in respective types. On the other hand, weakly typed language don't enforce type checking at compile time and they tree values based upon context. Python and Perl are two popular example of weakly typed programming language, where you can store a numeric string in number type.


9. Can you describe the difference between valid and well-formed XML?
A well-formed XML is the one which has root element and all tags are closed properly, attributes are defined properly, their value is also quoted properly. On other hand, a valid XML is the one which can be validated against a XSD file or schema. So it's possible for a XML to be well-formed but not valid, because they contain tags which may not be allowed by their schema.


10. What is difference between DOM and SAX parser? (detailed answer)
DOM parser is a in memory parser so it loads whole XML file in memory and create a DOM tree to parse. SAX parser is a event based parser, so it parses XML document based upon event received e.g. opening tag, closing tag, start of attribute or end of attribute. Because of their working methodology, DOM parser is not suitable for large XML file as they will take lot of space in memory and your process may ran out of memory, SAX is the one which should be used to parse large files. For small files, DOM is usually much faster than SAX.


11. What is the relationship between threads and processes? (detailed answer)
A process can have multiple threads but a thread always belongs to a single process. Two process cannot share memory space until they are purposefully doing inter process communication via shared memory but two threads from same process always share same memory.


12. What is Immutable class mean? (detailed answer)
A class is said to be Immutable if its state cannot be changed once created, for example String in Java is immutable. Once you create a String say "Java", you cannot change its content. Any modification in this string e.g. converting into upper case,  concatenating with another String will result in new object. Immutable object are very useful on concurrent programming because they can be shared between multiple threads without worrying about synchronization. In fact, whole model of functional programming is built on top of Immutable objects.


13. Why would you ever want to create a mock object? (answer)
Mock object are very useful to test an individual unit in your Software, in fact stud and mocks are powerful tool for creating automated unit tests. Suppose you write a program to display currency conversion rates but you don't have a URL to connect to, now if you want to test your code, you can use mock objects. In Java world, there are lot of frameworks which can create powerful mock objects for you e.g. Mockito and PowerMock.


14. What is SQL injection?
SQL injection is a security vulnerability which allows intruder to steal data from system. Any system which take input from user and create SQL query without validating or sanitizing that input is vulnerable to SQL injection. In such system, intruder can inject SQL code instead of data to retrieve more than expected data. There are many instances on which sensitive information e.g. user id, password and personal details are stolen by exploiting this vulnerability. In Java, you can avoid SQL injection by using Prepared statement.


15. What is the difference between an inner join and a left join in SQL? (answer)
In SQL, there are mainly two types of joins, inner join and outer join. Again outer joins can be two types right and left outer join. Main difference between inner join and left join is that in case of former only matching records from both tables are selected while in case of left join, all records from left table is selected in addition to matching records from both tables. Always watch out for queries which has "all" in it, they usually require left join e.g. write sql query to find all departments and number of employees on it. If you use inner join to solve this query, you will missed empty departments where no one works.


16. What does the V in MVC stand for, and what does it signify? (answer)
V stands for View in MVC pattern. View is what user sees e.g. web pages. This is a very important design pattern of web development which is based upon segregation of concern, so that each area can be modified without impacting other areas. In Java world, there are lots of open source framework which provides implementation of MVC pattern e.g. Struts 2 and Spring MVC. By the way, M stands for model and C stands for controller. Modes are actual business objects e.g. User, Employee, Order while controller is used to route request to correct processor.


17. What is the difference between a class and an object? (detailed answer)
A class is a blue print on which objects are created. A class has code and behavior but an object has state and behavior. You cannot create an object without creating a class to represent its structure. Class is also used to map an object in memory, in Java, JVM does that for you.


18. What is loose-coupling?
Loose coupling is a desirable quality of software, which allows one part of software to modify without affecting other part of software. For example in a loosely coupled software a change in UI layout should not affect the back-end class structure.


19. What is difference between composition, aggregation and association? (detailed answer)
Association means two objects are related to each other but can exists without each other, Composition is a form of association where one object is composed of multiple object, but they only exists together e.g. human body is composition of organs, individual organs cannot live they only useful in body. Aggregation is collection of object e.g. city is aggregation of citizens.

20. What is the difference between an interface and an abstract class? (detailed answer)
This is the most classical question of all programming interviews. An interface is the purest form of abstraction with nothing concrete in place, while an abstract class is a combination of some abstraction and concrete things. The difference may vary depending upon language e.g. in Java you can extend multiple interface but you can only extend on abstract class. For a more comprehensive discussion see the detailed answer.





No comments:

Post a Comment

Robot Fish Can Blend in and Spy on Real Sea Creatures

As the world moving towards the Robotics and Automation, here comes a SoFi - which is called a Robofish developed by Computer Science stude...