
STRING CLASS
Presentation
•
Other
•
12th Grade
•
Practice Problem
•
Easy
Ana Dupla
Used 4+ times
FREE Resource
70 Slides • 5 Questions
1
PROGRAMMING
11 ICT
2
CLASS STRINGS
and PROGRAM STYLE
3
REVIEW
Answer the questions by arranging the line of code/s to get the output or correct a simple line of code.
Please also check if the CASING is right.
4
Open Ended
Arrange the given line of code:
public static main String ([] args)
5
Open Ended
Arrange and/or change the given line of code to make it correct. (if you think there is a missing part, add it to the program code)
int = myInteger 2.0
6
Open Ended
Arrange and/or change the given line of code to make it correct. (if you think there is a missing part, add it to the program code)
System.Print('HelloWorld')
7
Open Ended
What is the output?
public class Multiply{
public static void main (String [] args)
double y=10*1+10;
System.out.println(z)}}
8
Open Ended
Arrange the 3rd line of code to make it correct:
public class Multiply{
public static void main (String [] args){
double y=10*1+10;
System.out.println(z);}}
9
ANALYZE:
When do we normally use " " and ' ' ?
10
ANALYZE:
In language: direct quotes, dialogue, titles of short works, the emphasis of certain words, and separating nicknames from given names.
In programming?
" "
11
ANALYZE:
In language: used to replace double quotation marks when they’re inside of other double quotation marks
In programming?
' '
12
CLASS STRING
13
BUZZ BUZZ TO ANSWER
Be READY to answer during our discussion!
You can click the buzzer when you're done typing the correct answer.
14
ANALYZE:
Can you use " " inside another " "?
15
BUZZ BUZZ TO ANSWER
Can you use " " inside another " "?
16
ANSWER:
YES
17
Escape Sequences
\” = Double Quote
\’ = Single Quote
\\ = Backslash
\n = New line (beginning of the next line)
\r = Carriage return (beginning of the current line)
\t = Tab
18
CLASS STRING
-String
-Used to store and process strings of characters.
-When used to declare: String VariableName;
-Use of double quotation “ ”.
-The quoted string is a value of type String.
19
BUZZ BUZZ (type your answer then buzz)
Type a line of code for displaying/printing/result:
"Hello ICT!"
NOTE: Just a single line for printing/displaying the output.
20
ANSWER:
System.out.println(“\"Hello ICT!\"”);
21
BUZZ BUZZ (type your answer then buzz)
Declare Food to be the name of the String Variable
Set the value of Food as "Chicken and Pork Adobo"
How will you write it using Java Syntax/code?
NOTE: Just a single line for declaring variable.
22
CONCATENATION OF STRINGS
+ sign becomes or sometimes called concatenation operator
When you use the + operator on two strings, the result is the string obtained by connecting the two strings to get a longer string.
23
CONCATENATION OF STRINGS
Can we use concatenation when combining a variable and a string?
24
BUZZ BUZZ TO ANSWER
Can we use concatenation when combining a variable and a string?
25
ANSWER:
YES
26
String noun = “Strings”;
String sentence;
sentence = noun + “are cool.”;
System.out.println(sentence);
What is the output?
27
BUZZ BUZZ TO ANSWER
String noun = “Strings”;
String sentence;
sentence = noun + “are cool.”;
System.out.println(sentence);
28
ANSWER:
Stringsare cool
29
BUZZ BUZZ TO ANSWER
System.out.println(“100” + 42);
System.out.println(100 + 42);
What is the output?
30
ANSWER:
10042
142
31
TERMS TO REMEMBER
are entities that store data and can take actions.
Objects
the name for a type whose values are objects.
Class
the information in parenthesis
Argument
the actions that an object can take.
Methods
called sending a message to the object.
Invoking a method
32
String Methods
A string method is called (invoked) by writing a String object, a dot, the name of the method, and finally a pair of parenthesis that enclose any arguments to the method.
33
Example:
String greeting = “Hello”;
//int count = greeting.length();
System.out.println(“Length is ” + greeting.length());
What is the output?
34
BUZZ BUZZ TO ANSWER
String greeting = “Hello”;
//int count = greeting.length();
System.out.println(“Length is ” + greeting.length());
35
ANSWER:
Length is 5
36
Here are some METHODS in the Class String
37
int length()
returns the length of the calling object (which is a string) as a value of type int.
38
int length()
Example:
String greeting = “Hello ”;
greeting.length() displays ?
Output:
39
int length()
Example:
String greeting = “Hello ”;
greeting.length() displays ?
Output:
6
40
boolean equals(Other_String)
returns true if the calling object string and the Other_String are equal. Otherwise, returns false.
41
boolean equals(Other_String)
Example:
String greeting = “Hello”;
greeting.equals(“Hello”) returns ?
greeting.equals(“hello”) returns ?
greeting.equals(“Goodbye”) returns ?
Output:
?
?
?
42
boolean equals(Other_String)
Example:
String greeting = “Hello”;
greeting.equals(“Hello”) returns ?
greeting.equals(“hello”) returns ?
greeting.equals(“Goodbye”) returns ?
Output:
TRUE
FALSE
FALSE
43
boolean equalsIgnoreCase(Other_String)
returns true if the calling object string and the Other_String are equal, considering uppercase and lowercase versions of a letter to be the same. Otherwise, returns false.
44
boolean equalsIgnoreCase(Other_String)
Example:
String greeting = “mary! ”;
greeting.equalsIgnoreCase("Mary!") returns?
Output:
45
boolean equalsIgnoreCase(Other_String)
Example:
String greeting = “mary! ”;
greeting.equalsIgnoreCase("Mary!")
Output:
True
46
String toLowerCase()
returns a string with the same characters as the calling object string, but with all letter characters converted to lowercase.
47
String toLowerCase()
Example:
String greeting = “Hi Mary! ”;
greeting.toLowerCase() returns?
Output:
48
String toLowerCase()
Example:
String greeting = “Hi Mary! ”;
greeting.toLowerCase() returns?
Output:
hi mary!
49
String toUpperCase()
returns a string with the same characters as the calling object string, but with all letter characters converted to uppercase.
50
String toUpperCase()
Example:
String greeting = “Hi Mary! ”;
greeting.toUpperCase() returns?
Output:
51
String toUpperCase()
Example:
String greeting = “Hi Mary! ”;
greeting.toUpperCase() returns?
Output:
HI MARY!
52
String trim()
returns a string with the same characters as the calling object string, but with leading and trailing white space removed.
white space-blank space, tab, new line
53
String trim()
Example:
String pause = “ Hmm ”;
pause.trim() returns ?
Output:
54
String trim()
Example:
String pause = “ Hmm ”;
pause.trim() returns ?
Output:
Hmm
55
char charAt(position)
returns the character in the calling object string at the Position.
Position are counted 0, 1, 2, etc.
56
char charAt(position)
Example:
String greeting = “Hello!”;
greeting.charAt(0) returns ?
greeting.charAt(1) returns ?
Output:
57
char charAt(position)
Example:
String greeting = “Hello!”;
greeting.charAt(0) returns ?
greeting.charAt(1) returns ?
Output: H
e
58
String substring(start/position)
returns the substring of the calling object string starting from position Start through to the end of the calling object.
59
String substring(start/position)
Example:
String sample = “AbcdefG”;
sample.substring(2) returns ?
Output:
60
String substring(start/position)
Example:
String sample = “AbcdefG”;
sample.substring(2) returns ?
Output:
cdefG
61
String substring(start, end)
returns the substring of the calling object string starting from position Start through but not including, position End of the calling object.
62
String substring(start, end)
Example:
String sample = “AbcdefG”;
sample.substring(2, 5) returns ?
Output:
63
String substring(start, end)
Example:
String sample = “AbcdefG”;
sample.substring(2, 5) returns ?
Output:
cde
64
int indexOf(A_String)
returns the index (position) of the first occurrence of the string A_String in the calling object string. Returns -1 if A_String is not found.
65
int indexOf(A_String)
Example:
String greeting = “Hi Mary!”;
greeting.indexOf("Mary") returns ?
greeting.indexOf("Sally") returns ?
Output:
66
int indexOf(A_String)
Example:
String greeting = “Hi Mary!”;
greeting.indexOf("Mary") returns ?
greeting.indexOf("Sally") returns ?
Output: 3
-1
67
int lastIndexOf(A_String)
returns the index (position) of the last occurrence of the string A_String in the calling object string. Returns -1 if A_String is not found.
68
int lastIndexOf(A_String)
Example:
String greeting = “Mary, Mary, Mary you are sweet”;
greeting.indexOf("Mary") returns ?
greeting.lastIndexOf("Mary") returns ?
Output:
0
12
69
RECALL OF METHODS
int length()
boolean equals(other_string)
boolean equalsIgnoreCase(other_string)
String toLowerCase()
String toUpperCase()
String trim()
70
RECALL OF METHODS
char charAt(position)
String substring(Start)
String substring(Start, End)
int indexOf(A_String)
int lastIndexOf(A_String)
71
OPEN OUR GOOGLE CLASSROOM
Check our activity there. Submit your output.
A student will explain the answer in class.
72
COMMENTS
Two ways to insert comment:
//comment and /* comment */
Line comments // (for comments meant only for the code writer or for programmers who modifies the code.
Block comments /* */ (for line breaks and documentation)
73
INDENTING
GENERAL RULE: easy to understand and easy to follow.
74
Questions?
75
OPEN OUR GOOGLE CLASSROOM
PERFORMANCE TASK AND WRITTEN ACTIVITY
PROGRAMMING
11 ICT
Show answer
Auto Play
Slide 1 / 75
SLIDE
Similar Resources on Wayground
63 questions
Common Competencies 2
Presentation
•
KG - University
75 questions
BUS 101 Chapter 14
Presentation
•
University
62 questions
Light from Objects in the Sky, Part 1
Presentation
•
11th - 12th Grade
76 questions
Film Quiz Extern 2025
Presentation
•
University - Professi...
72 questions
Fluida Statis Static Fluids
Presentation
•
University
67 questions
Heart lecture
Presentation
•
12th Grade
72 questions
MNT Diabetes
Presentation
•
University
65 questions
Unit 3.1 : Programming model - Register
Presentation
•
KG - University
Popular Resources on Wayground
20 questions
"What is the question asking??" Grades 3-5
Quiz
•
1st - 5th Grade
20 questions
“What is the question asking??” Grades 6-8
Quiz
•
6th - 8th Grade
10 questions
Fire Safety Quiz
Quiz
•
12th Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
34 questions
STAAR Review 6th - 8th grade Reading Part 1
Quiz
•
6th - 8th Grade
20 questions
“What is the question asking??” English I-II
Quiz
•
9th - 12th Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
47 questions
8th Grade Reading STAAR Ultimate Review!
Quiz
•
8th Grade
Discover more resources for Other
10 questions
Fire Safety Quiz
Quiz
•
12th Grade
20 questions
“What is the question asking??” English I-II
Quiz
•
9th - 12th Grade
10 questions
Fire Prevention
Quiz
•
9th - 12th Grade
20 questions
Grammar
Quiz
•
9th - 12th Grade
16 questions
AP Biology: Unit 1 Review (CED)
Quiz
•
9th - 12th Grade
20 questions
verbos reflexivos en español
Quiz
•
9th - 12th Grade
11 questions
Expectations Review
Quiz
•
9th - 12th Grade
10 questions
Climate Change and Its Impact
Interactive video
•
9th - 12th Grade