Data Types & Variables (H3) Flashcards

(68 cards)

1
Q

Encoded to a program is stored in memory and can have and be in several types—for example, using a person’s basic information such as name, age, and address.

A

Data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Describe possible operations on the data and the storage method.

A

Data Types

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Data Types in Java are Classified in 2:

A
  1. Primitive
  2. Abstract
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Built into the Java language. These are data that are not objects and have no methods. The Java compiler has detailed instructions on the valid operations this data type supports.

A

Primitive Data Types

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Primitive Data Types that java defines:

A
  1. byte
  2. short
  3. int
  4. long
  5. float
  6. double
  7. char
  8. boolean
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Java defines Byte, Short, Int, and Long as _. Since Java does not support unsigned integers, these four (4) are signed, positive, and negative values.

A

Integer Data Types

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Java does not support unsigned integers as these are mostly used to specify the behaviors of the—

A

High-order bit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

defines the sign of an integer value, and Java manages it differently by adding a special “unsigned right shift” operation.

A

High-order bit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Integer Types:

A
  1. byte
  2. short
  3. int
  4. long
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Default number java knows:

A

Integer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

The smallest integer type that represents a small number. It is used to declare a variable holding a natural number between -128 and 127.

A

Byte

Byte variables are declared by use of the byte

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Byte range:

A

-128 to +127 signed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

An integer is considered _ if its value is between -32768 and 32767. _ data types declare a variable that can hold numbers in that range.

A

Short

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Short Range

A

-32,768 to +32,767

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

A _ number can also be initialized as a Short variable instead of a normal decimal integer.
So, the 3001 integer can be written as 0x4A8. 0x is used in Java to represent:

A

Hexadecimal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

This data type can handle larger numbers and is considered the best choice when an integer is needed because when Byte and Short values are used in an expression, they are promoted to _ automatically.

A

Int

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Int Range:

A

-2,147,483,648 to 2,147,483, 647

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

This data type holds a number higher than a regular integer. The _ integer is a variable that can hold a very large number. A capital letter ‘L’ is placed right after the value.

A

Long

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

also called “real numbers”, and are used when evaluating an expression that needs fractional accuracy such as the computation of square root or a transcendental (sine and cosine)

A

Floating Point Types

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Floating Point Types:

A
  1. float
  2. double
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

described as a single precision floating point. A real number qualifies as a single precession when it only needs a limited number of bits. Single precision takes half the space of a double precision and is much faster on some processors.

_ are used to represent dollars and cents, so a small letter ‘f’ is placed to the right of the value when initializing the variable.

A

Float

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Floats are used to represent dollars and cents, so a _ is placed to the right of the value when initializing the variable.

A

small letter ‘f’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

A real number qualifies as a _ when it only needs a limited number of bits. _ takes half the space of a double precision and is much faster on some processors.

A

single precission

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

_ can be faster than single precision on modern processors that have been optimized for high-speed mathematical calculations. It can handle larger numbers than Float.

A

Double

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Character types can be divided into two (2):
(a) A Byte for a character (ASCII) and (b) a type in itself (Unicode).
26
ASCII meaning
American Standard Code for Information Interchange – a code that assigns numbers to letters, digits, etc.
27
Allows Byte data types to be used to declare a variable that would hold a single character to initialize such variable or assign a **single quoted character**.
Byte for a Character Type **You need single quotes for a byte for it to initialize as a ASCII** (ASCII for 'f' is 102)
28
To support characters that are not traditionally used in (US) English and do not work with compilers, the _ character format was created which includes **Latin-based** and **non-Latin-based languages**. The Char data type was created to support _ characters in Java.
Unicode **To initialize, assign the character variable in single quotes.**
29
This data type is used for **logical** values and can only hold true or false values. It is a type returned by all relational operators such as =, >, and <.
Boolean
30
These are based on primitive data types but with more functionality. For example, String is an abstract data type that can store letters, digits, and other characters such as a slash (/), comma (,), parentheses (()), semi-colon (;), dollar sign ($), and a hashtag (#).
Abstract Data Types
31
an abstract data type that can store letters, digits, and other characters such as a slash (/), comma (,), parentheses (()), semi-colon (;), dollar sign ($), and a hashtag (#). This also provides methods for linking two (2) strings, searching for one string within another, and extracting a portion of a string.
String
32
Performing calculations on a variable of the **string data type** is _, even if the data stored in it has digits
Not allowed
33
a code that assigns numbers to letters, digits, etc.
American Standard Code for Information and Interchange or ASCII
34
Long range
-2^63 to 2^63-1
35
±1.4 × 10⁻⁴⁵ to ±3.4 × 10³⁸
Float
36
±4.9 × 10⁻³²⁴ to ±1.8 × 10³⁰⁸
Double
37
Char range
0 to 65,535
38
What are the sizes of these: Byte Short Int Long
Byte: 8 Short: 16 Int: 32 Long: 64
39
What are the sizes of these: Float Double Char Boolean
Float: 32 Double: 64 Char: 8 Boolean: 1
40
Java uses **constants and variables** for **storing** and **manipulating** data in a program. The values of variables can be changed in a program, but the value of ___, **cannot**.
constants
41
Unique names must be assigned to ________.
variables and constants
42
If the name “digit” refers to an **area in memory** where a numeric **value is stored**, then “digit” is a _.
Variable
43
_ is defined by the combination of an identifier, a type, and an optional initialization depending on the task to be performed.
Variable
44
Regardless of the data type, each variable used in a program must be ___. The “digit” variable must be ____ with an **Int data type** since it refers to a memory storing an **integer value**.
Declared
45
Just like identifiers, naming ___ must follow specific rules and conventions. The program will not compile if the programming language rules are not followed.
variables
46
In general, here are the **rules** for naming **variables**.
1. The name of a variable must be **meaningful**, short, and without any embedded space or symbols. However, **underscores (_) can be used**. 2. Variable names must be **unique**. 3. A variable name must begin with a letter, a dollar sign, or an underscore. 3. **Keywords cannot be used** for variable names.
47
For **Java**, here are the **variable naming conventions**.
1. Variable names should be **meaningful**. 2. The names must reflect the data that the variables contain. 3. Variable names are **nouns** and must **begin** with a **lowercase letter**. 4. If a variable name contains two or more words, begin each word with an **uppercase letter**. However, the first word will start with a lowercase letter.
48
To declare more than one (1) variable of the same data type, a ___ separated list is used.
A comma (,)
49
Variables cannot also be used without ______ them.
initializing
50
Java assigns a **default value** to the ____ class variables **when creating an object or a class**.
primitive data types **class variables**
51
The following displays the default initial values that are used to initialize the data members of a class. **Data Type** Byte: Short: Int: Long: Float: Double: Char: Boolean: Abstract:
Data Types and their **Default Initial Value** Byte: 0 Short: 0 Int: 0 Long: 0L Float: 0.0 Double: 0.0 Char: 'u0000' Boolean: false Abstract: Data Type Null
52
0 or the default data types is **replaced** by the **actual value to be used**. The values are only automatically assigned to the data members of a class that are of the **primitive data types**. Java returns an error if the **variable** declared in a method is not ___.
initialized
53
In Java, **variables** can be assigned with ____. The ____ to be assigned **must have the data type** of the **variable**.
Answer: **Constant** Values More info: Constants are permanent values (cannot be changed) (Not Constant) int age = 18; age = 19; System.out.println(age); // prints 19 (Constant) **final** int BIRTH_YEAR = 2007; BIRTH_YEAR = 2008; //error (u cant change a constant)
54
_____ are the values that may be assigned to primitive- or string-type variables and constants.
Literals
55
Boolean literals are ____ and cannot use numbers to represent them.
true or false
56
___ are numeric data that can be represented as octal, hexadecimal, and binary literals. Octal is the number with a zero prefixed. Hexadecimal is the number prefixed with 0x. Binary Literal is the number that starts with 0B or 0b. An underscore (_) can be used to improve the readability of the numeric data.
Integer Literals
57
(Integer Literals) ___ is the number with a **zero prefixed**.
Octal (Integer Literals)
58
(Integer Literals) ____ is the number **Prefixed with 0x**.
**Hexadecimal** (Integer Literals)
59
(Integer Literals) ___ is the number that starts with 0B or 0b.
Binary Literal (Integer Literals)
60
(Integer Literals) An _ can be used to **improve the readability** of the numeric data.
underscore "_" (Integer Literals) Int aMillion = 1_000_000
61
(Integer Literals) reminder that an underscore (_) at the start and end of a literal is _.
**Not allowed**
62
____ are **numbers that have a decimal fraction**. A suffix letter F (lower or uppercase) to the number; otherwise, the compiler will flag about loss of precision.
Floating-point literals
63
**Floating-point literals** are numbers that have a decimal fraction. A ____ is needed to the number; otherwise, the compiler will flag about loss of precision.
A **suffix letter F** (lower or uppercase)
64
___ must also be enclosed in single quotes (‘,’). The **Unicode value** of the character is also **allowed**.
Character literals
65
**Character literals** must also be enclosed in ___. The Unicode value of the character is also allowed.
single quotes (‘,’)
66
(Character Literal) A _ can also be used to represent a character that can be typed in as a literal.
backslash "\\"
67
_ are enclosed in double quotes (","). _ are included as literal as they can still be typed directly into the code, even though it is **not a primitive type**.
String literals
68
string literals are enclosed in __. Strings are included as literal as they can still be typed directly into the code, even though it is not a primitive type.
double quotes (",")