Java Printing
Basic printing
System.out.println() sends a line of text to the console. It is usually the first output statement you learn.
Simple print example
System.out.println("Hello world!");
System.out.println("Welcome to Java programming!");
// Output:
// Hello world!
// Welcome to Java programming!Program structure
A runnable Java program lives in a class and starts in main.
Complete Java program
public class MyProgram {
public static void main(String[] args) {
// Your code goes here
System.out.println("Hello from Java!");
System.out.println("This is my first program");
}
}Key ideas
- Argument: The string inside the parentheses is what gets printed.
- Semicolon: Each statement ends with
;. - Quotes: Text literals use double quotes
"...". - Capitalization:
Systemmust be spelled exactly that way.
Multiple lines and comments
public class Example {
public static void main(String[] args) {
// Single-line comment
System.out.println("First line");
System.out.println("Second line");
/* Multi-line comment
for longer explanations */
System.out.println("Third line");
}
}Printing habits
Good Practices:
- Use meaningful text in your print statements
- Add comments to explain your code
- Use the
soutshortcut in IDEs (type ‘sout’ + Tab) - One command per line for readability
Avoid:
- Forgetting semicolons at the end of statements
- Misspelling
printlnasprintin - Missing quotation marks around text
- Writing everything on one line
Try It Yourself:
Exercise 1: Basic Printing
- Write a program that prints your name
- Print your favorite programming quote on multiple lines
- Add comments explaining what each print statement does
- Try the ‘sout’ shortcut if you’re using an IDE
Practice with these printing exercises in your IDE or in the Mantik editor on earlier examples on this page.
Printing in FRC
On the robot, System.out.println goes to the driver station console. It is a quick way to see numbers while tuning without opening Elastic or AdvantageScope.
FRC console printing example
System.out.println("********** Drive FF Characterization Results **********");
System.out.println("\tkS: " + formatter.format(kS));
System.out.println("\tkV: " + formatter.format(kV));
The \t inserts a tab so columns line up. Concatenating with + turns numbers into strings for display. For match play you will usually prefer structured logging; println is still useful during bring-up.