Many
Don’t underestimate the power of diagrams.
Knowledge-based questions vary greatly in frequency from interview to interview. Some interviewers will not ask knowledge-based questions, while others will focus solely on them. Interviewers often ask these questions when there is no whiteboard or paper available, such as at
Knowledge-based questions
It’s a very good idea to review your rsum prior to your interview and make sure you’re prepared to answer questions about every item on the rsum, no matter how small. Some interviewers will even go through your rsum and ask you general questions about each item - ”What is X ?” and “What have you done with X ?” For example, if you put SOAP on your resume, be prepared for the questions “What is SOAP?” and “What have you done with SOAP?” If you can’t intelligently answer either question, you should remove the SOAP reference from your rsum.
| Tip |
Be prepared to answer questions about everything on your rsum. |
In a similar vein, be careful with what you say during the interview. The interviewer may want some more
It would be
Interviewers prefer specific answers to general answers. For example, suppose you are asked, “What is AJAX?” One general answer is, “It stands for
asynchronous JavaScript and XML
.” While this answer is technically correct, it doesn’t
| Tip |
Offer specific and thorough responses. |
One final note: The answers presented here are researched answers that result from many people thinking about a question and coming up with the best answer. As a candidate hearing a question for the first time, you are not expected to replicate such detailed solutions. Consider these answers to be the goal, and try to get as close to these solutions as possible.
| Important |
What are the differences between C++ and Java? |
C++ and Java are syntactically very similar. Java’s designers intended this to make it easy for C++ developers to learn Java. Apart from this area of similarity, Java and C++
C++ is a superset of C and maintains features such as programmer-controlled memory management, pointers, and a preprocessor for full backward compatibility with C. In contrast, Java eliminates these and other bug-prone features. Java
| Tip |
A limited form of multiple inheritance can be simulated in Java using interfaces. |
In Java, all objects are passed by reference, whereas in C++, the default behavior is to pass objects by value. Java does not perform automatic type casting as C++ does, though
In situations where there is legacy C code and a great need for performance, C++ has certain benefits,
| Important |
Discuss friend classes in C++ and give an example of when you would use one. |
The
friend
keyword is applied to either a function or a class. It gives the
friend
function or
friend
class access to the private members of the class in which the declaration occurs. Some programmers feel this feature
In some cases, however, the benefits of a friend class outweigh its drawbacks. For example, suppose you implemented a sophisticated dynamic array class. Imagine that you wanted a separate class to iterate through your array. The iterator class would probably need access to the dynamic array class’s private members to function correctly. It would make sense to declare the iterator as a friend to the array class. The workings of the two classes are inextricably tied together already, so it probably doesn’t make sense to enforce a meaningless separation between the two.
Note that while Java and C# do not support the concept of friend classes, they do support nested classes, and nested classes have access to their enclosing class’ private data and methods. nested classes can therefore take the place of friend classes in many instances.
| Important |
Assume you have the class hierarchy shown in Figure 14-1.
|
| Important |
You are given a method that takes a B as an argument. Which of the classes can you pass to the method? |
Clearly, you can pass B because that’s exactly what the method takes. You can’t possibly pass D because it may have totally different characteristics than B. A is the parent class of B. Consider that a child class is required to implement all of the methods of the parent, but the parent does not
A hash table does one thing well. It can store and retrieve data quickly (in O(1) or constant time). However, its uses beyond this are limited.
| Important |
Discuss what garbage collection is and explain different ways it can be implemented. |
Garbage collection is the process by which a program automatically finds and reclaims memory that is no longer used or no longer accessible by an application. This reclamation occurs without programmer assistance. C#, Java, Lisp, and Perl are examples of languages with garbage-collection facilities.
Garbage collection provides several advantages over having a programmer explicitly deallocate memory. It eliminates bugs due to dangling pointers and memory leaks. It also promotes greater simplicity in program and interface design because the complicated mechanisms traditionally used to ensure that memory is properly freed (such as “smart pointers” in C++) are unnecessary. In addition, because programmers don’t have to worry about memory deallocation, program development proceeds at a more rapid pace.
Garbage collection is not without its disadvantages, however. Garbage-collected programs often run more slowly because of the overhead needed for the system to determine when to deallocate and
One method of garbage collection is to use
reference counting
. This involves tracking how many
Reference counting is simple and relatively fast. However, it doesn’t handle circular references. Consider what happens in the case of a circularly linked list with nothing external pointing to it. Every element in the list has a nonzero reference count, yet the memory isn’t referenced by any object outside the list itself. Thus, the memory could safely be deallocated, but reference-based garbage collection won’t free it.
A second method of garbage collection is known as mark and sweep . In the first pass, the memory manager will mark all objects that can be accessed by any thread in the program. In the second pass, all unmarked objects are deallocated, or swept away.
Mark and sweep handles circular references, but it’s also less efficient. The garbage collector runs at different points in an application’s execution and may cause the application to pause while the garbage collecting occurs.
| Important |
What are the two major issues in networking performance? |
Any network can be measured by two major characteristics: latency and bandwidth. Latency refers to how long it takes a given bit of information to get through the network. Bandwidth refers to the rate at which data moves through the network once communication is established. The perfect network would have infinite bandwidth and no latency.
A pipe is a good analog for a network. The time it takes for a
Latency and bandwidth problems are often
| Important |
Discuss the differences between symmetric key cryptography and public key cryptography. Give an example of when you would use each. |
Symmetric key cryptography,
also called
shared key cryptography,
involves two people using the same key to encrypt and decrypt information.
Public key cryptography
makes use of two different keys: a public key for encryption and a private key for decryption. Symmetric key cryptography has the advantage that it’s much faster than public key cryptography. It is also generally easier to implement, less likely to involve patented algorithms, and usually requires less processing power. On the downside, the two parties sending messages must agree on the same private key before securely transmitting information. This is often inconvenient or even impossible. If the two parties are
Public key cryptography has the advantage that the public key, used for encryption, does not need to be kept secret for encrypted messages to
Both public key and symmetric key cryptography are used to get secure information from the Web. First your browser establishes a shared session key with the Web site using public key cryptography. Then you communicate with the Web site using symmetric key cryptography to actually obtain the private information.
| Important |
If you discover a new cryptography algorithm, should you use it immediately? |
This is not a trick question, but goes to the heart of modern cryptography. Basically, no algorithm stays secret for long, and almost every algorithm has at least minor bugs in it or in its implementation. It’s virtually impossible to hide an algorithm given the number of people who develop it and know about it and the advanced techniques used by today’s best crackers. If your security is based on the
Thus, it’s best to make any algorithm public from the beginning and flush out the bugs, rather than keep it secret and encounter a lot of security problems when it is
| Important |
Compare and contrast a hash table and a binary search tree. If you were designing the address book data structure for a personal digital assistant (PDA) with limited memory, which one would you use? |
A binary search tree can insert and retrieve in O(log( n) ). This is fast, though not as fast as a hash table’s O(1). A binary search tree, however, also maintains its data in sorted order.
In a PDA, you want to keep as much memory as possible available for data storage. If you use an unordered data structure such as a hash table, you need additional memory to
If you use a binary search tree, you won’t have to waste memory or processing time on sorting records for display. Although binary tree operations are slower than hash table operations, a device like this is likely to have no more than about 10,000 entries, so a binary search tree’s O(log( n )) lookup will undoubtedly be fast enough. For these reasons, a binary search tree is better suited for this kind of task than a hash table.