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

String Class: Prof. Irysh Paulo R. Tipay, MSCS

This document provides an introduction to the String class in Java. It discusses that a String is a sequence of characters enclosed in double quotes, and is not a primitive data type but rather a class. It explains that String objects are immutable and reference variables that point to the memory location of the value rather than storing the value itself. The document also covers declaring String variables, comparing Strings using == versus the equals() method, and built-in Java libraries like java.lang that contain common classes like String and System.

Uploaded by

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

String Class: Prof. Irysh Paulo R. Tipay, MSCS

This document provides an introduction to the String class in Java. It discusses that a String is a sequence of characters enclosed in double quotes, and is not a primitive data type but rather a class. It explains that String objects are immutable and reference variables that point to the memory location of the value rather than storing the value itself. The document also covers declaring String variables, comparing Strings using == versus the equals() method, and built-in Java libraries like java.lang that contain common classes like String and System.

Uploaded by

PaulReeves
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

STRING CLASS

Prof. Irysh Paulo R. Tipay, MSCS

Quote For the Day


Any fool can write code that a
computer can understand. Good
programmers write code that humans
can understand.- Martin Fowler

Introduction
What is a Class?
So far you know that.
- building blocks in Java
- contains main method

Introduction
Large applications in Java Contain a
collection of classes.
Two types
Built-in classes - predefined functionality
(System, String, Scanner)
User Defined - Created by programmer

Introduction
Collection of classes is called a package.
Collection of packages is called a library.

Introduction
As a programmer, you can create your
own package or library.
You can also use libraries or packages
created by other programmers.
User-defined Libraries/Package

Introduction
You can also use Built-in
libraries/packages in Java.
java.util
java.io
java.awt
java.lang

Introduction
Java.lang Library
-doesn't need to be explicitly imported, java
does it automatically
-included in all java programs
-provides access to the basic Java Classes
-contains String, System, Math.

String Class
Contains a sequence of characters
Enclosed in double quotes.
String is NOT a primitive data type
String is a class

Reference Variables
Variables created using the String Class are
called objects
Objects in Java are reference variables.
Reference variables do not store the
actual value but rather it holds the address
where the value is stored

Reference Variables Vs Primitive


Variables
Primitive Variables
int var =
1;

var

1
letter

char letter =
b;

Reference Variables Vs Primitive


Variables
Reference Variables

str
1000111

String str =
Hello;
1000111

Hello

String is Immutable
Objects of the String Class are
immutable.
String str = Hello;
str = Hi;
10111

Hi

str
1000111
10111

1000111
Garbage
Collectio
Hello
n

Declaring Strings
String str1 = Hello;
OR
String str1= new String(Hello);

Declaring Strings (1)


String str1 = Hello;
String str2= Hello;

str1

110011
1
1100111

Hello

str2

110011
1

Declaring Strings (2)


String str1 = new String(Hello);
String str2= new String(Hello);
str2

str1

110000
1

111001
11

1100001

11100111

Hello

Hello

Comparing Strings (1)


String str1 = Hello;
String str2= Hello;

str1

110011
1

str1 == str2?
1100111

TRUE

Hello

str2

110011
1

Comparing Strings (2)


String str1 = new String(Hello);
String str2= new String(Hello);
str1 == str2?

str2

str1

110000
1

111001
11

1100001

11100111

Hello

Hello

FALSE

Comparing Strings (3)


String str1 = new String(Hello);
String str2= new String(Hello);
str1.equals(str
2)?

str2

str1

110000
1

111001
11

1100001

11100111

Hello

Hello

TRUE

Questions?

You might also like