Java Strings Learning Sheet - Programming 1 PDF
Document Details
Colegio de San Gabriel Arcángel
JIMMY DE VERA ROLDAN, MSIT
Tags
Related
- ADP262S-Prac 8-Exception-2024 PDF, Cape Peninsula University of Technology, 17 Apr 2024
- IP_Lecture_08_Latex PDF - SLIIT University
- Java Programming Fifth Edition - Characters, Strings, and the StringBuilder PDF
- Java Programming Fifth Edition: Characters, Strings, and StringBuilder - PDF
- Lecture 2 (Chapter 2) Introduction to Java Programming PDF
- Strings Java PDF
Summary
This document is a learning sheet for a Programming 1 class, focusing on Java strings. It explains defining and using strings, special characters, and how to display text in Java. The sheet also includes review questions and practical exercises. It's for use in an undergraduate information technology course.
Full Transcript
Colegio de San Gabriel Arcangel City of San Jose del Monte, Bulacan, Philippines COLLEGE OF COMPUTER STUDIES INFORMATION TECHNOLOGY DEPARTMENT Program Bachelor of Sc...
Colegio de San Gabriel Arcangel City of San Jose del Monte, Bulacan, Philippines COLLEGE OF COMPUTER STUDIES INFORMATION TECHNOLOGY DEPARTMENT Program Bachelor of Science in Information Technology Course Code BITE2 Description Programming 1 LEARNING SHEET NO. 8 Name Score Date Section Topic Java Strings Learning 1. Define strings. Outcomes 2. Describe stored text in a string. 3. Identify the procedure of displaying strings and special characters used in strings. 4. Discuss string concatenation. 5. Explain the use of other variables with strings. References Gonzales, V. Ph.D. Java 2 Bible. UP Los Baños, Laguna. http://math.hws.edu/eck/cs124/javanotes3/c4/s4/html http://chortle.ccsu.edu/VectorLessons/vmch13/vmch13_2.html http://www.fou.uib.no/fd/1996/h/413002/node28.html http://mathbits.com/MathBits/Java/arrays/Matrices.htm Hoffer, J. A., George, J., Valacich, J. (2013). Modern Systems Analysis and Design (7 th Ed.), Pearson Education. Parsons, JJ., Oja, D. (2012). Computer Concepts: Illustrated Introductory (9 th Ed.), Cengage Learning. Schildt, H. (2011). Java the Complete Reference (8th Ed.).McGraw-Hill Professional. iscussion Java Strings Strings are sequences of characters beginning and ending with double quotation marks (“). Unlike other programming languages, Java does not use an array of characters to represent a string. Use a String by typing some text surrounded by double quotations. This is called a String literal. Storing Text in String Variables A character is the basic element of a string. It is a single letter, number, punctuation mark, or other symbols. In Java programs, a character is enclosed in single quotation marks (‘). Character variables are created with char type in the statement. When you create character variables, you can set them up with an initial value. A string is a collection of characters. Using the String literal and the name of the variable, you can set up a variable to hold a string value. You can also assign a String literal to a String variable to change its content. Using Special Characters in Strings Special Characters Display \’ Single quotation mark \” Double quotation mark \\ Backslash \t Tab \b Backspace \r Carriage return \f Form feed \n New line Display Strings The System.out.println() statement is used to display a string in the Java program. When you display a line of text on screen, this often refers to printing. Prepared by: JIMMY DE VERA ROLDAN, MSIT Page 1 Colegio de San Gabriel Arcangel City of San Jose del Monte, Bulacan, Philippines COLLEGE OF COMPUTER STUDIES INFORMATION TECHNOLOGY DEPARTMENT Concatenate Strings Java allows the use of the plus (+) sign to concatenate or connect two strings together. When you concatenate a String with a value that is not a string, the latter is converted into a string. Review Questions 1. Differentiate a character from a string. 2. Enumerate the special characters used in Java. 3. How can Java display lines of text on screen? 4. Can we use concatenation with integers? Support your answer. Activities Laboratory Exercises 1. Write a program that will ask for the initials of the user’s first and last name, and then give an output of a greeting that says “Hello, “, followed by the user’s initials and an exclamation point. 2. Write a program that displays the initials of your full name. 3. Write a program that will ask as user to enter two characters. The program should compare is the two inputs are equal or not. Display a message notifying that the inputs are equal or not. Prepared by: JIMMY DE VERA ROLDAN, MSIT Page 2