Mar 182013
 

Sometimes, accessing the content of a web page from an application may be necessary. The simplest solutions to this requirement download the page by establishing a TCP connection to the web server, sending a HTTP request and reading the HTML code that the server sends as response.

But this procedure fails when a server with dynamic content is accessed. A server of this kind generates part of the content of the page using some javascript code that runs on the client once the page has been downloaded (normally as part of the “onload” event handling). This javascript code might interact with the DOM, retrieve additional content issuing ajax requests, etc. The final content of the page could be in this case quite different from the initially delivered by the server.

This post explains how to use the java library HtmlUnit. This library implements a headless browser with a javascript interpreter. The HtmlUnit browser can be fully controlled from a java program. In this way, pages from a dynamic web site can be downloaded, and the final content of the pages after execution of the javascript code can be retrieved by the program. Continue reading »

 Posted by at 10:38 am
Oct 262012
 

An associative array is a very useful data structure for all kinds of application. An associative array is just a set of (key, value) pairs. Many programming languages, such as PHP and Perl (using hash variables) implement the functionality to work with these structures. Also Java incorporates associative arrays in the form of instances of the java .util.Hashtable class.

Continue reading »

 Posted by at 3:51 pm
Oct 262012
 

In our previous post introducing the Java Language we have already mentioned that variables in this language must be declared before being referenced in the code. Besides, a variable can only hold values of a given data type, specified in the variable declaration. The sample code below exemplifies how variables are declared and initialized, and the primitive data types available in Java:

Continue reading »

 Posted by at 12:13 pm