#6 | Declaring Java Strings and using String literals | Learn Java

Published: 01 September 2023
on channel: Neil Gillies | Coding & Music
215
4

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.


On this page of the site you can watch the video online #6 | Declaring Java Strings and using String literals | Learn Java with a duration of hours minute second in good quality, which was uploaded by the user Neil Gillies | Coding & Music 01 September 2023, share the link with friends and acquaintances, this video has already been watched 215 times on youtube and it was liked by 4 viewers. Enjoy your viewing!