This post originated from an RSS feed registered with Java Buzz
by instanceof java.
Original Post: Java example program to print message without using System.out.println()
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
System.out.format("format",Object obj) by using this method we can format the text and print
package com.instanceofjava;
public class PrintMessage {
public static void main(String[] args){
System.out.format("%s", "James");
}
}
Output:
James
3. FileDescriptor:
Create PrintStream object by passing FileOutputStream(FileDescriptor.out) object as an argument to the constructor
package com.instanceofjava;
public class PrintMessage {
public static void main(String[] args){
PrintStream myout = new PrintStream(new FileOutputStream(FileDescriptor.out)); myout.print("i love Java");
}
}
Output:
i love java
4. System.err.print(""):
We can use System.err.print("") method to print the message actually its used to print error message
package com.instanceofjava;
public static void main(String[] args){
System.err.print("This is custom error message");
}
}
Output:
This is custom error message
5.System.console().writer().println("");
System.console() returns null if your application is not run in a terminal System.console() provides methods for reading password without echoing characters
package com.instanceofjava;
public static void main(String[] args){
System.err.print("This is custom error message");
}
}
Output:
This is custom error messageException in thread "main" java.lang.NullPointerException at PrintMessage.main(PrintMessage.java:24)