Results 1 to 8 of 8

Thread: The URL class constructor

  1. #1

    Thread Starter
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    The URL class constructor

    There is one form of the URL class constructor that takes the filename as an argument along with the protocol and the hostname. In the filename argument, an initial slash (/) is mandatory. If this is so, why is the constructor not smart enough to add it to the filename every time it finds the slash is missing?

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    I suppose you'll have to blame Sun for that. You could always subclass URL, and make it "smart enough".

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    hmmm.... Making your own Smart classes.....

    I also read that Solaris JDK 1.0 did not support the ftp protocol. But it would be a poor idea to write your own protocol handler in Java for ftp.

    Anyways, I shall just continue using a slash in the beginning rather than subclassing the URL class. As with the package concept in Java, if the .net package is modified, I would most probably lose the subclass.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  4. #4
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    If this is so, why is the constructor not smart enough to add it to the filename every time it finds the slash is missing?
    That's a good question. The main URL constructor
    takes the whole string as an arguement. ie...... "http://www.vbworld.com/thread.html" but when using one of the alternate constructors that breaks up the string into pieces
    the slashes from the protocol can be ommitted but the file has to start with a slash "/"

    For instance URL u = new URL("http", "www.vbworld.com", /thread1.html")

    I just think the reason that the file name must start with a slash is just so the the authority and the file path can be properly combined.

  5. #5

    Thread Starter
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    But in this other constructor, Sun could very well provide that the initial slash is added by the constructor if it was not there.

    There is another question similar to this: The JavaC compiler always requires that the filename be spelt out in full, including name and extension. And also it requires that the extension be .Java. Wouldn't it be easier to make JavaC so smart that it could assume an extension of .Java if no extension was specified? It's like the bad interface design where there's only one choice and you still have to click onto an option button or a command button to make a selection.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  6. #6
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Posted by HoneyBee
    But in this other constructor, Sun could very well provide that the initial slash is added by the constructor if it was not there.
    Of course they could That's what i was trying to say. When using the one of the other constructors that breaks up the URL the //'s can be ommited from the protocol. So then why would they make us add it to the file segment?

    For instance URL u = new URL("http", "www.vbworld.com", /thread1.html")

    Wouldn't it be easier to make JavaC so smart that it could assume an extension of .Java if no extension was specified?
    Yes i agree with you also, because when you run the interpeter it's non necessary to append .class to the file. ie... java -classpath C:\Java; MyApp so why would you have to append .java when you compile. ie javac C:\Java\MyApp.java

    I doubt that you would be working from the console if you had a programming job so i don't see how sun would really try and change the process of compiling.

  7. #7

    Thread Starter
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    In short, all URLs are better off being sent first to the encoder class. I am reading a few O'Reilly books on servlets and networking right now, if I find something interesting I shall post it here.

    btw, the O'Reilly book on networking has an example of a decoder class they say is not in Java. Perhaps it was added in the newer versions of JDK.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  8. #8
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Perhaps it was added in the newer versions of JDK.
    Perhaps, The latest one i have is Java Network Programming. Oreilly, by Elliotte Rusty Harold. Second Edition which covers java 1.2 & 1.3 This dude knows his stuff. It does make sense to encode all url's first. He really didn't say that, and i don't know if that is common to do in the work place (since i have never had a programming job). but it makes sense to do.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width