Java.io.Printstream Class in Java | Set 2 Last Updated : 01 May, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report Java.io.Printstream Class in Java | Set 1More Methods: PrintStream printf(Locale l, String format, Object... args) : A convenience method to write a formatted string to this output stream using the specified format string and arguments. Syntax :public PrintStream printf(Locale l, String format, Object... args)Parameters:l - The locale to apply during formatting. If l is null then no localization is applied.format - A format string as described in Format string syntaxargs - Arguments referenced by the format specifiers in the format string.Returns:This output streamThrows:IllegalFormatException NullPointerException Java //Java program to demonstrate printf method import java.io.*; import java.util.Locale; class PrintStreamDemo { public static void main(String[] args) { String s = "for"; // create printstream object PrintStream printStream = new PrintStream(System.out); // illustrating printf(Locale l, String format, Object... args) method printStream.printf(Locale.US, "Geeks%sGeeks", s); } } Output:GeeksforGeeksPrintStream printf(String format, Object... args) : A convenience method to write a formatted string to this output stream using the specified format string and arguments. Syntax :public PrintStream printf(String format, Object... args)Parameters:format - A format string as described in Format string syntaxargs - Arguments referenced by the format specifiers in the format string.Returns:This output streamThrows:IllegalFormatException NullPointerException Java //Java program to demonstrate printf(String format, Object... args) method import java.io.*; public class PrintStreamDemo { public static void main(String[] args) { String s = "for"; // create printstream object PrintStream obj= new PrintStream(System.out); // illustrating printf(String format, Object... args) method obj.printf("Geeks%sGeeks", s); } } Output:GeeksforGeeksvoid println(): Terminates the current line by writing the line separator string. Syntax :public void println() Java //Java program to demonstrate println() methods import java.io.PrintStream; class PrintStreamDemo { public static void main(String[] args) { PrintStream obj = new PrintStream(System.out); //illustrating println(); obj.println("GeeksforGeeks"); } } Output:GeeksforGeeksvoid println(boolean x): Prints a boolean and then terminate the line. Syntax :public void println(boolean x) Java //Java program to demonstrate println(boolean) method import java.io.*; class PrintStreamDemo { public static void main(String[] args) { // create printstream object PrintStream obj = new PrintStream(System.out); //illustrating println(boolean) method obj.println(true); // flush the stream obj.flush(); } } Output:truevoid println(char x): Prints a character and then terminate the line. Syntax :public void println(char x) Java //Java program to demonstrate println(char x) method import java.io.*; public class PrintStreamDemo { public static void main(String[] args) { char c = 'g'; // create printstream object PrintStream obj = new PrintStream(System.out); // illustrating println(char x) obj.println(c); // flush the stream obj.flush(); } } Output:gvoid println(char[] x): Prints an array of characters and then terminate the line. Syntax :public void println(char[] x) Java //Java program to demonstrate println(char[] x) method import java.io.*; public class PrintStreamDemo { public static void main(String[] args) { char[] c = {'G', 'E', 'E','K'}; // create printstream object PrintStream obj = new PrintStream(System.out); // illustrating println(char[] x) obj.println(c); // flush the stream obj.flush(); } } Output:GEEKvoid println(double x): Prints a double and then terminate the line. Syntax :public void println(double x) Java //Java program to demonstrate println(double x) method import java.io.*; public class PrintStreamDemo { public static void main(String[] args) { double c = 5.42762; // create printstream object PrintStream obj = new PrintStream(System.out); // illustrating println(double x) obj.println(c); // flush the stream obj.flush(); } } Output:5.42762void println(float x): Prints a float and then terminate the line. Syntax :public void println(float x) Java //Java program to demonstrate println(float x) method import java.io.*; public class PrintStreamDemo { public static void main(String[] args) { float c = 5.168502f; // create printstream object PrintStream obj = new PrintStream(System.out); // illustrating println(float x) obj.println(c); // flush the stream obj.flush(); } } Output:5.168502fvoid println(int x): Prints an integer and then terminate the line. Syntax :public void println(boolean x) Java //Java program to demonstrate println(int x) method import java.io.*; public class PrintStreamDemo { public static void main(String[] args) { int c = 5; // create printstream object PrintStream obj = new PrintStream(System.out); // illustrating println(int x) obj.println(c); // flush the stream obj.flush(); } } Output:5void println(long x): Prints a long and then terminate the line. Syntax :public void println(long x) Java //Java program to demonstrate println(long x) method import java.io.*; public class PrintStreamDemo { public static void main(String[] args) { long c = 123456789l; try { // create printstream object PrintStream obj= new PrintStream(System.out); // illustrating println(long x) obj.println(c); // flush the stream obj.flush(); } catch (Exception ex) { ex.printStackTrace(); } } } Output:123456789void println(Object x) :Prints an Object and then terminate the line. Syntax :public void println(Object x) Java //Java program to demonstrate println(Object x) method import java.io.*; public class PrintStreamDemo { public static void main(String[] args) { // create printstream object PrintStream obj = new PrintStream(System.out); //illustrating println(Object X) obj.println(obj); // flush the stream obj.flush(); } } Output:java.io.PrintStream@15db9742void println(String x) :Prints a String and then terminate the line. Syntax :public void println(boolean x) Java import java.io.*; //Java program to demonstrate println(String x) method public class PrintStreamDemo { public static void main(String[] args) { String c = "GeeksforGeeks"; // create printstream object PrintStream ps = new PrintStream(System.out); // illustrating println(String x) ps.println(c); // flush the stream ps.flush(); } } Output:GeeksforGeeksprotected void setError() :Sets the error state of the stream to true. Syntax :public void println(String x) Java //Java program to demonstrate setError() method import java.io.*; public class PrintStreamDemo extends PrintStream { public PrintStreamDemo(OutputStream out) { super(out); } public static void main(String[] args) { byte c[] = {65, 66, 67, 68, 69, 70, 71}; // create printstream object PrintStreamDemo obj = new PrintStreamDemo(System.out); // illustrating write() method obj.write(c, 1, 3); // flush the stream obj.flush(); //illustrating setError() method obj.setError(); } } Output:BCDvoid write(byte[] buf, int off, int len) :Writes len bytes from the specified byte array starting at offset off to this stream. Syntax :public void write(byte[] buf, int off, int len)Overrides:write in class FilterOutputStreamParameters:buf - A byte arrayoff - Offset from which to start taking byteslen - Number of bytes to write Java //Java program to demonstrate write(int b) method import java.io.*; public class PrintStreamDemo { public static void main(String[] args) { byte c = 65; // create printstream object PrintStream obj = new PrintStream(System.out); //illustrating write(int b) obj.write(c); // flush the stream obj.flush(); } } Output:BCDvoid write(int b) :Writes the specified byte to this stream. Syntax :public void write(int b)Overrides:write in class FilterOutputStreamParameters:b - The byte to be written Java //Java program to demonstrate write(int b) method import java.io.*; public class PrintStreamDemo { public static void main(String[] args) { byte c = 65; // create printstream object PrintStream obj = new PrintStream(System.out); //illustrating write(int b) obj.write(c); // flush the stream obj.flush(); } } Output:A Comment More infoAdvertise with us Next Article Java.io.Printstream Class in Java | Set 2 C ChippingEye2766 Improve Article Tags : Java Practice Tags : Java Similar Reads Java Tutorial Java is a high-level, object-oriented programming language used to build web apps, mobile applications, and enterprise software systems. It is known for its Write Once, Run Anywhere capability, which means code written in Java can run on any device that supports the Java Virtual Machine (JVM).Java s 10 min read Java OOP(Object Oriented Programming) Concepts Java Object-Oriented Programming (OOPs) is a fundamental concept in Java that every developer must understand. It allows developers to structure code using classes and objects, making it more modular, reusable, and scalable.The core idea of OOPs is to bind data and the functions that operate on it, 13 min read Java Interview Questions and Answers Java is one of the most popular programming languages in the world, known for its versatility, portability, and wide range of applications. Java is the most used language in top companies such as Uber, Airbnb, Google, Netflix, Instagram, Spotify, Amazon, and many more because of its features and per 15+ min read Arrays in Java Arrays in Java are one of the most fundamental data structures that allow us to store multiple values of the same type in a single variable. They are useful for storing and managing collections of data. Arrays in Java are objects, which makes them work differently from arrays in C/C++ in terms of me 15+ min read Collections in Java Any group of individual objects that are represented as a single unit is known as a Java Collection of Objects. In Java, a separate framework named the "Collection Framework" has been defined in JDK 1.2 which holds all the Java Collection Classes and Interface in it. In Java, the Collection interfac 15+ min read Inheritance in Java Java Inheritance is a fundamental concept in OOP(Object-Oriented Programming). It is the mechanism in Java by which one class is allowed to inherit the features(fields and methods) of another class. In Java, Inheritance means creating new classes based on existing ones. A class that inherits from an 13 min read Java Exception Handling Exception handling in Java allows developers to manage runtime errors effectively by using mechanisms like try-catch block, finally block, throwing Exceptions, Custom Exception handling, etc. An Exception is an unwanted or unexpected event that occurs during the execution of a program, i.e., at runt 10 min read Java Programs - Java Programming Examples In this article, we will learn and prepare for Interviews using Java Programming Examples. From basic Java programs like the Fibonacci series, Prime numbers, Factorial numbers, and Palindrome numbers to advanced Java programs.Java is one of the most popular programming languages today because of its 8 min read Java Interface An Interface in Java programming language is defined as an abstract type used to specify the behaviour of a class. An interface in Java is a blueprint of a behaviour. A Java interface contains static constants and abstract methods. Key Properties of Interface:The interface in Java is a mechanism to 12 min read Introduction to Java Java is a high-level, object-oriented programming language developed by Sun Microsystems in 1995. It is platform-independent, which means we can write code once and run it anywhere using the Java Virtual Machine (JVM). Java is mostly used for building desktop applications, web applications, Android 4 min read Like