Tuesday, November 29, 2011

XPath tutorial

http://www.w3schools.com/xpath/xpath_nodes.asp

terminology:
Nodes/Atomic values/parent/children/siblings/Ancestors/Descendants


examples:

Using XMLHttpRequest to load XML documents is supported in all modern browsers.
var xmlhttp=new XMLHttpRequest()

IE: xmlDoc.selectNodes(xpath);
other browsers:xmlDoc.evaluate(xpath, xmlDoc, null, XPathResult.ANY_TYPE,null);

xpath = /bookstore/book/title Select all the titles
/bookstore/book[1]/title select the first book title

/bookstore/book[price>35]/title

SAX vs DOM

http://geekexplains.blogspot.com/2009/04/sax-dom-jaxp-jdom-evolution-of-java-xml.html

the difference
http://geekexplains.blogspot.com/2009/04/sax-vs-dom-differences-between-dom-and.html

--
SAX v/s DOM

Main differences between SAX and DOM, which are the two most popular APIs for processing XML documents in Java, are:-
Read v/s Read/Write: SAX can be used only for reading XML documents and not for the manipulation of the underlying XML data whereas DOM can be used for both read and write of the data in an XML document.
Sequential Access v/s Random Access: SAX can be used only for a sequential processing of an XML document whereas DOM can be used for a random processing of XML docs. So what to do if you want a random access to the underlying XML data while using SAX? You got to store and manage that information so that you can retrieve it when you need.
Call back v/s Tree: SAX uses call back mechanism and uses event-streams to read chunks of XML data into the memory in a sequential manner whereas DOM uses a tree representation of the underlying XML document and facilitates random access/manipulation of the underlying XML data.
XML-Dev mailing list v/s W3C: SAX was developed by the XML-Dev mailing list whereas DOM was developed by W3C (World Wide Web Consortium).
Information Set: SAX doesn't retain all the info of the underlying XML document such as comments whereas DOM retains almost all the info. New versions of SAX are trying to extend their coverage of information.

Friday, November 18, 2011

Doctype

http://www.w3schools.com/tags/tag_doctype.asp

Thursday, November 17, 2011

JavaScript basics

http://www.w3schools.com/js/js_loop_for_in.asp

var person={fname:"John",lname:"Doe",age:25};

for (x in person)
{
document.write(person[x] + " ");
}

--
JavaScript is Case Sensitive

--
You can break up a code line within a text string with a backslash. The example below will be displayed properly:

document.write("Hello \
World!");

--
try--catch--throw

--

interview questions

1.draw architect design of the project you worked on.
2. SQL;
employee, dept
find departid which has duplicate employee name
SELECT name, departid  COUNT(name) AS NumOccurrences FROM employee GROUP BY name,departid HAVING ( COUNT(name) > 1 )
find the person who has the highest salary in one dept
select name

where salary = (select max(salary)
from employee
group by departid )
from employee
3. List
sort the list
(calling Collection.sort)
4.tapestry design
5.java jdbc calls what is the common mistakes
6. http protocol
7. WAR config
8. webservices structure

(ST)

Wednesday, November 16, 2011

create or update a view

http://www.w3schools.com/sql/sql_view.asp

CREATE OR REPLACE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition

Tuesday, November 15, 2011

java memory leak

what are Java memory leaks? If a program holds a reference to a heap chunk that is not used during the rest of its life, it is considered a memory leak because the memory could have been freed and reused.

http://www.ibm.com/developerworks/rational/library/05/0816_GuptaPalanki/

Monday, November 14, 2011

java 1.5 vs 1.4

1. autoboxing/unboxing
2.generics
3.annotations
4.java.util.concurrent
5.enum
http://docs.oracle.com/javase/1.5.0/docs/guide/language/enums.html
6.variable number of arguments
aMethod(T... args)
a T... is only a syntactic sugar for a T[].
7.for each
8. import static

the following syntax imports a particular static member:

import static packageName.ClassName.staticMemberName;

The following syntax imports all static members of a class:

import static packageName.ClassName.*;
9. printf
great examples

Overflow and underflow

http://javapapers.com/core-java/java-overflow-and-underflow/

it has very good code example in the link:

In Java arithmetic operators don’t report overflow and underflow conditions. They simply swallow it! It is a very dangerous thing to do.

When the resultant value of an operation is larger than 32 bits (the maximum size an int variable can hold) then the low 32 bits only taken into consideration and the high order bits are discarded. When the MSB (most significant bit) is 1 then the value is treated as negative.

While using java floating point operators, overflow will result in Infinity and underflow will result 0.0 As a general rule here also Java doesn’t throw an error or exception for overflow and underflow.

Garbage Collection

1. reference counting
2. Mark and sweep: starting at root objects ( objects on the stack, global object etc), mark them live, and recursively marking any object referenced from them.

Interpreted language

http://en.wikipedia.org/wiki/Interpreted_language

Once was asked: is Java a interpreted language or compiled language.

Interpreted language is a programming language in which programs are 'indirectly' executed ("interpreted") by an interpreter program. This can be contrasted with a compiled language which is converted into machine code and then 'directly' executed by the host CPU.

Sunday, November 13, 2011

query plan

http://www.sqlite.org/eqp.html

final array

void foo() {
final int[] number = {1,2,3};
numbers[1] = 50; // is this legal?
}

legal, the final is on the array, so you can not change the length of array, but you can change the element

Difference between Vector and List in Java

http://javapapers.com/core-java/java-collection/difference-between-vector-and-arraylist-in-java/

Vector and ArrayList are very similar. Both of them represent a 'growable array', where you access to the elements in it through an index.

ArrayList it's part of the Java Collection Framework, and has been added with version 1.2, while Vector it's an object that is present since the first version of the JDK. Vector, anyway, has been retrofitted to implement the List interface.

The main difference is that Vector it's a synchronized object, while ArrayList it's not.

While the iterator that are returned by both classes are fail-fast (they cleanly thrown a ConcurrentModificationException when the orignal object has been modified), the Enumeration returned by Vector are not.

Unless you have strong reason to use a Vector, the suggestion is to use the ArrayList.

--------

java.util.Vector came along with the first version of java development kit (JDK). java.util.ArrayList was introduced in java version1.2, as part of java collections framework. As per java API, in Java 2 platform v1.2,vector has been retrofitted to implement List and vector also became a part of java collection framework.

All the methods of Vector is synchronized. But, the methods of ArrayList is not synchronized. All the new implementations of java collection framework is not synchronized.

Vector and ArrayList both uses Array internally as data structure. They are dynamically resizable. Difference is in the way they are internally resized. By default, Vector doubles the size of its array when its size is increased. But, ArrayList increases by half of its size when its size is increased.

Therefore as per Java API the only main difference is, Vector’s methods are synchronized and ArrayList’s methods are not synchronized.

Vector or ArrayList? Which is better to use in java?

In general, executing a ‘synchronized’ method results in costlier performance than a unsynchronized method. Keeping the difference in mind, using Vector will incur a performance hit than the ArrayList. But, when there is a certain need for thread-safe operation Vector needs to be used.

Is there an alternate available in java for Vector?
ArrayList can be synchronized using the java collections framework utility class and then ArrayList itself can be used in place of Vector.

When there is no need for synchronized operation and you still look for better performance ‘Array’ can be used instead of ArrayList. But the development is tedious, since it doesn’t provide user friendly methods.

When you use Vector or ArrayList, always initialize to the largest capacity that the java program will need. Since incrementing the size is a costlier operation.

Thursday, November 10, 2011

LDAP

LDAP, Lightweight Directory Access Protocol, is an Internet protocol that email and other programs use to look up information from a server.

dn: cn=John Doe,dc=example,dc=com
cn: John Doe
givenName: John
sn: Doe
telephoneNumber: +1 888 555 6789
telephoneNumber: +1 888 555 1232
mail: john@example.com
manager: cn=Barbara Doe,dc=example,dc=com
objectClass: inetOrgPerson
objectClass: organizationalPerson
objectClass: person
objectClass: top