Which toString() method does System.out.println() call?
Which toString() method does System.out.println() call? I know that if I did something like System.out.println( new myClass() ) that the toString being called would be that of the myClass class.
My initial thought about this was that System.out.println() is the equivalent of System.out.println( new Object() ) but I remember trying that in a test program and it gave me a myClass@some_hash_code type of message when adding the new Object() part within the System.out.println().
Could someone please tell me which toString the System.out.println() statement calls? Also, it would be great if an elaboration follows :).
Any input woudl be greatly appreciated!
Thanks in advance!
s3a wrote:
My initial thought about this was that System.out.println() is the equivalent of System.out.println( new Object() ) Huh?
In one method call you pass no parameters in the other method call you pass one parameter. How could you possibly think that they would do the same thing?
Could someone please tell me which toString the System.out.println() statement calls? Also, it would be great if an elaboration follows :).Yes. The toString of the class of the object which you pass to the method. If that class does not have a toString method it uses the toString method it inherits from the parent class. If the parent class does not have a toString method it uses the one inherited and so and so on all the way up to the Object class.
Similar Messages
-
Intercepting System.exit() and System.out.println() calls
hi there,
I have often problems when working with code that uses System.exit() and System.out.println() extensively, because it becomes difficult to debug.
Basically I do have wrappers for System.exit() (my own static exit function) and for System.out.println() (log4j).
Still not all programmers are using these methods; Probably the only way to enforce this is some kind of code warrior, but I was hoping to be able to intercept the two System.XXX calls (and throw an appropriate Exception). is this possible ??Why not simply make your own security manager andhandle checkExit() and checkWrite?
Does anyone have a simple example of this? Please?System.exit() can be intercepted using a security manager, but not System.out.xxx.
Here is a short example:
//set your security manager
static{
SecurityManager s = new OwnSecurityManager();
System.setSecurityManager(s);
//redirect the out stream
try{
PrintStream ps = new PrintStream(new FileOutputStream("output.txt"));
System.setOut(ps);
}catch(IOException ioe){
ioe.printStackTrace();
//some tests
System.out.println("Test");
System.exit(2);
//your security manager
class OwnSecurityManager extends SecurityManager{
public void checkExit(int code){
if(code > 0){
super.checkExit(code);
throw new SecurityException("Not allowed here->" + code);
public void checkRead(FileDescriptor fd){
public void checkRead(String file){
public void checkRead(String file, Object context){
public void checkPermission(Permission perm){
if(perm.getName().equals("exitVM")){
System.out.println("exitVM");
} -
How does System.out.println(). Work inside src.zip file !
Hello guyz,
I was just wondering how System.out.println() worked so i opened up the src.zip file and checked the source code. But could not understand it. As written i remember
"out is an object encapsulated in the System class."
Thats ok. But i could not understand the code.
public final static PrintStream out = nullPrintStream();
private static PrintStream nullPrintStream() throws NullPointerException {
if (currentTimeMillis() > 0) {
return null;
throw new NullPointerException();
}Also when i ran the DJ Decompiler it decompiled it to this:
public class One
public static void main(String args[])
System.out.println("hello world");
import java.io.PrintStream;
public class One
public One()
public static void main(String args[])
System.out.println("hello world");
}Also, why does it need to import PrintStream ?Peter__Lawrey wrote:
I was just wondering how System.out.println() worked so i opened up the src.zip file and checked the source code.This value is a place holder. This value is changed as soon as enough of the JVM is initialised for printing to work.
Also, why does it need to import PrintStream ? It doesn't, but it is used in the code so DJ is including it just in case.Sorry,
But i don't understand at all. -
Where does System.out.println go?
Hi Everyone: I know I've seen this topic before, but I'm still having some trouble. I would like to debug my EJBs, and so I've added some System.out.println statements to them. Where does that go? I've looked at the defaultTrace.trc files in the
C:\usr\sap\P48\JC00\j2ee\cluster\server0\log
folder, and haven't found any of the text that I think I am writing. I appreciate any guidance! Ian.Hi lan,
I was facing the same question earlier, and now I think I have figured out one possible answer. Actually, where the System.out.println goes is up to the Server Admin to config. There is a default SYSTEM.OUT log controller ( under location controller side) pre-defined to cater for all System.out.println(). All the System.out.println() output is considered as INFO type log message. However, this default SYSTEM.OUT controller is not assigned with any real log destination, thus, we cannot find the output anywhere.
If you goes to the log configurator (using Visual Admin), you can locate this SYSTEM.OUT controller , and add in a default (Anonymous) destionation for it . (you need to toggle on the advance edit mode from the top menu , then you can add modify the destination settings of a Controller).
For Anonymous destionation, the println() output will sure go to the defaultTrace.trc (better view it using Log Viewer, instead of viewing it from the log file ).
Or , you can define a separate file (e.g. c:\temp\myStd.log ) as the log destination ..
Last but not the least, you need to set the ForceSingleTraceFile setting from 'YES' to 'NO' , then you can see your "myStd.log".
To change the ForceSingleTraceFile , go to Visual Admin, J2EE server --> Kernel --> LogManager.
Hope you find the above useful. -
Does System.out.println() has a limit ?
I have this little program that permuates strings
public class PermutationGenerator
private void perm(String s, String prefix)
int length = s.length();
if (length== 0)
System.out.println(prefix);
else
for (int i = 0; i < length; i++)
perm(s.substring(0, i) + s.substring(i+1, length), prefix + s.charAt(i));
public void printPermutations(String s)
perm(s,"");
public static void main(String[] args)
new PermutationGenerator().printPermutations("word") ;
The problem is that when I use a longer string like "longword", I only get 299 different permutations printed. Even if I use an "evenlongerword", I will get 299 permutations. Is this because of java? Because I can't see any errors in my code.You probably need to change your command prompt
screen buffer size. Sounds like you have the height
set to 300 lines. You can also redirect your output
to a file to see everything.Very well spotted! The voice of experience! -
Hello,
the code below:
if(System.console()!=null)
outStream=System.out;
else
outStream=new PrintStream(new FileOutputStream(new File("BasicCardReaderManagerLog.log")));
outStream.println(System.currentTimeMillis());
outStream.println(System.out.toString());produce the following output, in the BasicCardReaderManagerLog.log file:
1249991451796
java.io.PrintStream@190d11
So it looks like System.out is valid and usable, however, since the application as no console, where I can see the output ???
Precision: I get this situation in the main function of a console application which I launch using Process.Start. Is there any way to get a console by this mean ?
Best regards,
SebastienBased on [http://forums.sun.com/thread.jspa?messageID=10790600#10790600|http://forums.sun.com/thread.jspa?messageID=10790600#10790600]
import java.util.*;
public class Java {
public static void main(String[] arg) throws Exception {
String[] cmd = { "cmd.exe", "/C", "start", "java.exe" };
List<String> l = new ArrayList<String>(Arrays.asList(cmd));
l.addAll(Arrays.asList(arg));
cmd = l.toArray(cmd);
Process p = Runtime.getRuntime().exec(cmd);
} -
Where does System.out.println("") send info?
Under normal java execution it goes to the java console... where does it go when running a servlet under Tomcat on localhost?
Output is written to the log file whose location is specified in server.xml. The default is the /logs directory under the tomcat root.
-
System.out.println in which log file
We are using weblogic 51 server.
We have System.out.println's in the servlets but don't see
it in any log file. Which log file would/should
it go to.
If you are running a shell script (not as as service) you will see it in
that shell window, if you run it without a console window (service), you
usually see nothing.
If you are using a third party tool to run the server as a service (e.g.
ServiceMill for Win2k/NT) you usually can set files where you would like
your output to be redirected.
If you run the server as a service and don't have this option you can do
it yourself by setting System.setErr / System.setOut, e.g. in a
startup-class
Daniel
-----Ursprüngliche Nachricht-----
Von: smita [mailto:[email protected]]
Bereitgestellt: Mittwoch, 6. Juni 2001 18:54
Bereitgestellt in: servlet
Unterhaltung: System.out.println in which log file
Betreff: System.out.println in which log file
We are using weblogic 51 server.
We have System.out.println's in the servlets but don't see
it in any log file. Which log file would/should
it go to.
-
System.out.println crashes wireless toolkit
I'm using system.out.println calls to create debugging commands to test my application. They mostly work but if I try to print out a lot at once the wireless toolkit crashes.
This is all on my computer, not on any mobile device.
The error I get is:
Exception in thread "Child process stdout copier" java.lang.ClassCastException: sun.java2d.NullSurfaceData cannot be cast to sun.java2d.d3d.D3DSurfaceData
at sun.java2d.d3d.D3DRenderer.copyArea(D3DRenderer.java:55)
at sun.java2d.d3d.D3DSurfaceData.copyArea(D3DSurfaceData.java:638)
at sun.java2d.SunGraphics2D.doCopyArea(SunGraphics2D.java:1986)
at sun.java2d.SunGraphics2D.copyArea(SunGraphics2D.java:1968)
at javax.swing.BufferStrategyPaintManager.copyArea(BufferStrategyPaintManager.java:315)
at javax.swing.RepaintManager.copyArea(RepaintManager.java:1228)
at javax.swing.JViewport.blitDoubleBuffered(JViewport.java:1604)
at javax.swing.JViewport.windowBlitPaint(JViewport.java:1573)
at javax.swing.JViewport.setViewPosition(JViewport.java:1118)
at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.vsbStateChanged(BasicScrollPaneUI.java:1027)
at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.stateChanged(BasicScrollPaneUI.java:1016)
at javax.swing.DefaultBoundedRangeModel.fireStateChanged(DefaultBoundedRangeModel.java:348)
at javax.swing.DefaultBoundedRangeModel.setRangeProperties(DefaultBoundedRangeModel.java:285)
at javax.swing.DefaultBoundedRangeModel.setValue(DefaultBoundedRangeModel.java:151)
at javax.swing.JScrollBar.setValue(JScrollBar.java:446)
at com.sun.kvem.toolbar.MainWindow$ConsoleStream.write(Unknown Source)
at java.io.PrintStream.write(PrintStream.java:430)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
at com.sun.kvem.environment.StreamCopier.run(Unknown Source)
at java.lang.Thread.run(Thread.java:619)Am I doing something wrong or is this a bug in the toolkit?
Once I get this exception the whole toolkit becomes unresponsive and I have to close it and re-open.mydreamgirl, welcome to the forum. Please don't post in threads that are long dead and don't hijack another poster's thread. When you have a question, start your own topic. Feel free to provide a link to an old post that may be relevant to your problem.
I'm locking this thread now.
db -
Disable or restrict System.out.println() statements on client side
Hi All,
This might be a stupid question, but i am still going ahead and asking the question.
Is there a way to disable or restrict System.out.println() statements in applet code from executing on the client side by using settings in proxy server or firewall or other security settings.
Thanks
NagHi All,
This might be a stupid question, but i am still going
ahead and asking the question.
Is there a way to disable or restrict
System.out.println() statements in applet code from
executing on the client side by using settings in
proxy server or firewall or other security settings.
System.out.println() calls are executed on the client machine, and thus do not pass through any firewalls or proxies. If the applet is signed, you can redirect the System.out, by System.setOut(...). -
System.out.println() fn in j2me
Hello Everbody,
can anyone plz tell that if i write down System.out.println() in my j2me app(in many classes and and at many places) and use it on mobile that app, does it slows down the app after sometime,bcz i m running the app it goes good for half anhour or so, but slows down after that and gets slower and slower does "System.out.println()" affect it or do thread creates the prob,plz clearify it, if any one knows,
Thanksask it in the j2me forum
http://forum.java.sun.com/forum.jspa?forumID=76 -
How does one intercept System.out.println stream.
If you want some functionality wherein when you call System.out.println - the stream gets written to System.out AND additionally does something else (e.g. send mail).
AND
You do not want to write a new class/method to do so and replace all System.out.println in your source base with this new class/method;
Then how would you be able to achieve this. Thanks in advance.Here is the basic code, you may need to tune performance. I havent compiler or tested it, but it should give you a good idea.
public class OutputStreamCollection extends OutputStream{
private OutputStream[] outs = new OutputStream[0];
public synchronized void addOutputStream(OutputStream argOut) {
OutputStream[] old = outs;
outs = new OuputStream[old.length + 1];
System.arraycopy(old,0,outs,0, old.length);
outs[outs.length - 1] = argOut;
public syncrhonized void write(int data) {
for(int i = 0; i < outs.length; i++) {
outs.write();
public synchronized void write(byte[] data, int offset, int length) {
for(int i = 0; i < outs.length; i++) {
outs[i].write(data, offset, length);
nor the following code, will print and log to respective files whatever is going to stdout or stderr
OutpputStreamCollection out = new OutputStreamCollection();
out.addOutputStream(System.out);
out.addOutputStream(new FileOutputStream("stdout.log"));
System.setOut(out);
OutpputStreamCollection err = new OutputStreamCollection();
out.addOutputStream(System.err);
out.addOutputStream(new FileOutputStream("stderr.log"));
System.setOut(err);
you can write adapter classes to process the stream in any way you need, like logging with log4J, or sending mail depending on some crieteria.
Hope it helps. -
Is there a way to force System.out.println to run when called
I working on my first threaded program and having a hard time debugging. I've used System.out.println to let me know what's going on but due (I assume) to the nature of threads the output is not sequential. Is there a way to force println to execute immediatly so that they show up in the order they were called?
Thanks --- Mikemjs1138 wrote:
endasil, Thanks for the reply. I'm currenlty running the program from within the NetBeans IDE. It is the output displayed by in NetBeans "output" that I'm looking at.
--- MikeI don't use Netbeans, but I would guess that it too pipes Standard Out and Standard Error to the same console. You didn't address my comment. Are you printing to System.err as well? This happens implicitly if you use Exception.printStackTrace(), for example. -
System.out.println does not print out anything
I'm wonder why the dos mode does not print out the System.out.println.
My code has:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class test extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws IOException,
ServletException {
System.out.println("Hello");
The compilation is ok... but it does not display anything... how come?"System.out.print()" prints to the log file of the tomcat server. in order to print on the screen use JspWriter.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class test extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws IOException,
ServletException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Hello");
//System.out.println("Hello");
Hope this helps! -
Where does the logging happens for System.out.println
Hello:
I'm usingNetWeaver 2004sJava SP9 evaluation version. Added some System.out.println to the ejbs. Would like to know where to look for the logging details in this case.
Thanks for your help,
RaviHi,
By default, if the setting has been done, then it appears in defaultTrace as mentioned. For configuration of it, refer to this link.
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/db315878-0801-0010-928e-98c8283616d3
Reward points if it helps.
Regards,
Vijai
Maybe you are looking for
-
I have installed ACDSee Pro3 and have problem to transfer photofiles from device: I got the message; The item could not be edited because you do not have sufficent access privileges or destination volume is no longer available." What can I do?
-
Hi Gurus I have to select few accounts by Time and I want the Bas(2010.total) to be displayed by account how do i achive this for ex: account1 account2 account3 jan, feb,mar..
-
Everytime I download a movie I am required to confirm the sale on my PC
-
I have a large number of data files containing values for acoustic and vibration data from machinery. I am trying to look for distinguishing features in particular groups of files (covering certain dates) but there is a lot of random noise contained
-
WAN MTU change: impact on applications?
Has anyone made an in-production MTU change to their WAN? If so, how have the applications been impacted? Our DMVPN (enterprise site-to-site) MTU is currently set to 1400 bytes, and we're looking at dropping it by a few more. I know that new connec