Why System.out.println not PrintStream.println ?

Hi, just a beginner question
I just wonder why should we use System.out.println, not PrintStream.println ?
the field out in the System class is the instance of PrintStream class, isn't it?
So why don't we just use the PrintStream class directly?
Thanks..
Edited by: riff_almighty on Oct 27, 2007 3:27 AM

According to the api:
A PrintStream adds functionality to another output stream, namely the ability to print representations of various data values conveniently. Two other features are provided as well. Unlike other output streams, a PrintStream never throws an IOException; instead, exceptional situations merely set an internal flag that can be tested via the checkError method. Optionally, a PrintStream can be created so as to flush automatically; this means that the flush method is automatically invoked after a byte array is written, one of the println methods is invoked, or a newline character or byte ('\n') is written.
So there is nowhere mentioned about the PrintStream associated with the user console. System.out is the one instance of PrintStream which is associated with the console...
Also println() is not a static method and cant be called upon the class...
Edited by: VijayBabu on Oct 27, 2007 12:51 AM

Similar Messages

  • Why System.out.println() is ok but System.out.print(); ?

    why System.out.println() is ok but System.out.print();?
    if i leave empty between parantheses in print .compiler gives error but println() doesnt?

    gimbal2 wrote:
    Think about it for a moment. What would System.out.print() do without any parameters? What CAN it do?That's easy: print() COULD behave like println() without writing a newline at the end ;)
    But I agree with Kayaman and Ram: javadoc is very nice, you simply have to read it.

  • System.out will not flush before input

    Hello everyone,
    I am using Netbeans 5.5, JDK6, and J2EE. I am new to the environment so I wrote a test application that would prompt a user to enter a string and then echo it. I have:
    String str = "";
    BufferedReader br = new BufferedReader(new nputStreamReader(System.in));
    System.out.print("Enter a string: ");
    System.out.flush();
    try
    str = br.readLine();
    catch(IOException ex)
    System.out.print(ex.toString());
    System.out.print(str);
    What is really bizarre is that System.out will NOT flush no matter what. My application will always ask for input before it even prompts the user for the string. This is what the output looks like when running:
    init:
    deps-jar:
    compile:
    run:
    hello
    Enter an string: hello
    BUILD SUCCESSFUL (total time: 5 seconds)
    Notice how I had to enter the string first? The only way that I have seen that it flushes is if I used println() instead of print. But what if I don't want the prompt to have an end line in it. This just seems like weird behavior. Also, I have tried using a Scanner for input and the results are the same. Not really sure what to do. Any help would be most appreciated. Thanks.

    are you running this inside netbeans as well? the "console" view in netbeans (and eclipse, and probably other IDEs) is not a real console, it's a GUI component that the IDE writes to. it's behaviour isn't guaranteed to act like a real console. I've seen this sort of thing on eclipse before, but never used netbeans. but it still stands that an IDE's console view isn't an actual console/terminal window. that may well be the root of the problem

  • Tomcat 4.0.1 on Linux, system.out.prinln() not working

    I recently installed Tomcat 4.0.1 on RH Linux 7.2 and I am trying to develop some servlet- and JSP-based applications. I've set up everything according to the instructions, however, I'm finding that when I put a system.out.println(somestring) statement in my servlet and I have a console window open, nothing is printed out on the command line.
    In the past when I was using Tomcat 3.1 that was not a problem.
    Thanks,
    Ethan

    err. did you check "catalina.out" in the logs
    directory ?
    rahulOK, I just did, and there's the output from my print statements. I didn't know that's where standard output goes. Thanks for the information.
    Ethan

  • Why System.out.println("joint"+3) can work?

    When add another object MyObject to a String,it will append MyObject.toString to the String. But for 3(a primary type,int) ,is not an obect ,and have not corresponding toString method.Then how this work?How "joint"+3 to be compiled?

    It's magic.
    For poorly defined operations (i.e. those not specified in the Java Language Specification Version 2 section 15.18.1.1), the compiler tries to guess what you are trying to do, and then kind of randomly decides what the best guess is and goes with that.

  • Unicode in System.out.println()

    Hello All,
    Can somebody help me figure out why the following code prints '?'.
    import java.io.*;
    class Test {
    public static void main(String args[]) throws Exception {
    System.out.println("\u0080");
    PrintWriter aPrintWriter = new PrintWriter(System.out);
    aPrintWriter.write("\u0080");
    aPrintWriter.flush();
    What needs to be done to get the actual character that is expected.
    Nischal

    Can somebody help me figure out why the following code
    prints '?'. It's because of the character set of your console.
    System.out is a PrintStream which works with bytes not with characters.
    You can use
    OutputStreamWriter osw = new OutputStreamWriter(System.out, "ISO-8859-1")
    PrintWriter myPrintWriter = new PrintWriter( osw);
    myPrintWriter.write( "\u0080");of course you'll have to use the character set your console uses.

  • System.out.printf problem

    I keep getting an error message when I type in
    System.out.printf(celsius / 5 = (fahrenheit - 32 ) / 9);
    the error keeps pointing at the first /, stating that its an unexpected type?
    How do i fix this?

    RizwanMportal wrote:
    There is System.out.print()
    and
    System.out.println()
    Do not try printf .... I think you are still in C...Since System.out is a PrintStream object, and since PrintStream has a printf method, which is wrong, the API or you Rizwan?
    see:
    http://java.sun.com/javase/6/docs/api/java/io/PrintStream.html#printf(java.lang.String,%20java.lang.Object...)

  • System Update 5 not detecting drivers for M92P (2988-A6U)

    I've installed our corporate image (Windows 7 SP1 - 64bit) which has an older network driver installed. 11.12.36.0
    The latest driver from Lenovo's web site is 11.15.16.0 which installs without a problem.
    So i re-imaged again with the older driver 11.12.36.0 and figured that the easiest way to update the driver(s) would be to use System Update 5. 
    To my surprise when i ran system update it returns the following:
    "No packages applicable to your system were found"
    No i know i could just fix the image and install the driver during the image process but I want to use System Update.
    Does anybody have a clue as to why System Update is not detecting the needed drivers?
    Has anybody had any success with running System Update 5 on a Windows 7 sp1 64-bit machines?
    Thanks-

    Unfortunately right now it appears that the 11.15.16.0 version of that driver does not have TVSU support yet.  Once the content team completes the process of creating and testing the package through TVSU, it will be published for customers.  I'll try to find out where this one falls in the queue. Sorry for the inconvenience.

  • Is it possible to redirect System.out and System.in for a thread

    I would like to run two threads. One should keep writing to System.out and System.in. The other thread output written to System.out and System.in shoudl be captured and written to a file. Is this possible? I don't think so, but perhaps someone know some workaround.
    rasped

    hmmm sure it's possible. You can write an outputstream that does different things depending on which thread is running, and then set system.out to a printstream that writes to that outputstream.

  • Is it possible not to use System.out.println?

    Hi guyz,
    Can anyone tell me if there is a way not to use System.out.println but produce the output on the command prompt? I need to add two numbers which are accepted through the args(command prompt). I have to add them and show them on command prompt without using System.out.println. Can ANYONE HELP?

    Hi guyz,
    Can anyone tell me if there is a way not
    s a way not to use System.out.println but produce the
    output on the command prompt? I need to add two
    numbers which are accepted through the args(command
    prompt). I have to add them and show them on command
    prompt without using System.out.println. Can ANYONE
    HELP?Why can't you use System.out.println? What's the reason?
    Kaj

  • Why we use logger instead of System.out.println for debugging?

    Hi,
    why we use logger instead of System.out.println for debugging?
    Regard
    Sankar

    Ya Basha,
    good question....
    You can use the idoc method to transfer the data when you are having an interface between the sap system and the legacy system......
    All the times BDC is not preferable like take the case you developed on upload program with bdc after some days your company thought to go for upgrade the sap vesion from lower version to upper version... in that upgraded version the application may change like sequence of fields or screens at that time you previous bdc program will not work here so u have to develop a new program and and you have to take the things into consideration again...
    where as if you use bapi or idoc method it will support the upgradations...
    in the case of bdc you have to take the data into flat files.... and then upload it to sap system after all the validations done some times the data which is in the flat file is confidential so there is no security if u take such data in flat file any user can chang the data even though if u maintain the data in application server super user can change the data
    where is idoc is fully secured... you can easily establich the interface between the systems and once it is done you can transfer the data with full security because idoc r generated by a program... so there is no manual interaction.....
    I think i gave some useful answer to you
    ~~Guduri

  • 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!

  • 32-bit JDK 7 System.out.println not working in IDE

    Hi folks,
    I have a 64-bit Windows 7 OS.
    Due to 3rd party library/jar dependencies, i had to install the 32-bit Java JDK 1.7 and Eclipse IDE.
    I also installed NetBeans.
    So i have a 64-bit OS and am running 32-bit Java JDK/JRE & IDEs.
    The problem I am having is that my program's System.out.println("...") statements are not outputting strings to either IDE debug console.
    Executing the compiled program from a command line/prompt produces the expected string output.
    The basic "Hello, World" program is enough to cause this behaviour to start occurring.
    I have not manually / intentionally changed any IDE-specific Debug Console or Windows environment settings.
    One caveat: This same environment has worked successfully in the past ?! Yes, this is one of those "..it worked last week & yesterday and today it isn't and i swear i didn't do anything..." issue.
    Thoughts ?

    Thanks for the reply.
    The 64-bit versions of Java & Eclipse were installed first.
    When i discovered I had to use the 32-bit versions, i un-installed the 64-bit ones & installed the 32-bits.
    Even after that initial un-install 64-bit/install 32-bit process, it was working.
    I have also been installing the Windows 7 64-bit OS updates when i am informed of them.
    I'm not sure if any of these would affect how the Eclipse / NetBeans IDEs behave.
    Behaviour has been inconsistent.
    Initially it was always working.
    But over the past several days, it has been working less and less.
    I don't have any large data structures.
    This isn't a large complicated program, couple hundred lines, so i highly doubt that i'm doing anything to the resources, but something has changed.
    The main project I am working on takes command line parameters, does some initial processing, produces output using System.out.printlns [SOP] then depending on the parameters, branches into 2 different processing paths, let's call them A & B. Each of these processing paths also use SOPs. When i run the program in the IDE going thru path A, sometimes the initial SOP statements will work and the SOP statements specific to path A will also work. If i immediately change the parameters to go thru path B & re-run it, not even the initial SOP statements before the branching decision work.
    I've tried doing System.flush()s too - no affect.
    I haven't tried the re-direction option to a file option you mentioned yet.
    It always works from a command prompt - that is telling me that the Java SOPs are working properly, correct ?
    Inside an Eclipse or NetBeans IDE, SOP output to the debug console is inconsistent.
    Running from a command prompt, the SOPs always work.
    It'd help to know if this an IDE issue, a Java issue, a Windows 7 issue so i can narrow down where to try and correct the situation.
    I have a Windows XP VM set up, i'll try running the program there and see if there's a difference.
    Thanks for your reply.

  • System.out.println () is not working properly

    Hi, Why does this happens:
    Object temp=null;
    System.out.println ("temp is null? "+temp==null);
    just prints: true
    expected: temp is null? true
    Why does this happens????
    If I do System.out.println ("temp is null? "+(temp==null)); it works bu it should work without the pharentesis too

    MelGohan wrote:
    Hi, Why does this happens:
    Object temp=null;
    System.out.println ("temp is null? "+temp==null);
    just prints: trueThat is odd, mine prints "false".
    type Test126.java
    public class Test126 {
        public static void main(String[] args) {
            Object temp=null;
            System.out.println ("temp is null? "+temp);
            System.out.println ("temp is null? "+temp==null);
    }javac Test126.java
    java Test126
    temp is null? null
    false

  • System.out.println not working in Tomcat-4.1.x

    System.out.println not working in Tomcat-4.1.24. Any settings has to be enabled??? I am using tomcat for Solaris

    I think u can use ServletContext.log() to output info instased.

Maybe you are looking for

  • Oracle 8i: Business Days Calculation in a Subquery

    To Whom It May Concern: I apologize if this has been posted already, but I didn't find any threads that address my issue: I need to find the number of business days between 2 dates (excludes weekends) provided by dates from an outer query such as the

  • Question on event object

    In the official flex tutorial. They called a function and passed in the event object, but they never used that object in that function. Why is that? I have realized several times in Day1 and Day2 tutorials. Here is the tutorial video: Link Here is pa

  • Resetting original Mac Mini Owner Information

    HI Gents; Bought a slightly used (2 Month Old ) Mini and so far love it. Question... is there a way to re enter "new owner" info.. and elminate the original owners names and entries.? Owner was not sure. Front row comes up wsith "Joe blows Mini" etc.

  • HT1848 Is it possible to do a one-way sync?

    We have several iPads that we loan out. When they are returned, I would like an easy way to quickly remove any apps they have installed and take the iPad back to our standard configuration.  Currently, when I sync, everything on the iPad is transferr

  • Time entries booked against network & activity are not transferring to PS

    Hi every one, We have scheduled a job to transfer time entries which were booked against network & activity on daily basis,  but for some reason the time entries are not getting posted against the network (Only for certain network, see attachment), t