How are Observer and Observable used?

Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects. In Java, the Observer and Observable classes were part of the java.util package to implement the … Read more

Why do threads block on I/O?

Threads block on I/O (that is enters the waiting state) so that other threads may execute while the I/O Operation is performed. Threads often block on I/O (Input/Output) operations in Java due to the nature of these operations. When a thread performs I/O, such as reading from a file, writing to a network socket, or … Read more

What is a transient variable?

A transient variable is a variable that may not be serialized. In Java, a transient variable is a variable that is marked with the transient keyword. When an instance of a class is serialized, the values of its transient variables are not included in the serialized form. This means that transient variables are not part … Read more

How are Servlets and JSP Pages related

JSP pages are focused around HTML (or XML) with Java codes and JSP tags inside them. When a web server that has JSP support is asked for a JSP page, it checks to see if it has already compiled the page into a servlet. Thus, JSP pages become servlets and are transformed into pure Java … Read more

How can I delete a cookie with JSP?-

Say that I have a cookie called “foo, ” that I set a while ago & I want it to go away. I simply: <% Cookie killCookie = new Cookie(”foo”, null); KillCookie. setPath(”/”); killCookie. setMaxAge(0); response. addCookie(killCookie); %> In JavaServer Pages (JSP), you can delete a cookie using the HttpServletResponse object. Here’s an example of … Read more