Went on a few developer interviews recently, looks like tech hiring is picking up. Here are some of the question I got, and my answers.
I'd love to see the *real* answers from all you gurus out there.
QUESTIONS
1. What is the difference between a LinkedList and an ArrayList? Why would I use a LinkedList instead of an ArrayList?
2. Write a method that reverses a string. Don't use StringBuffer reverse() thank you!
3. Write a method that calculates the factorial of a given number.
4. Why should I use the MVC pattern in a web app?
********** ANSWERS *************
1. What is the difference between a LinkedList and an ArrayList? Why would I use a LinkedList instead of an ArrayList?
ANSWER: a) A LinkedList is similar to an ArrayList in that it is ordered by index position, but it differs in that the elements are double-linked to one another. This linkage gives you new mehtods for adding and removing from the beginning or end.
b) If your program frequently provides random access to the data of the list, the ArrayList class offers quick access to individual elements of the list. This quick access comes at a cost of slower operations for adding and removing in the middle of the list. If this latter behavior is what you desire, than the LinkedList class offers a better alternative. It provides quick sequential access, additions, and deletes, at a cost of slower random access.
2. Write a method that reverses a string. Don't use StringBuffer reverse() thank you!
ANSWER:
3. Write a method that calculates the factorial of a given number.
ANSWER:
4. Why should I use the MVC pattern in a web app?
ANSWER:
- You can decouple the view from the model and thereby swap out views easily.
- You can put all security, authorization, session logic in the Controller instead of in each protected page.