Operators in Java Flashcards

1
Q

What is an expression built using?

A

Constants, variables, operators and method calls

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

What are operators?

A

Symbols which are used in expressions to perform arithmetic or logical operations

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

What is operand?

A

The variable or literal on which the operator is applied

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

Name the three forms of operators

A
  1. Unary
  2. Binary
  3. Ternary
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a unary operator?

A

An operator that has just one operand.

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

Give examples of unary operators

A

+,-, ++, –, !

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

What is a binary operator?

A

An operator that has two operands in known as binary operator

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

Give examples of binary operators

A

+, %, >, &&, etc

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

What is a ternary operator?

A

An operator that has three operands is known as a ternary operator

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

Give example of a ternary operator

A

?:

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

What are arithmetic operators?

A

+, -, *, /, %

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

What is the result when two integers are divided?

A

The result of the division will also be an integer (the decimal part will be truncated

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

What are the two forms of the plus and minus operators?

A
  1. Unary form - adding/subtracting stuff

2. Preceding an operand

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

Name the process of joining two strings together

A

Concatenation

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

What are relational operators?

A

They determine the relationship between the two operands by comparing them

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

What is the outcome of relational operators?

A

The outcome of these operations is a boolean value which is either true or false

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

How many relational operators does Java provide?

A

6 types

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

Name the six types of relational operators

A
  1. Greater than (>)
  2. Less than (=)
  3. Less than or equal to (<=)
  4. Not equal to (!=)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What are logical operators?

A

They operate only on boolean operands and are used to construct simple decision making expressions

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

Name some logical operators

A
  1. Logical AND - &&
  2. Logical OR - I I
  3. Logical NOT - !
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the logical && operator?

A

It is a binary operator and is used to combine two conditions or expressions. The resultant value is a boolean value. The result is true if both values are two, and false if either is false

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

What is the logical | | operator?

A

It is a binary operator and is used to combine two conditions or expressions. The resultant value is also a boolean value. The result is true if both or either is true, false if both are wrong

23
Q

What is the logical NOT operator?

A

It is a unary operator and is written before a single operand. It negates the result of the expression following it

24
Q

What are assignment operators?

A

It is used to assign the value of an expression to a variable

25
Q

What type of operator is the assignment operator?

A

Binary operator

26
Q

Give the difference between = and ==

A

= is an assignment operator, whereas == is a comparison operator

27
Q

What are shorthand assignment operators?

A

Several variations of the assignment operator that are offered in Java

28
Q

Give two advantages of using shorthand operators

A
  1. They save a little bit of typing time
  2. The use of shorthand operators result in an efficient code as they are implemented most efficiently by Java run-time environment as compared to their long forms
29
Q

State the main shorthand operators

A
  1. +=
  2. -=
  3. *=
  4. /=
  5. %=
30
Q

What are increment and decrement operators?

A

The operators ++ and –are increment and decrement operators, respectively

31
Q

What type of operators are increment and decrement operators?

A

Unary

32
Q

What is the rule in postfix increment?

A

First use, then increment

33
Q

Explain the process of postfix increment

A
  1. Initially, the value of a variable y is 10, and the value of z us not defined
  2. You first use y, which is 10, hence z is assigned to the value 15
  3. You increment the value of y by 1. Thus, the final value of y = 16
34
Q

What is the rule in the Prefix increment?

A

First increment, then use

35
Q

What is the conditional operator?

A

It is also called a ternary operator because it has three operands

36
Q

What is the syntax of a conditional operator?

A

boolean-expression ? expression 1 : expression 2

37
Q

What is precedence of operators?

A

Each operator has a precedence associated with it. Precedence is the priority of an operator according to which it is evaluated. This precedence is used to determine the order of evaluation of an expression involving more than one operator.

38
Q

What is associativity?

A

If two operators have the same precedence, then they are either evaluated from “Left to Right” or from “Right to Left”. This is termed as associativity, which tells the direction of execution of operators

39
Q

Name the two steps involved in creating the object of the class datatype

A
  1. Declaring a variable of the class type

2. Allocating memory for the object where the details of the object can be stored

40
Q

What is the new operator used for?

A

To allocate memory for the object

41
Q

Give the syntax for creating an object of a class

A

Classname objectname = new Classname();

42
Q

What does it mean when a class is being instantiated?

A

An instance of the class is being created

43
Q

What is the purpose of the dot operator?

A

Once the objects have been declared and the memory has been allocated, member variables and member methods can be accessed using the dot operator

44
Q

Give the syntax of the dot operator

A

Objname.memberVariable;

Objname.memberMethod();

45
Q

What do you use to determine the order of evaluation of the operators when several operators appear in an expression?

A

Precedence and associativity

46
Q

What does an arithmetic expressoin represent?

A

A numeric value

47
Q

When does a type conversion take place?

A

When an arithmetic expression consists of constants and variables of different data types (mixed expression)

48
Q

What is type conversion?

A

It is a process that converts a value of one data type to another data type

49
Q

What are implicit type conversions?

A

The type conversions which are automatically performed by the Java compiler

50
Q

Give other names for implicit type conversions

A

Automatic type conversion, type promotion, widening conversion or coercion

51
Q

What are explicit type conversions?

A

In a case where a data type smaller than another has to hold a value of the bigger data type, a programmer has to force the conversion

52
Q

What needs to be done to create a conversion between two incompatible types?

A

A cast must be used, which is simply an explicit type conversion

53
Q

What is the drawback of using a cast?

A

It can lead to loss of precision. For example, when a double value is assigned to an int type, the fractional component is lost