Values and Data Types Flashcards
What is a character set?
A character set is a defined list of characters recognized by a language
What does a character set consist of?
- Alphabets: letters, A-Z, a-z
- Numerals: digits, 0-9
- Special characters: ?, %, }, >, @, etc.
What are the alphabets and numerals collectively known as?
The alphanumeric character set
Name two standard character sets
ASCII and Unicode
What does ASCII stand for?
American Standard Code for Information Exchange
What is ASCII?
It is a 7-bit set of codes that defines 128 different characters
What is the ASCII character set enough to represent?
It is enough to represent every uppercase letter, lowercase letter, digit, and special character used in the English Language keyboard.
What is Unicode?
It is an international character set designed to represent all the characters found in languages around the world, such as English, Hindi, Japanese, Chinese, French, Geman
How many bits can Unidode use to represent a character?
8 to 32 bits
Which character encoding does Java use?
The Unicode character coding
How is a specific Unicode character expressed?
By using the escape sequence ‘\u’ followed by its four digit hexadecimal code
What is the extended ASCII code?
It is an 8-bit character set that defines 256 different characters (2^8 = 256), including the standard 7-bit ASCII characters
What are tokens?
Tokens are the smallest individual units of a Java program. All characters in a Java program are grouped into symbols called tokens.
How many categories of tokens are in Java?
- Keywords
- Literals
- Operators
- Punctuators
- Identifiers
What are keywords?
Keywords are the words that have a special meaning to the Java compiler
What is another name for keywords?
Reserved words
Why are keywords not available as names for variables or methods?
Java compiler reserves keywords for its own use, and hence they are not available
Which keywords are currently not used in Java?
goto and const
Name words you cannot use as variable names despite them not being keywords
true, false, null, literal values
What are identifiers?
They are fundamental building blocks of a program & are used to name different components of a program, such as variables, methods, and objects
What are the fundamental building blocks of a program?
Identifiers
What are Java identifiers naming conventions?
- An identifier can consist of any combination of letters, digits, underscore character, dollar sign
- It cannot begin with a digit
- It may be of any length
- Both uppercase and lowercase letters can be used in naming an identifier
- Java is case sensitive, which means that two identifier names that differ only in uppercase and lowercase characters are considered to be different identifiers
- An identifier cannot be a keyword or a boolean literal or a null literal
What are literals?
They are a sequence of characters that represent values in a program and are stored in variables. Literals are made out of digits, letters, and other characters
Name the types of literals Java supports
- Numeric -> Integer and Real
- Non Numeric -> Character and String
- Boolean
- Null
What are numeric literals?
Values that may consist of digits (0-9), a decimal point (.), a positive (+) or negative (-) sign
Name the 2 types of numeric literals
Integer Literals
Real Literals
What are integer literals?
Values that represent whole numbers only. They can be positive or negative values.
What is not allowed in integer literals?
Space, comma, and a decimal point not allowed
Give another name for real literals
Floating-point literals
What are real literals?
They represent values with a decimal point
Name the two ways in which real literals can be written
In fractional or exponential form
How is a real literal in the fractional form written?
It consists of signed or unsigned digits, including a decimal point between the digits. Eg. - +233.06
How is a real literal in the exponential form written?
It consists of two components: mantissa and exponent. Eg. -> 7.04*10^34 can be written as 7.04E34
What is the mantissa?
Component before E, in a real literal in exponential form
What is the exponent?
Component after E, in a real literal in exponential form
What would make a real literal invalid in exponential form?
- No digit specified after E
- The exponent is not an integer value
- No digit before E
- Comma
What would make a real literal invalid in fractional form?
- No decimal point
- No digit after the decimal point
- No digit before the decimal point
- Two decimal points
- Comma
What are the two non-numeric literals?
Character literals
String literals
What are character literals?
Literals of this type represent exactly one character enclosed in single quotes
What are Boolean Literals?
The logical values true and false are the boolean literals
What do true and false represent during logical evaluation?
On/off, yes/no, presence/absence of something
What is the null literal?
This is a special kind of literal which is represented by the keyword null or escape sequence ‘\0’
What are punctuators?
Symbols used for grouping and separating the code
Give another name for punctuators
Separators
Name some punctuators
; , {} () [] .
What is the use of semicolon?
Used to separate statements
What is the use of comma?
Used to separate consecutive identifiers in a variable declaration
What is the use of {}?
Used to define a block of code in a Java program. They are also used to initialize the values of arrays
What is the use of ()?
Parenthesis is used to define methods. They are also used to define the precedence of operators in an expression and conditions in control structures
What is the use of []?
Used to declare arrays and refer to values at a particular index
What is the use of .?
The period operator in Java is used to access member variables and methods. It is also used to differentiate the package names from sub-packages and class names
What are operators?
Operators are symbols that are used to perform arithmetic or logical operations in a given expression.
Name the main categories of operators in Java
- Unary operators
- Assignment Operator
- Arithmetic Operators
- Relational Operators
- Increment/Decrement Operators
- Logical Operators
- Bitwise Operators
- Conditional/Ternary Operators
What is an escape sequence?
It is a set of non-graphical characters that has a special meaning to the Java compiler.
What is the structure of an escape sequence?
In an escape sequence, a character is preceded by a backslash ()
What does the usage of the backslash result in?
When you print a certain character, the same character is displayed on the screen, but when it is prefixed with ‘', it is read as an escape sequence
What is the use of escape sequence ‘\n’?
Inserts a new line in the text at this point (shifts control to next line)
What is the use of escape sequence ‘\t’?
Inserts a tab in the text at this point
What is the use of escape sequence ‘\’?
Inserts a backslash character in the text at this point
What is the use of escape sequence ‘ " ‘?
Inserts a double quote character in the text at this point
What is the use of escape sequence ‘ ' “?
Inserts a single quote character in the text at this point
What is the use of escape sequence ‘\r’?
Inserts a carriage return in the text at this point (same as pressing the Enter key)
What is the use of escape sequence ‘\?’?
Inserts a question mark in the text at this point
What is the use of escape sequence ‘\a’?
Inserts an audible bell (beep sound)
What is the use of escape sequence ‘\0’?
Represents a null character
Name the two categories of data types
Primitive Data Types
Non-Primitive Data Types
What are primitive data types?
The fundamental data types that are an integral part of the Java programming language
Give other names for primitive data types
Intrinsic or built-in data types
How many primitive data types are in Java?
- byte
- short
- int
- long
- char
- float
- double
- boolean
What are non-primitive data types?
The data types that are derived from primitive data types are called non-primitive.
Give other names for non-primitive data types
Reference types, composite data types, derived types
How many non-primitive data types are in Java?
Classes, arrays, interfaces
What are integer data types?
They are used to store whole numbers
Which four categories are integer data types divided into?
byte, short, int, long
What is the size of byte data type?
8 bits (1 byte)
What is the size of the short data type?
16 bits (2 bytes)
What is the size of the int data type?
32 bits (4 bytes)
What is the size of the long data type?
64 bits (8 bytes)
What is the range of byte data type?
-128 to 127 (-2^7 to 2^7 - 1)
What is the range of short data type?
-32,768 to 32,767 (-2^7 to 2^7 - 1)
What is the range of int data type?
-2 billion to +2 billion (approx.) (-2^31 to 2^31 - 1 )
What is the range of long data type?
-9E18 to +9E18 (approx.) (-2^63 to 2^63 - 1)
What can the floating-point data type be divided into?
Float and double data type
What is the size of the float data type?
32 bits (4 bytes)
What is the range of float data type?
1.4e—045 to 3.4e+038
What is the precision of the float data type?
Up to 7 significant decimal digits
What is the size of double data type?
64 bits (8 bytes)
What is the range of double data type?
4.9e—324 to 1.8e+308
What is the precision of double data type?
Up to 15 significant decimal digits
What does the float data type store?
Low precision digits, such as temperature, salary, and percentage
What does the double data type store?
High precision digits, such as scientific readings, the location of celestial bodies, and their distances.
What is the default data type of floating-point literal?
double
What do you need to do to designate a literal constant of the type float?
You must append the letter f or F. For eg., 6.7f or 6.7F
What is the size of the data type char?
16 bits (2 bytes)
What is the range of the data type char?
0-65535
Name a data type that supports the Unicode character set
char data type
What is the size of the boolean data type?
8 bits (1 byte) but uses only one bit
What is the range of the boolean data type?
true or false
Short description of boolean data type
Binary and boolean values
What is a variable?
It is an identifier that denotes a location in computer memory to store a data value. The variable may take different values at different times during the execution of the program
What is the condition for a variable to be used in a Java program?
It must be declared first
What does the computer do when it encounters a variable declaration?
- Sets aside memory for the variable
2. Associates variable name with memory location
Give the syntax of a simple variable declaration
data-type variable-name;
What does variable initialization mean?
Assigning a value to the variable
What is the default value of byte data type?
0
What is the default value of short data type?
0
What is the default value of int data type?
0
What is the default value of long data type?
0L
What is considered to be a good programming practice in case of declaration?
Not depending on the default value of the declared variable and initializing it instead
What is the default value of float data type?
0.0f
What is the default value of double data type?
0.0d
What is the default value of char data type?
‘\u0000’
What is the default value of boolean data type?
false
What is the default value of non-primitive type?
null
Which keyword is used to make the variable a constant?
final
What does the modifier final do?
In Java, the modifier final can be used in the variable declaration to ensure that the value stored in the variable cannot be changed after the variable has been initialized
What will the compiler show if an assignment operator tries to assign a value to a variable that has ‘final’ in front of it?
Syntax error
What are the advantages of using constants?
- With an underscore, they improve the readability and understandability of the program
- Any unintentional changes to such variables are flagged by the compiler
- Later, if there is a change in the value of such a variable, you just need to modify its value at one place and all the occurrences will be taken care of automatically
_ do not change their value; _ can change their value
Constants, variables
What is the purpose of comments?
To document the code and provide additional information that is not readily available in it, so that even a layperson can understand the written code
Where can comments not appear?
In the middle of an identifier, a reserved word or a literal constant
Name the three styles of comments in Java
- Single Line Comment
- Multiline Comment
- Documentation Comment
What is a single line comment?
It begins with a double slash (//) and continues to the end of the line
What does the compiler do if it encounters a double slash?
It ignores any text following it
What is a multiline comment?
It starts with initiating slash-asterisk (/) and ends with terminating asterisk-slash (/). There must be no space between the asterisk and the slash
What is a documentation comment?
It is a special comment that looks like a multiline comment, but it is generally used to generate external documentation about the source code
What does a documentation comment look like?
It starts with a forward slash followed by two asterisks (/**) and ends with an asterisk followed by a forward slash (*/)
What is documentation comment also called?
Javadoc
Name the points to remember while using comments
- Keep your comments clear and concise
- Arrange them in the code in an easy to see way
- Don’t make them too long or all over the statements
What are constants?
Memory locations whose values cannot be changed
Give another name for constants
Symbolic constants
The ASCII codes of A-Z are represented by decimal range?
65-90