This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mock exam question doubt?

 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,



The question above is from David Bridgewater and the answer is given as E. I thought C?? won't the System.out.println write to the server console (log)???
 
Srinivasan thoyyeti
Ranch Hand
Posts: 557
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shankar,

System.out.println will write output to standard output device.

For logging purpose: you need to use ServletContext.log() method.
 
Sergio Tridente
Ranch Hand
Posts: 329
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think E is the correct answer.

Note that the example is using two kind of scripting elements: declarations (<%! %> and scriptlets (<% %> . The Date code is part of a scriptlet block, so it will be put inside the _jspService method during translation. The other two blocks are declarations, which means they will be put outside the _jspService method. What is more, those two blocks are declaring a jspInit method, which will be run only once during servlet initilization (that's why the second time you'll see no output in the log).

I hope I made myself clear.

PS: I am copying my response from the other thread + some corrections to try to make it clearer.
[ April 23, 2007: Message edited by: Sergio Tridente ]
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Srinivasan,

As you say the System.out.println() methods outputs to the tomcat console and it is not the same as log. Am I right?
 
Khaled Mahmoud
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Sergio, the answer should be E. Regarding the
System.out.println, it prints to a text file inside the logs directory of the tomcat. If you are using an IDE like Netbeans, this text will appear in an output window too.
[ April 23, 2007: Message edited by: Khaled Mahmoud ]
 
Aniket Patil
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As you say the System.out.println() methods outputs to the tomcat console and it is not the same as log. Am I right?


Depends on the version of Tomcat used. Some output to the console, other to a text file.
 
Aniket Patil
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As you say the System.out.println() methods outputs to the tomcat console and it is not the same as log. Am I right?


Depends on the version of Tomcat used. Some output to the console, others to a text file.
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using an IDE and it outputs to the console!
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many IDE's many confusions
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic