Results 1 to 2 of 2
- 07-03-2010, 11:15 PM #1
Member
- Join Date
- Jul 2010
- Posts
- 18
- Rep Power
- 0
Creating Java objects using "new"
In the following method, while creating Java servlets one of the methods used (according to the book Im refering too)
doGet(HttpServletRequest req, HttpServletResponse res)
req is an object of type HttpServletRequest but one does not need to write
HttpServletRequest req = new HttpServletRequest
Even in the following method, there is no mention of new for creating PrintWriter object
PrintWriter Systemout = res.getWriter();
Im new to java and trying to understand when to use "new" AND when not to.
Thank you for your responses.
- 07-03-2010, 11:38 PM #2
Its possible for methods to return objects. The res.getWriter() method probably does that.
Read the API doc the class and method for further information.
You use new when YOU want to create an object. In the method declaration:
doGet(HttpServletRequest req, HttpServletResponse res)
req and res are objects passed to that method. They were created previously.
Similar Threads
-
Java, Military Format using "/" and "%" Operator!!
By sk8rsam77 in forum New To JavaReplies: 11Last Post: 02-26-2010, 03:03 AM -
Runtime error "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
By shantimudigonda in forum New To JavaReplies: 1Last Post: 11-20-2009, 07:58 PM -
MoneyOut.println("It took you (whats wrong?>",year,"<WW?) years to repay the loan")
By soc86 in forum New To JavaReplies: 2Last Post: 01-24-2009, 06:56 PM -
"source not found" at debug time when creating new class
By rafamd11 in forum New To JavaReplies: 0Last Post: 11-22-2008, 01:49 AM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks