|
-
Dec 23rd, 2001, 12:30 AM
#1
Thread Starter
Randalf the Red
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?
.
-
Dec 23rd, 2001, 04:05 PM
#2
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
-
Dec 24th, 2001, 02:38 AM
#3
Thread Starter
Randalf the Red
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.
.
-
Jan 2nd, 2002, 05:32 PM
#4
Dazed Member
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.
-
Jan 4th, 2002, 06:31 AM
#5
Thread Starter
Randalf the Red
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.
.
-
Jan 4th, 2002, 02:00 PM
#6
Dazed Member
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.
Last edited by Dilenger4; Jan 4th, 2002 at 02:16 PM.
-
Jan 4th, 2002, 10:08 PM
#7
Thread Starter
Randalf the Red
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.
.
-
Jan 4th, 2002, 11:46 PM
#8
Dazed Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|