Tuesday, March 24, 2009

Core Java

Can we make a class as static?

We declare the top level class as the member of a package with the name of the class same as the java file. There is no point in making the top level class as static. It will be reported as an error by the java compiler.
The inner classes can how ever be declared as static.

The inner classes can be of four types:
1. Annonymous Inner class : The annonymous inner class is the class that does not have any name. It is created by calling the new() in the function argument. Like

Onclick.doAction(new xyz() {
public void actionPerformed()
{ }
});

So there is no way u can make the annonymous inner class as static.

2. Member classes: Member classes are the classes that are defined with in a class. They can be used any where with in the body of the same class. We can make the member classes as static. And we can access that class from outside by making use of the dot operator.

3. Nested Top Level classes: A nested top-level class is a member class with a static modifier. A nested top-level class is like any other top-level class except that it is declared within another class or interface. It is used to group a set of classes without creating any package.

4.Local Classes: Local classes are the classes which are are created and used inside a block.

Monday, March 16, 2009

Good Tools

Converting the Word file to HTML files. Use perl5utils library. It provides a lot of functions to play around with the text

http://www.java2s.com/Code/Jar/Apache/Downloadvelocitydep15jar.htm

Playing with the microsoft format files like .doc, .xls use the poi library of jakarta apache.

http://www.softinterface.com/DL/DL_UserData_Proc.ASP

URL rewriting tool
http://tuckey.org/urlrewrite/manual/3.0/

Free Images:
http://www.gettyimages.co.uk/
http://www.sxc.hu/index.html

Saturday, February 28, 2009

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.

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