Varriables Flashcards
What is a “boolean” data type?
In Java, thebooleanprimitive data type is used to store a value, which can be eithertrueorfalse
What is a String variable?
A String in Java is a Object that holds multiple characters. It is not a primitive datatype.
How do you create a String?
A String can be created by placing characters between a pair of double quotes (“).
What is an “int” data type?
In Java, the int datatype is used to store integer values. This means that it can store all positive and negative whole numbers and zero. 3,4,0,-5 etc
How do you compare Strings?
To compare Strings, the equals() method must be used instead of the primitive equality comparator ==.
What is a “char” data type?
In Java, char is used to store a single character. The character must be enclosed in single quotes. char answer = ‘y’;
What are primitive data types?
Java’s most basic data types are known as primitive data types and are in the system by default.
The available types are as follows:
int = Holds whole numbers char = Holds single characters boolean = Holds true or false byte = long = short = double = Holds numbers with decimals float = null = is another, but it can only ever store the value null
What is Static Typing in java?
In Java, the type of a variable is checked at compile time. This is known as static typing. It has the advantage of catching the errors at compile time rather than at execution time. Which means that every variable and every expression has a type that is known at compile time.
Variables must be declared with the appropriate data type or the program will not compile.
What are compound assignment “operators”?
Compound assignment operators can be used to change and reassign the value of a variable using one line of code. Compound assignment operators include +=, -=, *=, /=, and %=.
For example:
int number = 5;
number += 3; // Value is now 8 number -= 4; // Value is now 4 number *= 6; // Value is now 24 number /= 2; // Value is now 12 number %= 7; // Value is now 5
What are increment and decrement assignment “operators”?
The increment operator, (++), can increase the value of a number-based variable by 1 & the decrement operator, (–), can decrease the value of a variable by 1.
int numApples = 5;
numApples++; // Value is now 6
int numOranges = 5;
numOranges–; // Value is now 4
What does the “Final” keyword do?
When you use the “final” keyword on a variable the value will remain the same, and any attempts to change it later with operators will result in an error message.
What is the Order of Operations?
The order in which an expression with multiple operators is evaluated is determined by the order of operations: parentheses() -> multiplication* -> division/ -> modulo% -> addition+ -> subtraction
What are the Math Operations and which variables can they be applied to?
Basic math operations can be applied to int, double and float data types:
\+ addition - subtraction * multiplication / division % modulo (yields the remainder)
These operations are not supported for other data types.
What are the Comparison operators and which data types can they be used with?
Comparison operators can be used to compare two values:
> greater than < less than >= greater than or equal to <= less than or equal to == equal to != not equal to They are supported for primitive data types and the result of a comparison is a boolean value true or false
What is a Data type?
There are two kinds of data types in the Java programming language: primitive types and reference types. There are, correspondingly, two kinds of data values that can be stored in variables, passed as arguments, returned by methods, and operated on: primitive values and reference values.