3.1 Fundamentals Of Programming Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Name the two data types.

A

Primitive & Non-Primitive.

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

What do Primitive data types include?

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

What do Non-Primitive data types include?

A
  • String.
  • Arrays.
  • Classes.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How many Primitive data types are there in Java?

A

Eight.

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

Define a Byte data type.

A

Stores whole numbers from -128 to 127.

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

Define the size of a byte data type.

A

1 Byte (8 bits).

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

Define a Short data type.

A

Stores whole numbers from -32,768 to 32,767.

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

Define the size of a Short data type.

A

2 Bytes (16 bits)

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

Define an Int data type.

A

Stores whole numbers from -2,147,483,648 to 2,147,483,647.

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

Define the size of an Int data type.

A

4 Bytes (32 bits).

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

Define a Long data type.

A

Stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.

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

Define the size of a Long data type.

A

8 Bytes (64 bits).

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

Define the data type Float.

A

Stores fractional numbers. Sufficient for storing six to seven decimal digits.

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

Define the size of the Float data type.

A

4 Bytes (32 bits).

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

Define a Boolean.

A

Stores true or false values.

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

Define the size of a Boolean.

A

1 Bit.

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

Define a char.

A

Stores a single character/letter or ASCII values.

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

Define the size of a char.

A

2 Bytes (16 bits).

19
Q

Define the two primitive number groups.

A

Integer types & Floating Point types.

20
Q

Define the purpose of Integer types.

A

Store whole numbers, positive or negative, without decimals.

21
Q

Define the valid Integer Types.

A
  • Byte.
  • Short.
  • Int.
  • Long.

Which type you should use depends on the numeric value.

22
Q

Define a Double data type.

A

Stores fractional numbers. Sufficient for storing 15 decimal digits.

23
Q

Define the size of a Double.

A

8 Bytes (64 bits).

24
Q

Define the purpose of Floating Point Types.

A

Represent numbers with a fractional part, containing one or more decimals.

25
Q

Define the valid Floating Point Types.

A
  • Float.

- Double.

26
Q

Define the difference between Float and Double.

A

The precision of a floating point value indicates how many digits the value can have after the decimal point. Whereas the precision of float is only about six or seven digits, double variables have a precision of 15 digits. Therefore, it is safer to use double for most calculations.

27
Q

Define a Non-Primitive data Type.

A

A data type that refers to an object. This is why they are also called reference types.

28
Q

Define the difference between a primitive and non-primitive data type.

A

Primitive types are predefined in Java, whereas non primitive types are defined by the user within Java.

Non primitive data types can be used to call methods to perform certain operations whereas primitive types can not.

A primitive type must always have a value, whereas non primitives can be defined as null.

Primitive types can be defined at the start with a lowercase letter, whereas non primitives begin with an uppercase letter.

The size of a primitive type depends on the data type, whereas non primitives have all the same size.

29
Q

Define a record.

A

A data structure that groups together related items of data.

30
Q

Define how a record differs from an array.

A

Records are more complex than arrays as you can store more than one type of data together.

31
Q

Define the Java.time package class ‘LocalDate’.

A

Represents a date (year, month, day (yyyy-MM-dd)).

32
Q

Define the Java.time package class ‘LocalTime’.

A

Represents a time (hour, minute, second and nanoseconds (HH-mm-ss-ns)).

33
Q

Define the Java.time package class ‘LocalDateTime’.

A

Represents both a date and a time (yyyy-MM-dd-HH-mm-ss-ns).

34
Q

Define the Java.time package class ‘DateTimeFormatter’.

A

Formatter for displaying and parsing date-time objects.

35
Q

What method is used to display the current Date?

A

‘.now( );’
e.g.
LocalDate myObj = LocalDate.now();

36
Q

What method is used to display the current Time?

A

‘.now ( );
e.g.
LocalTime myObj = LocalTime.now()

37
Q

What method is used to display the current Date and Time?

A

‘.now ( );
e.g.
LocalDateTime myObj = LocalDateTime.now()

38
Q

Define the purpose of ‘ofPattern ( )’.

A

Accepts all forms of values, if you want to display the date and time in a different format.

39
Q

Define an array.

A

An array is used to store multiple values in a single single variable, instead of declaring separate variables for each value.

40
Q

What is the syntax to declare an array?

A

Define the variable type with square brackets.

e.g.

int[] myNum = {10, 20, 30, 40);

41
Q

Define a multidimensional array

A

An array containing one or more arrays.

42
Q

Define the syntax for a multidimensional array.

A

Add each array within its own set of curly braces.

e.g.

int[][] myNumbers = { {1, 2, 3, 4}, {5, 6, 7} };

43
Q

How to access the elements of a two dimensional array

A

Specify two indexes: One for the array one one for the element inside that array.

e.g.

int[][] myNumbers = { {1, 2, 3, 4}, {5, 6, 7} };
int x = myNumbers[1][2];