Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
We can use the car type to store a single character.
So in this lesson, you're going to use the card type two story single character and you're also going
to learn when to use car versus drink.
First, I'll need you to make a new class by yourself inside Section two workspace, make a new file
named form Java and the form class must have the main method.
CA is short for a character, as I mentioned earlier, a car variable can only store one character like
A, B or C, and so to define a car variable, you need to write the variable type car, the variable
name, which in this case is gender.
And the character value, which is wrapped in single quotes.
Pay close attention to the single quotes.
Single quotes are for car values.
Don't confuse them with double quotes.
Double quotes are for string values.
Remember that for your next quiz.
All right.
So inside your code, make a car variable named a gender car gender and set it equal to f so single
quotes for a character value and f now print it system dot out.
Dot print line gender.
We're going to compile our code.
And run it.
And that's it, there's really nothing else to a car variable, it can only store one character and
one character, only the gender variable stores the character F, which we then printed.
You can join a string value with a car value using the plus symbol.
So far, using the plus symbol, you connected a number to a string and as a result, the number blended
into the string.
If you remember in the last lesson and you can do the same thing with characters.
This involves a string, the plus icon and a character, and as a result, the character blends into
the string, forming a more complete sentence.
We can apply this in our code, so instead of just printing boring old F will print the string gender.
Leave some white space and connect the string to your character value.
All right, compile the code using job C form dot Java and run it Java form.
Sweet Java embeds the character inside the string and prints it.
You might be asking, why not always use string?
What's the point of a car variable if it can only store one character?
If you actually try to store more than one character inside a car variable, Java would throw an error.
Try it out.
I'm going to try to store car name is equal to and in single code.
Since we're using a car, we'll have to put Jenah.
I already see that there's an Arab let's compile the code anyway, Gervasi form Java and attempting
to compile the code tells me there's an error in line four of my code.
So what I'm going to do actually is store all of these values into string variables, change both types
to string.
And you remember that string values are enclosed in double quotes.
All right, we're going to print the name.
System dart out.
Print line.
Name.
Colon leaf, some white space and connect the string to the string value inside named.
All right, Kapalua code.
Run it and everything works out.
So string is more flexible.
Why not always use it?
The answer is memory and performance.
Don't let these two words frighten you.
Just know this in terms of memory.
Card takes up less memory in terms of performance cars faster car is a primitive data type where a string
is an object.
We'll talk more about objects later.
But for now, when it's possible to use car use car, especially when you're OK, it's really big.
These types of considerations can really make a difference in how well your app performs.
Smack our code will say CA gender is equal to F instead.
We can narrow this down to one rule and it's simple, really use car to store a single character and
you string to store a larger text.
In this lesson, you used a car variable to story single character, a car variable can only store one
character.
You can also join a string value with a car value.
And finally, you learn to use car to store single characters and use string to store text.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.