Watch video (reading the Java api docs on ArrayLists)
Watch video (simple intro to lists)
Watch video (Looping through lists)
Watch video (Introduction to Generics)
Watch video (Non-destructive methods using lists)
Watch video (Help with easy assignment 1)
Upload your assignment to directory IS52013B-assignments-2010-11 or to IS52014B-assignments-2010-11 depending on your course.
import java.io.*;
import java.net.*;
import java.util.Scanner;
public class getURL {
public static void main (String[] args) throws Exception {
URL u;
Scanner s;
u = new URL("http://localhost");
s = new Scanner(u.openStream());
while (s.hasNext()) {
System.out.println(s.nextLine());
}
} // end of main
} // end of class definition
Convert it so the URL come from the command line.
Watch video (reading from a url)
For the first few weeks we are going to play with this HTML Parser. Read all the documentation. Find and try out all the sample programs.
To use it, you need to put htmlparser.jar in your CLASSPATH.
If you are using Eclipse you can add htmlparser.jar to the Java Build Path of the current Java Project. See, for example, http://www.cs.iastate.edu/~lmiller/cs362/ClasspathandEclipse.htm on how to do it in Eclipse.
Watch video (using the html parser)
import org.htmlparser.util.*;
import org.htmlparser.*;
import org.htmlparser.tags.*;
import org.htmlparser.filters.*;
class test1
{
public static void main(String args[]) throws Exception
{
Parser parser = new Parser (args[0]);
NodeList list = parser.parse (new LinkStringFilter("")); // no filter
for (int i=0;i<list.size();i++)
{
System.out.println(((LinkTag)(list.elementAt(i))).extractLink());
}
}
}
Run with
java -cp .:htmlparser.jar test1 http://somewebsite/
static ArrayList <String> urlToArrayList(String url)
which takes a String representing a URL and returns an ArrayList <String> of all the links in the file.
static ArrayList <String> filter(String s,ArrayList <String> m)
which
returns an ArrayList <String> of all the elements of m which contain s. (Look up the right method for Strings).
s.danicic@gold.ac.uk