Module 2: Basic Elements of Java Flashcards

(130 cards)

1
Q

Are user-defined names for methods, variables, constants, and classes

A

Identifiers

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

Rules in Naming Identifiers

A
  1. The first character of your identifier should start with a letter of the alphabet, an underscore (_), or a dollar sign ($).
  2. Identifier must contain no spaces.
  3. Identifier must contain no special characters.
  4. Keywords are Reserved words, thus it should not be used as Identifier
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Create identifiers that are _____.

A

descriptive of their purpose

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

If your identifier is composed of several words (65,535 characters is the maximum length per identifier), _____ is a good programming practice.

A

capitalizing the first letter of each word

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  • Specify the different sizes and values that can be stored in the variable variable
  • Defines the values that a variable can take
A

Data Types

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

Two Types of Data Types

A
  1. Primitive Data Type

2. Reference Data Type (Non-Primitive Data Type)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  • The building blocks of data manipulation.

- Basic data types available in Java language.

A

Primitive Data Type

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

Include Classes, Interfaces, and Arrays

A

Reference Data Type (Non-Primitive Data Type)

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

8 Primitive Data Types

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

Primitive Data Type:

true or false

A

boolean

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

Primitive Data Type:

two’s (2) compliment integer

A

byte, short, int, and long

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

Primitive Data Type:

unicode character

A

char

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

Primitive Data Type:

IEEE 754 floating point

A

float and double

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

Default value of boolean

A

false

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

Default value of byte

A

0

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

Default value of char

A

\u0000

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

Default value of short

A

0

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

Default value of int

A

0

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

Default value of long

A

0

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

Default value of float

A

0.0

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

Default value of double

A

0.0

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

Range of Values of boolean

A

true, false

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

Range of Values of byte

A

-128 to 127

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

Range of Values of char

A

Character representation of ASCII values 0 to 255

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Range of Values of short
-32,768 to 32,767
26
Range of Values of int
-2,147,483,648 to 2,147,483,647
27
Range of Values of long
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
28
Range of Values of float
up to 7 decimal digits
29
Range of Values of double
up to 16 decimal degits
30
Are identifiers whose values can be changed
Variables
31
The general syntax for declaring a variable is:
;
32
To declare a variable with an initial value, the syntax is:
=;
33
Are identifiers whose values never change once declared
Constants
34
The general syntax for declaring constants is:
final = ;
35
The process of assigning a value or variable of a specific type to a variable of another type
Type Casting
36
Type Casting is a method or process that _____ into _____ in both ways manually and automatically.
converts a data type; another data type
37
The _____ is done by the compiler and _____ performed by the programmer
automatic conversion; manual conversion
38
Two Types of Castings
1. Widening Type Casting | 2. Narrowing Type Casting
39
Converting a lower data type into a higher one
Widening Type Casting
40
Widening Type Casting is also known as _____
Implicit Conversion or Casting Down
41
Converting a higher data type into a lower one
Narrowing Type Casting
42
Narrowing Type Casting is also known as _____
Explicit Conversion or Casting Up
43
If we do not perform casting in Narrowing Type Casting then the compiler reports a _____.
compile-time error
44
In the case of Narrowing Type Casting, the higher data types (having larger size) are converted into lower data types (having smaller size). Hence there is the _____. This is why this type of conversion does not happen automatically.
loss of data
45
Are symbols that perform logical or mathematical functions on operands such as variables, constants, and objects
Operators
46
Java divides the operators into the following groups:
- Arithmetic - Unary - Shorthand Assignment - Relational/Comparison - Logical/Conditional - Bitwise
47
Are used to perform common mathematical operations
Arithmetic Operators
48
Are used to increasing or decreasing the value of an operand
Unary Arithmetic Operators
49
Adds 1 to the value of a variable
Increment Operator
50
Decreases 1 from a value of a variable.
Decrement Operator
51
Symbol for Pre-increment
++a
52
Symbol for Pre-decrement
--a
53
Symbol for Post-increment
a++
54
Symbol for Post-decrement
a--
55
Add 1 to the value of a first then use the value of a
Pre-increment
56
Subtract 1 to the value of a first then use the value of a
Pre-decrement
57
Use first the value of a then add 1 to its value
Post-increment
58
Use first the value of a then subtract 1 to its value
Post-decrement
59
This operator can be used to connect Arithmetic operator with an Assignment operator
Shorthand Assignment Operators
60
Assignment with Addition
+=
61
Assignment with Subtraction
-=
62
Assignment with Multiplication
*=
63
Assignment with Division
/=
64
Assignment with Modulus
%=
65
Equivalent Expression for +=
a = a + 20 | Example: a+= 20
66
Equivalent Expression for -=
z = z - w++ | Example: z -= w++
67
Equivalent Expression for *=
d = d * k | Example: d *= k
68
Equivalent Expression for /=
y = y / 1 | Example: y /= n+1
69
Equivalent Expression for %=
x = x % y | Example: x %= y
70
Are used to compare two values
Relational/Comparison Operators
71
Comparison Operators are mainly used when applying _____ in the program
control statements
72
The output of the relational operator is _____, and in Java, _____ is a non-numeric value that is not related to zero or one
(true/false) boolean value; true or false
73
Are those operators which are used to form compound conditions by combining two or more conditions or relations
Logical/Conditional Operators
74
Logical/Conditional Operators is also called _____.
Boolean Logical Operators
75
Logical/Conditional Operators operates on two Boolean values, which return _____.
Boolean values as a result
76
Symbol for Logical NOT
!
77
Symbol for Logical OR
||
78
Symbol for Logical AND
&&
79
Is a Unary Operator, it operates on single operands. It reverses the value of operands, if the value is true, then it gives false, and if it is false, then it gives true
Logical NOT
80
Is only evaluated as true when one of its operands evaluates true. If either or both expressions evaluate to true, then the result is true
Logical OR Operator
81
If both operands are true then only "______" | evaluate true
Logical AND Operator
82
Negates the value of the operand
The NOT! (!) Operator
83
Operator is a binary operator that returns true if at least one of its operands is true
The OR (||) Operator
84
Is a binary operator that returns true only when both operands are true. Otherwise, it will return false
The AND (&&) Operator
85
Is a binary operator that returns true when both operands have different values. Otherwise, it will return false
Bitwise Exclusive OR or XOR (^) Operator
86
Determines the order in which the operators in an expression are evaluated.
Operator Precendence
87
Operators with _____ are evaluated _____.
higher precedence; before operators with lower precedence
88
Precedence of Postfix
expr++ | expr-- | ( )
89
Precedence of Unary
++ expr | --expr | ! | ~
90
Precedence of Multiplicative
* / %
91
Precedence of Additive
+ -
92
Precedence of Relational
< > <= >= | instanceof
93
Precedence of Equality
== !=
94
Precedence of Bitwise XOR
^
95
Precedence of Logical AND
&&
96
Precedence of Logical OR
||
97
Precedence of Ternary
? :
98
Precedence of Assignment
= += -= *= /= %=
99
The operands of operators are evaluated from
left to right
100
Every operand of an operator (except the conditional operators &&, ||, and ? :) are evaluated completely _____ any part of the operation itself is performed
before
101
The _____ are evaluated completely before any part of the | _____ is evaluated
left-hand operand of a binary operator; right-hand operand
102
_____ get's preference over _____.
Order of evaluation given by parenthesis (); operator precedence
103
The _____ evaluates the incremented value while _____ evaluates the current value, then increments/decrements by one
prefix version of ++ or --; postfix version of ++ or --
104
_____ are evaluated from left to right except _____.
All binary operators; assignment operator
105
Use to print a string literal on the same line
Print Method
106
The position of the cursor remains on _____ after a string literal is printed on the monitor
the same line
107
The _____ are written continuously without a break.
string literals
108
Use to print a string literal on the next line
println Method
109
A character preceded by a backslash (\) is an _____ and has special meaning to the compiler
escape sequence
110
Escape Character: - Inserts a tab
\t
111
Escape Character: - Inserts a backspace
\b
112
Escape Character: - Inserts a new line
\n
113
Escape Character: - Carriage return
\r
114
Escape Character: - Form feed
\f
115
Escape Character: - Inserts a single quote
\'
116
Escape Character: - Inserts a double quote
\"
117
Escape Character: - Inserts a backslash
\\
118
Is widely used to parse text for strings and primitive types using a regular expression.
Java Scanner class
119
The _____ is used to _____, and it is found in the java.util package
Scanner class; get user input
120
By the help of _____ in Java, we can get input from the user in primitive types such as int, long, double, byte, float, short, etc.
Scanner
121
Reads a boolean value from the user
nextBoolean()
122
Reads a byte value from the user
nextByte()
123
Reads a double value from the user
nextDouble()
124
Reads a float value from the user
nextFloat()
125
Reads a int value from the user
nextInt()
126
Reads a String value from the user
nextLine()
127
Reads a long value from the user
nextLong()
128
Reads a short value from the user
nextShort()
129
What is the maximum length of of characters per identifier?
65,535
130
Java Keywords
``` abstract char double for instanceof private strictfp throws boolean class else goto interface protected super transient break const extends if long public switch try byte continue final implements naive return synchronized void case default finally import new short this volatile catch do float int package static throw while ```