What is design by contract? Explain the assertion construct?
contract is a valuable technique, which should be used to build well-defined interfaces. The strength of this programming methodology is that it gets the programmer to think clearly about what a function does, what pre and post conditions it must adhere to and also it provides documentation for the caller. Java uses the assert statement to implement pre- and post-conditions. Java’s exceptions handling also support design by contract especially checked exceptions.
What is the main difference between a String and a StringBuffer class?
String is immutable: you can’t modify a string object but can replace it by creating a new
instance. Creating a new instance is rather expensive.
StringBuffer is mutable: use StringBuffer or StringBuilder when you want to modify the contents. StringBuilder was added in Java 5 and it is identical in all respects to StringBuffer except that it is not synchronized, which makes it slightly faster at the cost of not being thread-safe.
What is a user defined exception?
User defined exceptions may be implemented by defining a new exception class by extending the Exception class.
What is the difference between processes and threads?
A process is an execution of a program but a thread is a single execution sequence within the process. A process can contain multiple threads. A thread is sometimes called a lightweight process.
Explain different ways of creating a thread?
Threads can be used by either :
Extending the Thread class
Implementing the Runnable interface.