Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mock Question - What is the answer?

 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ServletContext interface provides direct access to the hierarchy of static content documents that are part of the web application, including HTML, GIF and JPEG files through following methods
A

getSource
B

getResource
C

getResourceStream
D

getResourceAsStream
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

->getResourceAsStream(...)


Thanks,
 
Srinivasan thoyyeti
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Options B,D are correct.
B returns URL, where we need to handle URLConnection objects.
D returns InputStream directly, where container handles URLConnection objects.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, B and D are correct!
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure why getResource() is the correct answer; it returns
URL whereas getResourceAsStream() returns InputStream.

Would anybody please the option 'B' with regard to what is asked in the
question?


Thanks,
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can access the resource using the URL that is returned by getResource(). You open a stream on the URL. getResourceAsStream saves you a setp by doing it for you. Look up the IO tutorial and you will see these 2 methods used and it will explain the differences between them
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Michael,

I got it, using getResourceAsStream() or getResource() both solves our
purpose. Whereas getResourceAsStream() directly returns the stream.

So when we have URL, we use that URL to open a stream, so still we need to
follow one more step in getting the stream. Right?


Thanks,
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that is correct
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jothi Shankar Kumar Sankararaj:
The ServletContext interface provides direct access to the hierarchy of static content documents that are part of the web application,


As chandra said, i also think of same when seeing the words "direct access" which gives an impression that you get the content of the resource at hand with NO additional steps!

But does the word "hierarchy of" contribute something to this context? I think its NOT. Any suggestions?
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I always try to understand the spirit of the question rather than the exact words used. For me, this prevents me from over thinking the question, which I sometimes do. Since most books or articles that deals with this subject discuss using both of the methods, I always think that both methods may be used.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Michael Ku:
I always try to understand the spirit of the question rather than the exact words used. For me, this prevents me from over thinking the question, which I sometimes do. Since most books or articles that deals with this subject discuss using both of the methods, I always think that both methods may be used.



Yes, sometimes its helpful!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic