The difference between constructors and regular methods
1.Constructors have the same name as the class name and cannot return a value. Regular methods can have any name and can be called any number of times.
2.Constructors are called only once per creation of an object while regular methods can be called many times.
When to use serialization
1.A common use of serialization is to use it to send an object over the network or if the state of an object needs to be persisted to a flat file or a database.
2.The objects stored in an HTTP session should be serializable.
3.Objects are passed in RMI across network using serialization.
Serialize an object to a file
Car car = new Car();
FileOutputStream fos = new FileOutputStream(filename);
ObjectOutputStream out = new ObjectOutputStream(fos);
out.writeObject(car);
out.close();
The difference between an instance variable and a static variable
1.Instance variables are non-static and there is one occurrence of an instance variable in each class instance.
2.Class variables are called static variables. There is only one occurrence of a class variable per JVM per class loader.
The difference between final, finalize and finally
final
1.A final class can’t be extended.
2.A final method can’t be overridden when its class is inherited.
3.Can’t change value of a final variable.
finally, handles exception
finalize, method helps in garbage collection.
The difference between Runtime(unchecked) exceptions and checked exceptions
Unchecked exceptions:
1.represent defects in the program.
2.subclasses of RuntimeException.
3.a method is not obliged to handle the unchecked exceptions.
Checked exceptions:
1.represent invalid conditions in areas outside the immediate control of the program.
2.subclasses of Exception.
3.a method is obliged to handle all the checked exceptions.
MVC
Model, represent the core business logic and state. A model commonly maps to data in the database and will also contain core business logic.
View, renders the contents of a model. A view accesses the data from the model and adds display logic to present the data.
Controller, acts as the glue between a model and a view.
The life cycle methods of a servlet
The Web container is responsible for managing the servlet’s life cycle.
1.The Web container creates an instance of the servlet and then the container calls the init() method.
2.At the completion of the init() method the servlet is in ready state to service requests from clients.
3.The container calls the servlet’s service() method for handling each request by the spawning a new thread for each request from the Web container’s thread pool.
4.Before destroying the instance the container will call the destroy() method.
The difference between doGet() and doPost() or GET and POST
1. The request parameters are transmitted as a query string appended to the request. This is a security risk. GET is not appropriate when large amounts of input data are being transferred.
2. The request parameters are passed with the body of the request. More secured. Can send much more information to the server.