Example Application: prints
There is no line break.
System.out.print("Simple Print - Hello World\n");
It has line break.
System.out.println("Simple Println - Hello World");
Format Specifier: %d
System.out.println("Print Number: " + 999);
Format Specifier: %d
System.out.println("Print Long: " + 10L);
Format Specifier: %c
char c = 'A';
System.out.println("Print Char: " + c);
Format Specifier: %s
System.out.println("Print String: " + "String Value");
Person person = new Person();
person.setName("Name");
person.setAge(30);
System.out.println("Print Class Model: " + person.toString());
Use format specifier to replace with variable.
String format = "Custom Format: [Number: %d] - [Text: %s] - [Person Name: %s, Person Age: %d]";
Object[] params = new Object[] { 999, "Simple text", person.getName(), person.getAge() };
System.out.println(String.format(format, params));
Use format specifier to replace with variable.
String format = "Custom Format: [Number: %d] - [Text: %s] - [Person Name: %s, Person Age: %d]";
Object[] params = new Object[] { 999, "Simple text", person.getName(), person.getAge() };
System.out.printf(format, params);
See Java - Stringformat Specifiers
Format Specifier: %t
Date date = new Date();
System.out.println("Date: "+ date);
SimpleDateFormat dateFormatBR = new SimpleDateFormat("dd/MM/yyyy - hh:MM:ss");
System.out.println("Date BR: "+ dateFormatBR.format(date));
System.out.println("Insert Text Here: ");
Scanner in = new Scanner(System.in);
String text = in.nextLine();
System.out.println("Keyboard text: " + text);