0% found this document useful (0 votes)
20 views

Java Lesson 3 - Displaying Text On Screen

This document provides a lesson on Java programming that teaches students how to display text on screen using print and println methods, differentiate between print and println, discuss comments in Java and demonstrate how to display comments. It includes examples of print vs println, the anatomy of the print method, and practice tests displaying names, numbers and comments.

Uploaded by

Rowell Marquina
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Java Lesson 3 - Displaying Text On Screen

This document provides a lesson on Java programming that teaches students how to display text on screen using print and println methods, differentiate between print and println, discuss comments in Java and demonstrate how to display comments. It includes examples of print vs println, the anatomy of the print method, and practice tests displaying names, numbers and comments.

Uploaded by

Rowell Marquina
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

TUNASAN NATIONAL HIGH SCHOOL

SDO - Muntinlupa City

Lesson 3 - Java Programming

ROWELL L. MARQUINA
Senior High School Teacher
TUNASAN NATIONAL HIGH SCHOOL
LEARNING OBJECTIVES:
At the end of the session, you will be able to:
1. differentiate print and println from
one another;
2. display text on screen using print and
println;
3. discuss what is a comment in Java
and what it is used in a program; and
4. demonstrate how to display
comments on a Java program;
DISPLAYING TEXT ON SCREEN
One of the most basic competencies in Java
programming is how to instruct the program to
display text on the screen.
Java offers two ways of displaying text output on the
screen using the print, and println methods.
PRINT vs PRINTLN METHOD
The print method refers to the Java statement that
instructs the program to display text in a single line.

The println method on the other hand is used to


display text in separate lines.
PRINT vs PRINTLN METHOD
As we have discussed earlier, the print method is used
to display text in a single line.

Even if you code the lines separately using print


method, the texts will still appear in a single line.
PRINT vs PRINTLN METHOD
The println method on the other hand is used to
display text in separate lines.

What happens in the code is that


after the first line of text is
displayed it will bring the cursor to
the next line before displaying the
second line of text and so forth.
ANATOMY OF THE PRINT METHOD

System.out refers to the Java object that details where it will


display the output of the program.
print refers to the method that instructs the program to
display the text in a single line.
(“Have a wonderful day!”) is the text that will be displayed
on the screen.
; is referred to as a separator which signifies the end
of the line code.
PRACTICE TEST 1:
Create a simple program which
will display the numbers 1-5 in a
single line. Each number must be
displayed using individual print
methods.
PRACTICE TEST 2:
Using println, create a simple
program which will display the
following information:
▪ Name
▪ Date of Birth
▪ Name of Father
▪ Name of Mother
PRACTICE TEST 3:
On a piece of paper, write the
expected output of the source
code below:
WHAT ARE COMMENTS?
Comments are non-executable Java statements that
are used by programmers to place notes, descriptions,
or explanations on their program.
It is also referred to as inline documentation because
it is used to document and provide explanations
about specific parts of the program.
This is an example of a comment in Java.
WHAT ARE COMMENTS?
Since comments are non-executable statements,
they do not have any effect on the program.
SINGLE-LINE COMMENTS
There are two ways of writing comments in Java. The
one you are seeing below is called a single-line
comment which is used for writing short narrative or
explanations in a program. It is characterized by two
forward slashes ( // ) at the beginning of the
comment.
This is a single-line comment in Java.
MULTI-LINE COMMENTS
The other method is by writing a multi-line comment
which is for writing complex and details
documentations on the program. It is a block
statements that starts with forward slash then asterisk
(/*) and ends with a (*/) asterisk and forward slash.
This is a multi-line comment in Java.
PRACTICE TEST 4:
Using println, create a simple program
which will display the required
information below. Include comments
that tells something about the
information you have provided.
▪ Nickname
▪ Childhood Hero
▪ Favorite Color
▪ Dream Profession
DISPLAYING TEXT ON SCREEN
AND WRITING COMMENTS
MR. ROWELL L. MARQUINA
Tunasan National High School
Senior High School Department

Email Address:
[email protected]
[email protected]
[email protected]

You might also like