Output refers to information that a program produces. It can be sent
to the user via some output device.
User Interfaces: GUIs and TUIs
Graphical User Interface - Uses visual elements to let you
interact with a program.
User Interfaces: GUIs and TUIs
Terminal user Interface - A user interface that uses text and
symbols, rather than graphical elements.
Your First Java Method System.out.println()
System.out.println() is a method that displays a message in a terminal application.
System.out.println("Are you a 1 or a 0?");
Your First Java Method System.out.println()
System.out.println() is a method that displays a message in a terminal application.
System.out.println("Are you a 1 or a 0?");
Terminal window
1
Are you a 1 or a 0?
Demo
Call System.out.println(). Write a message of your choice.
Main.java
1
publicclassMain{
2
publicstaticvoidmain(String[]args){
3
System.out.println("Hello World!");
4
}
5
}
Output
Hello World!
Comments
Write notes or disable code. Ignored by the Java compiler.
Main.java
1
publicclassMain{
2
publicstaticvoidmain(String[]args){
3
// System.out.println("Hello!");
4
System.out.println("Goodbye!");
5
}
6
}
Output
Goodbye!
Key Terms
Method
Code that performs a specific action.
Output
Information that a program produces.
Console Output
Text displayed by a program in a command-line interface, like a
terminal.
Comments
Notes written within the code that are ignored by the Java
compiler, used by to explain or clarify the code.
'F' → Fullscreen
Objectives
Writing and executing code
Displaying console output
Debugging potential syntax errors
Reading comments
Activity Tasks
Create a new Java project named 1-1-Output.
Complete each task individually.
Task 1: Write and Test
Write each line of code from the section making sure to stay within
the main method.
Run and test your project to ensure it executes as intended.
Main.java
1
publicclassMain{
2
publicstaticvoidmain(String[]args){
3
System.out.println("Welcome to the Skynest Nexus.");
4
System.out.println("This class is taught by Mr. Mortimer");
5
System.out.println();
6
//
7
}
8
}
Task 2: Add More Code
Write the additional sections of output under your current print
statements.
Run and test your project to ensure it executes as intended.
Main.java
1
publicclassMain{
2
publicstaticvoidmain(String[]args){
3
System.out.println("Welcome to the Skynest Nexus.");
4
System.out.println("This class is taught by Mr. Mortimer");
5
System.out.println();
6
7
System.out.println("What is the answer to life, the universe, and everything?");
8
System.out.println("The answer is 42.");
9
System.out.println();
10
11
System.out.println("Sally sells seashells by the seashore.");
12
System.out.println("Sally wants to invite you to invest in a money making opportunity.");
13
System.out.println();
14
15
System.out.println("If you start to feel overwhelmed, just remember:");
16
System.out.println("Mortimers don't quit, we get fired!");
17
//
18
}
19
}
Task 3: Add Space
Add an additional blank print statement at the end of each section
to increase the spacing between the sections.
Run and test your project to ensure it executes as intended.
Task 4: Write a Custom Section
Output a three-line paragraph of your choice somewhere in the
program. Keep it school appropriate.
Run and test your project to ensure it executes as intended.
Task 5: Write Comments
Write the following comments to document and modify the code.
Disable the line of code that displays the message 'The answer
is 42.' by placing a single-line comment at the beginning of the
line.
Write a comment at the end of a blank print statement that
states 'Displays a blank line'.
Run and test your project to ensure it executes as intended.
Reflection Questions
What is the primary function of System.out.println()? How does it
relate to the idea of a program "speaking" to a user?
Imagine you typed Sistem.out.println() by mistake. What do you think would happen when you
try to run your program? Why is correct spelling so important in
programming?
What was the most challenging part of writing your first line of
code?
Submission
Submit your activity and reflection answers to the appropriate
dropbox.