Results 1 to 2 of 2
  1. #1
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    Default [SOLVED] [newbie]

    A book example...I'm trying to guess...

    public class PrintStream
    {
    public PrintStream printf(String fmt, Object... args);
    }

    1. Can I convert PrintStream to an object that I can display on screen (ahem...the default stream writer), say, using System.out.println.

    2. What values do I need to set for 'fmt'?

    :confused:

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    1. Can I convert PrintStream to an object that I can display on screen (ahem...the default stream writer), say, using System.out.println.
    System.out is a PrintStream — see Field Detail of the System class.
    2. What values do I need to set for 'fmt'?

    Here is where the javadocs (aka, documentation) become(s) useful.
    Start with Java™ Platform, Standard Edition 6. In the lower left frame find the PrintStream class, select the link and the PrintStream class api loads in the main frame. This document contains a lot of information about this class and how to use it.
    Scroll down to the Method Summary to find your two–argument printf method and follow the link to the Method Detail section.

    The Parameters section shows where to find out about this with a link into the Formatter class.
    An example:
    Java Code:
    import java.awt.Point;
    import java.io.PrintStream;
    
    public class Test {
        public static void main(String[] args) {
            PrintStream ps = new PrintStream(System.out);
            ps.println("printing with ps");
            Point p = new Point(100, 35);
            String format = "p = [%d, %d]%n";
            Object[] argsArray = { p.x, p.y };
            ps.printf(format, argsArray);
            // Explore System.out:
            System.out.printf("Is System.out a PrintStream: %b%n",
                               System.out instanceof PrintStream);
            // Use methods of the Class class.
            System.out.printf("Class name of System.out: %s%n",
                               System.out.getClass().getName());
            System.out.printf("Superclass name: %s%n",
                               System.out.getClass().getSuperclass().getName());
        }
    }

Similar Threads

  1. Another newbie
    By PhHein in forum Introductions
    Replies: 0
    Last Post: 04-22-2009, 01:26 PM
  2. Newbie Help
    By mattkid in forum New To Java
    Replies: 4
    Last Post: 03-25-2009, 04:55 AM
  3. :) newbie...........
    By Somitesh Chakraborty in forum Introductions
    Replies: 1
    Last Post: 08-19-2008, 09:00 AM
  4. newbie newbie newbie
    By krislogy in forum New To Java
    Replies: 9
    Last Post: 08-15-2008, 12:28 AM
  5. newbie needs help...
    By vicky08 in forum New To Java
    Replies: 2
    Last Post: 03-31-2008, 04:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •