Chapter 2 Flashcards
What is the difference between a string literal and a literal
A string literal is presented by putting double quotes around the text. A liteal is an explicit data value used in a program.
What is the string concatenation?
The string concatenation operator (+) concatenates / puts together different string together.
For example, “Peanut butter” + “and jelly”.
Why is the following statement wrong?System.out.println(“We present the following facts
for your extracurricular edification:”);
The System.out.println cannot be divided into two different lines. If we want to distribute the code onto two different lines, we will have to write two times the method.
When concatenating in a println method, what’s the difference between writing: + 34 + 35 and + (34 + 35) ?
Without parenthesis 34 and 35 get only concatenated, for them to be added and then displayed we will have to use the parenthesis.
What are escape sequences?
Escape sequences are a particular form of writing that allows particular characters written in a string not to be confused with synctactical parts of the programming language.
If you were to write …(“John:”I’m coming””);
Java would not understand which quotas are the extremes of a string and which are intended as a character.
So we write: \" for commas. \n new line \t tab \' quote \\ backslash
What is a variable?
A variable is a name for a location in memory that holds a value.
How do you declare a variable?
You define the data type (like int, double, char, etc), you write the desired name of the variable and you CAN (not necessary) write the variable’s value.
How do you declare a constant? What is its use in Java?
A constant is defined in the same way as a variable, but at the beginning there must be written “final”. The variable should follow the convention and be written with capital letters only.
Constants are used to distinguish specific variables from others, to avoid writing various variables with the same value and to avoid their values be changed by error.
What are the eight primitive data types in Java?
Integers: byte, short, int, long
Floating point numbers: float, double
Characters: char
Boolean values: boolean
What is the max value of each of these data types?
byte, short, int, long
byte = 127 short = 32 767 int = 2 147 483 647 long = > 9 * 10^18
What does a char variable store?
A char variable stores a single character. Those are delimited by single quotes: ‘a’, ‘X’, ‘7’, ‘,’, ‘\n’.
What is the difference between a char variable and a string?
A char variable contains only one character, while a string contains a series of characters.
What is a character set?
How many bits used Unicode?
It is an ordered list of characters, with each character corresponding to a unique number.
Unicode uses sixteen bits to store characters, allowing to 65 536 differenct characters.
What is the ASCII character set?
It is an older and smaller character set, but it’s still quite popular.
How do you assign characters?
char c = ‘\u005B’; -> you assign the character with that unicode value.
char d = 91; -> you assign the character with that unicode value, but written in decimal form.