Data Types, Variables, & Expressions Flashcards

1
Q

What is a primitive data type in Java?

A

It specifies the size and type of variable values and has no additional methods.

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

What are the most commonly used numeric types in Java?

A
  1. int (for whole numbers)
  2. double (for floating-point numbers).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the integer types available in Java?

A
  1. Byte
  2. Short
  3. Int
  4. Long
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the floating-point types available in Java?

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

How should you indicate a long value in Java?

A

You should end the value with an “L”.

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

How should you indicate a float value in Java?

A

End the value with an “f”.

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

How should you indicate a double value in Java?

A

End the value with a “d”.

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

How can a floating-point number be expressed in scientific notation in Java?

A

Use an “e” to indicate the power of 10.

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

What values can the boolean data type in Java take?

A

The boolean data type can only take the values true or false.

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

What are boolean values mostly used for in Java?

A

Boolean values are mostly used for conditional testing.

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

What is the purpose of the char data type in Java?

A

The char data type is used to store a single character.

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

How should a character be enclosed in Java?

A

The character must be surrounded by single quotes, like ‘A’ or ‘c’.

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

What is the String data type used for in Java?

A

The String data type is used to store a sequence of characters (text).

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

How should String values be enclosed in Java?

A

String values must be surrounded by double quotes.

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

Why is String considered a non-primitive data type in Java?

A

Because String refers to an object.

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

What are non-primitive data types also known as, and why?

A
  • ‘references’ because they refer to objects.
17
Q

Can you name some examples of non-primitive data types in Java?

A

Examples include String, Arrays, Classes, and Interfaces.

18
Q

How are primitive data types and non-primitive data types defined in Java?

A

Primitive types are predefined in Java, while non-primitive types are created by the programmer (except for String).

19
Q

What is a key functional difference between primitive and non-primitive data types in Java?

A

Non-primitive types can call methods to perform operations, whereas primitive types cannot.

20
Q

What is a key difference between primitive and non-primitive data types regarding their values?

A

A primitive type always has a value, while non-primitive types can be null.

21
Q

How do the naming conventions differ between primitive and non-primitive data types in Java?

A

Primitive types start with a lowercase letter, while non-primitive types start with an uppercase letter.

22
Q

What is the purpose of variables in Java?

A

Variables are containers for storing data values.

23
Q

How can you ensure a variable’s value cannot be changed in Java?

A

Use the final keyword to declare the variable as “final” or “constant,” making it unchangeable and read-only.

24
Q

What is type casting in Java?

A

It is when you assign a value of one primitive data type to another type.

25
Q

What are the two types of type casting in Java?

A
  1. Widening Casting (automatically)
  2. Narrowing Casting (manually)
26
Q

What is widening type casting in Java?

A

It is converting a smaller type to a larger type size.

27
Q

What is narrowing type casting in Java?

A

It is converting a larger type to a smaller size type.

28
Q

How can you combine text and a variable in Java?

A

Use the + character to concatenate text and a variable.

29
Q

What are identifiers in Java?

A

Identifiers are unique names used to identify Java variables.

30
Q

What is recommended when choosing identifiers for Java variables?

A

It is recommended to use descriptive names to create understandable and maintainable code.