In this video we learn about String variables and String literals.
Here is the code used in this lesson:
public class Main {
public static void main(String[] args) {
String firstName = "Mary";
String surname = "MacPherson";
int houseNumber = 7;
String streetAddress = "Park Street";
String town = "Glasgow";
String postcode = "G12 45W";
System.out.println("Your name is " + firstName + " " + surname);
System.out.println("You live at " + houseNumber + " " + streetAddress);
System.out.println(town + " " + postcode);
}
}
Here is a copy of the lesson notes:
// Strings are a data type that allow you to store any text and characters, including "character representations" of numbers.
// For words, names, messages and so on, or combinations of text and numbers - e.g. vehicle registration, postcodes etc.
// You can't perform math operations on any "numbers" stored in a String (you'd need to store them as a numerical data type e.g. int).
// A String is actually a special type of data type and is technically considered a Java class.
// String literals are text values that are not stored within a variable - System.out.print("Hello World");
// You have to decide when best to use Strings and String literals - use a String if you think the value is liable to change.
Nesta página do site você pode assistir ao vídeo on-line #6 | Declaring Java Strings and using String literals | Learn Java duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Neil Gillies | Coding & Music 01 Setembro 2023, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 215 vezes e gostou 4 espectadores. Boa visualização!