Welcome back to KnowledgeCity's course on programming in Java. I'm Cliff Brozo, I'm your instructor. Today we're gonna learn all about strings, and how to get data into our program. Let's take a look at some code. When Java deals with strings, a string is considered to be a class and each string is an object in that class. Now you might be saying so what? Well, the problem is strings are stored as a reference variable. And that means that instead of containing the actual word that's in the string, it contains a pointer to a memory address. And a second string would contain a different pointer to a different memory address. Now, normally in programming, we would use equal equal to compare things. But in this case, equal equal would compare the memory addresses which are obviously different and it would not compare the data values. Let's look at what this looks like. If we write a short program on line five, I set up a variable called myName, and I give it the value of my name. Then I set up another string called myName2, I read in some information. I set up my scanner and then I print out a line that tells the user what to do. In line nine I say, "What is your name?" And the person at the console, types in their name which is stored in myName2. Then I ask the question, if myName is equal to myName2 then print out myName is equal to myName2, otherwise print out myName is not equal to myName2. And again, I'll call your attention to the fact that we're using equal equal here, which is a way to test for equality in most programming languages. When the program runs down below, the prompt appears on the screen, "What is your name?" That's from line nine. Then in line 10 I type in Cliff, that's my name. And line 11 says the Cliff that I stored in line five equal to the one that I typed in in line 10. Even though they are exactly the same, the program tells me that Cliff is not equal to Cliff. And that's because it's comparing where these variables are located in memory, not what the actual data is. A way around that is to go in and change how Java compares the equals, actually use a function called equal. Now this is the same program that you're looking at except in line 11, I changed the way the code works. Instead of using equal equal, I put in myName.equals and then in parentheses myName2. By using equals instead of checking the memory locations which are obviously not equal, it checks the values that are actually contained in those memory locations. So when the program runs again, I type in myName and this time it says Cliff is equal to Cliff. However, I'll draw your attention to the right-hand side of the screen. I ran the program again, and this time I typed in my name in all capital letters. Well, this time the program accurately stated Cliff is not equal to Cliff because one is not in all caps, and the other one is and the actual ones and zeros for these letters are different than the ones for the capital letters. Let's look at what happens when we compare individual characters. We have the ability to call on several different functions to evaluate what's inside an individual character. I can test, is it a letter? Is it a digit? Is it white space? Is it uppercase? Is it lower case? I can actually convert it to uppercase, I can convert it to lowercase or I can even convert the single letter to a string where it would be stored as a one character string. Let's take a look at how this runs. I wrote a program that starts in line five and I take a character variable and I call it letterC and I assign it the value of 'C.' And you'll remember that single characters get single quotes. Line six prints out the first line that says the character is blank. And that's the first line of the output here, the character is C. Then in line eight, I test to see if the character is uppercase, .isUpperCase is a function and I'm using letterC, it knows the difference between uppercase letters and lowercase letters. In this case, the 'C' which I assigned in line five is upper case. So line nine executes, and that's exactly what I say in my output, the character C is uppercase. The next part of the program says, letter C is now equal to, well, what I'm doing is I'm changing the value of the variable letterC to lower case. I'm calling upon the lowercase function to lowercase and that takes whatever's in letterC, changes it to lowercase and places it right back in letterC. Just for verification in line 15, I print out a line that says the character C has been changed to lower case. And that's the third line here the character C has been changed to lower case. Then I run my test again in lines 17 through 20 to see if the character is upper case. This code is exactly the same as lines 8 through 11. But this time it tells me that the character C is lowercase. Then I ask in line 22, is the character a letter? And I pass the .isLetter function, the letterC. In this case, the letterC is a letter and it prints out that it's a letter of the alphabet. In line 27, I assign that letter the character '5.' Now this is not a number '5', it's still treated as a character as it's in single quotes. I print out a line just for confirmation. The character has been changed to a 5. And then I ask is the character a digit? Now, .isDigit does not mean is numeric, they're different. It just knows the difference between letters of the alphabet and numbers of the alphabet. In this case, the character 5 is a digit and that's the line that prints here. I change the letterC to a space and I print out a line specifying that the character has been changed to a blank. That's the next last line here in the output. I test in line 39 to see if the character is white space. I pass the .isWhitespace function the letterC and yes indeed it prints out the character is white space. Now, you know how strings are stored. They're stored as memory locations, and I need to use the word dot equals rather than equal equal. We saw how we can input characters into our program and then test to see what kind of characters they are. We can turn them into uppercase, we can turn them into lowercase, and we can turn them into strings. Join me next time when we'll deal with strings characters, indexes of strings and some string operations. I'll see you soon.