Showing posts with label todo. Show all posts
Showing posts with label todo. Show all posts

January 25, 2010

Intro to XPath

Helpful XPath syntax reference from W3

Sample code based loosely on this Java2S example:

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

public class XMLParserAlpha
{
private static final String SOURCE = "C:/someFolder/xmlFile.xml";
private static final String EXPR = "*";

public static void main(String[] args)
{
XPath xpath = XPathFactory.newInstance().newXPath();
String xpathExpression = EXPR;
InputSource inputSource = new InputSource(SOURCE);

NodeList nodes = null;
int j = -1;
try
{
nodes = (NodeList) xpath.evaluate(xpathExpression, inputSource, XPathConstants.NODESET);
// NODESET maps to interface org.w3c.dom.NodeList
j = nodes.getLength();

for (int i = 0; i < j; i++) { System.out.println(nodes.item(i).getTextContent()); } } catch (XPathExpressionException e) { e.printStackTrace(); } } }


Other values of EXPR and what they're good for:
/Report/PublicationMetadata/DescriptiveMetadata/Title/@* - All attribute values of the title element (but not the attribute names)

TODO: FINISH POST

January 5, 2010

Java instanceof operator

instanceof checks true runtime values. So, the following code would print:


Object o = new LinkedList();
if(o instanceof LinkedList)
System.out.println("yep");


This is not the same behavior as method lookup (find the fancy name for this). This example would produce an error:


List theList = new Queue();
theList.enqueue(new Object());

December 24, 2009

Overriding vs. Overloading vs. Hiding

  • Overloading is using the same method name with a different parameter list.
  • Overriding is replacing a superclass method with a different and/or more specific one in a subclass.
  • Hiding is similar to overriding but not quite the same. In the special case where a subclass's static method has the same signature as a parent class's static method, the subclass's method hides rather than overrides the parent class's method. This makes the parent class's method completely unaccessible. TODO: Find out whether this is the only situation in which hiding applies.

Useful links
The best explanation I've found so far, from the JavaRanch FAQ

Also useful, from the Java Tutorials

This StackOverflow post is technically about .NET, but I think it's still correct for Java

Some examples from the Java Language Specification

December 16, 2009

Permanent Generation

permgen (Permanent Generation, cf. Tenured Generation)
constant string pool
does stuff in string pool get overwritten/deleted/garbage collected ever?

List of special topics

strictfp keyword
Var-args
finalize() method
Assertions
Labeled break/labeled continue
Constant pools