Comparison: HTTP with Java, Perl or Python
J Swartz
js_nntp at nospam_blackrocksoftware.com
Sat Jun 8 17:52:02 EDT 2002
This one:
public class URLTest {
public static void main(String[] arguments) {
String myurl = "http://www.uni-dortmund.de";
try {
java.io.BufferedReader reader = new java.io.BufferedReader
( new java.io.InputStreamReader((new java.net.URL(myurl)).openStream()) );
for (String curLine = reader.readLine(); curLine != null;
curLine = reader.readLine())
System.out.println( curLine );
reader.close();
} catch (java.io.IOException ex) { System.out.println(ex); }
}
}
is 11 lines (text is wrapped here to make 13), took about 4 minutes to write
and test. It was quite straightforward.
BTW the Java 1.4 API is online here:
http://java.sun.com/j2se/1.4/docs/api/index.html
- JS
On 6/8/02 8:43 AM, in article 3D022634.9050304 at gmx.de, "Ingo Linkweiler"
<i.linkweiler at gmx.de> wrote:
> Thanks a lot for your versions.
> Which of ALL solutions is the shortest, and which the best ?
> Do you know good ways to measure the size? (LOC, irredundant or packed
> bytes....)
> But even without this:
>
> The Python version is quite short, even after adding exception handling.
> TCL seems to be same.
> The Perl version seems to be the shortest, but can you read it without
> knowing Perl?
>
> Can you estimate the time you needed for writing it?
> Did you have any difficulties?
> My Python version needed 2 Minutes, with Java I needed 20, because I did
> not unterstand the f******* manual.
>
>
>
>
> PS:
> This was my own Java solution:
>
> package meintest;
> import java.lang.Exception;
> import java.net.*;
> import java.io.*;
> public class getURL {
> public static void main(String[] args) {
> try {
> URL url = new URL("http://www.uni-dortmund.de");
> InputStream in = url.openStream();
> for (;;)
> {
> int data = in.read();
> if (data == -1)
> break;
> else
> System.out.print ( (char) data);
> }
> }
> catch (Exception e) { }
> }
> }
>
More information about the Python-list
mailing list