Java Printing

beginner40 min

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

Program structure

A runnable Java program lives in a class and starts in main.

Complete Java 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: System must be spelled exactly that way.

Multiple lines and comments

Printing habits

Good Practices:

  • Use meaningful text in your print statements
  • Add comments to explain your code
  • Use the sout shortcut in IDEs (type ‘sout’ + Tab)
  • One command per line for readability

Avoid:

  • Forgetting semicolons at the end of statements
  • Misspelling println as printin
  • 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.