Back

Activity 1.1 Hello World!

divider

Introduction

Activity 1.1

Hello World!

Topics

  • Output
  • User Interfaces
  • Comments

Output

Output refers to information that a program produces. It can be sent to the user via some output device.

monitor
speaker
headphone

User Interfaces: GUIs and TUIs

Graphical User Interface - Uses visual elements to let you interact with a program.

GUI

User Interfaces: GUIs and TUIs

Terminal user Interface - A user interface that uses text and symbols, rather than graphical elements.

TUI

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
Are you a 1 or a 0?

Demo

Call System.out.println(). Write a message of your choice.

Main.java
public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
Output
Hello World!

Comments

Write notes or disable code. Ignored by the Java compiler.

Main.java
public class Main {
public static void main(String[] args) {
// System.out.println("Hello!");
System.out.println("Goodbye!");
}
}
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

  • icon Writing and executing code
  • icon Displaying console output
  • icon Debugging potential syntax errors
  • icon Reading comments
divider

Activity Tasks

  • icon Create a new Java project named 1-1-Output.
  • icon Complete each task individually.

Task 1: Write and Test

  • icon Write each line of code from the section making sure to stay within the main method.
  • icon Run and test your project to ensure it executes as intended.
Main.java
public class Main {
public static void main(String[] args) {
System.out.println("Welcome to the Skynest Nexus.");
System.out.println("This class is taught by Mr. Mortimer");
System.out.println();
//
}
}

Task 2: Add More Code

  • icon Write the additional sections of output under your current print statements.
  • icon Run and test your project to ensure it executes as intended.
Main.java
public class Main {
public static void main(String[] args) {
System.out.println("Welcome to the Skynest Nexus.");
System.out.println("This class is taught by Mr. Mortimer");
System.out.println();
System.out.println("What is the answer to life, the universe, and everything?");
System.out.println("The answer is 42.");
System.out.println();
System.out.println("Sally sells seashells by the seashore.");
System.out.println("Sally wants to invite you to invest in a money making opportunity.");
System.out.println();
System.out.println("If you start to feel overwhelmed, just remember:");
System.out.println("Mortimers don't quit, we get fired!");
//
}
}

Task 3: Add Space

  • icon Add an additional blank print statement at the end of each section to increase the spacing between the sections.
  • icon Run and test your project to ensure it executes as intended.

Task 4: Write a Custom Section

  • icon Output a three-line paragraph of your choice somewhere in the program. Keep it school appropriate.
  • icon Run and test your project to ensure it executes as intended.

Task 5: Write Comments

  • icon Write the following comments to document and modify the code.
    • icon 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.
    • icon Write a comment at the end of a blank print statement that states 'Displays a blank line'.
  • icon Run and test your project to ensure it executes as intended.
divider

Reflection Questions

  1. What is the primary function of System.out.println()? How does it relate to the idea of a program "speaking" to a user?
  2. 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?
  3. What was the most challenging part of writing your first line of code?
divider

Submission

Submit your activity and reflection answers to the appropriate dropbox.

Activity Complete