Practice Questions
Practice Questions
1.
What is object-oriented programming? What are two key features of object-oriented programming?
2.
What is encapsulation?
3.
What is multi-threaded computing? What are some of the dangers of multi-threaded computing and
how can they be mitigated?
4.
5.
What is a static variable? Can methods and classes be static? Why would you want to make a static
variable/method/class?
6.
What does the final keyword do? Can methods and classes be final? Why would you want to make a
final variable/method/class?
7.
What is an interface? What is an abstract class? Can you instantiate an interface or abstract class?
Why would you want to use an abstract class?
8.
9.
10. What is the difference between the stack and the heap?
11. What is DML? What is DDL? What is DCL?
12. If I have two tables A and B where B has a foreign key to A, what join would I use so that the result
has all records from A (even if there is no related record in B) and all related records from B?
13. In databases, what does indexing do?
14. What is an immutable object?
ANSWER KEY
1.
What is object-oriented programming? What are two key features of object-oriented programming?
Object-oriented programming is programming focused on manipulating data through objects. Objects
contain elements and methods to store and manipulate data. Two key features of object-oriented
programming are inheritance (objects inherit elements and method from parent objects) and
polymorphism (ability for an object to act as another, similar object).
2.
3.
What is multi-threaded computing? What are some of the dangers of multi-threaded computing and
how can they be mitigated?
Multi-threaded computing is computing in which multiple processing threads are used to complete a single
task. This typically makes the task much faster. One big danger of multi-threaded computing is the
manipulation of shared resources (resources that must be shared across multiple threads). Some ways this
danger can be mitigated is the use of locks/semaphores and/or assigning priority scores to threads.
4.
5.
What is a static variable? Can methods and classes be static? Why would you want to make a static
variable/method/class?
A static variable is a variable that, once declared, exists throughout the lifetime of the program. Methods
and classes can be static. You would want to make a variable static if several instances of a class/process
must use the variable in its current state (e.g. maintaining a list of logged-in users across multiple instances
of a controller). Methods and classes could be made static to avoid having to instantiate a new instance
every time a simple method wants to be invoked.
6.
What does the final keyword do? Can methods and classes be final? Why would you want to make a
final variable/method/class?
The final keyword makes the particular variable/class/method unchangeable and un-overridable. Methods
and classes can be made final. You would want to make a variable final to avoid it being modified by
external code (e.g. certain codes your program rely will want to be final). Methods would be made final if
you do not want their functionality to be overridden by a sub-class. Similar argument for final classes.
7.
What is an interface? What is an abstract class? Can you instantiate an interface or abstract class?
Why would you want to use an abstract class?
An interface is a contract that a class signs. An interface contains method signatures that the implementing
class must define. The methods in an interface have no implementation. An abstract class is similar to an
interface, except that an abstract class may implement any or all of the methods. Neither an interface nor an
abstract class can be instantiated. A good example of wanting to use an abstract class is implementing
mammals: all mammals eat and move in different ways, but all give live birth.
8.
9.
10. What is the difference between the stack and the heap?
The stack is used for static memory allocation and the heap is used for dynamic memory allocation. The
stack is assigned-to typically at compile time and the heap at runtime. Simply put, local variables within a
function are stored in the stack. Variables that are returned by functions are typically stored in the heap.
11. What is DML? What is DDL? What is DCL?
DML, DDL and DCL all refer to database SQL commands. DML stands for data-manipulation language
and encapsulates the commands such as SELECT, INSERT, UPDATE, DELETE, etc. DDL stands for
data-definition language and encapsulates the commands such as CREATE, ALTER, DROP, etc. DCL
stands for data-control language and encapsulates all commands that provide permissions such as GRANT.
12. If I have two tables A and B where B has a foreign key to A, what join would I use so that the result
has all records from A (even if there is no related record in B) and all related records from B?
Left outer join.
13. In databases, what does indexing do?
An index is used to make finding data in specified columns very quick. With an index the database engine
does not have to search through all rows, starting from the first, to find records for a query; it can actually
start in the middle of the data file to reduce the amount of searching.
14. What is an immutable object?
An immutable object is an object that cannot have its state changed. Typically, in order to manipulate an
immutable object, the object has methods that return a modified copy of itself (e.g. string.toUpper() returns
a copy of the string in all upper-case).