Colections in Java:
The collection frame work provides a set of interfaces ( Collection, List, Set, SortedSet)
The collection Interface
The collection interface :
* Objects can be added using the "add(Object x)" method. So any type of object can be added.
* We can use "addAll(Collection c)" method to store the elements of a certain collection into another one.
* "remove() and removeAll()" can be used to remove objects from the collections.
* "contains() and containsAll()" are methods that are used for the purpose of checking prescenece of one/all object in a collection.
* "toArray()" mehtod is used to convert the collection to an array
* "iterator()" returns an iterator over that collection.
The List Interface
The List interface extends collection and presents the behavior of storing a squence of elements. A list may contain duplicate elements.
* Methods like "add(), addAll(), add(int, Object) addALL(int, Object)" are methods used to add the elements either at the end or at the specified index.
* get(int) is used to retrive the object from the List
* indexOf() and lastIndexOf() is used to get the index of the object
* subList can be extracted specifying the start and end index. List subList(int, int)
The Set Interface
The set interface is the interface that extends the behavior of the collection.
* Elements in the set are unique. Duplicates are not allowed.
* It returns false if we try to add a duplicate.
The Sorted Set
Sorted Set interface extends the set interface and provides a behavior that elements in the sorted set are stored in ascending order.
* first() returns the first element of the sorted set.
* subset(Object start, Object end) returns the subset of the elemtns from the sorted set.
* comparator() returns the comparator of the sorted set.
* last() is used to get the last elemnt of the sorted set.
Saturday, February 28, 2009
Thursday, February 26, 2009
Java and J2EE Fundamentals
Cookies are used basically for the purpose of session management. How it works is. The server associates a cookie with a web client. It will send the cookie along with the response to the web client. THe web client then while responding will send the cookie back without changing it. So it can be used to do :
1. Session Tracking
2. Authentication
3. Any specific user information eg. shopping carts.
How the server sets the cookie is implementation dependent. It can be set once the user hits the site. Or it can be set when the user logs in. So once the cookie is set, all the communication between the web client and server will happen and server will identify the client on the basis of the cookie.
In some browser the cookies are disabled. SO in that case how should one do session tracking? It can be done by using the specific methods in the response object.
response.encodeURL();
response.encodeRedirectedURL();
WHat these functions do is. THey encode the URL specified as the parameter to the function and append the session id to it.
Can a class be static?
http://www.javaworld.com/javaworld/javaqa/1999-08/01-qa-static2.html
1. Session Tracking
2. Authentication
3. Any specific user information eg. shopping carts.
How the server sets the cookie is implementation dependent. It can be set once the user hits the site. Or it can be set when the user logs in. So once the cookie is set, all the communication between the web client and server will happen and server will identify the client on the basis of the cookie.
In some browser the cookies are disabled. SO in that case how should one do session tracking? It can be done by using the specific methods in the response object.
response.encodeURL();
response.encodeRedirectedURL();
WHat these functions do is. THey encode the URL specified as the parameter to the function and append the session id to it.
Can a class be static?
http://www.javaworld.com/javaworld/javaqa/1999-08/01-qa-static2.html
Subscribe to:
Posts (Atom)