Data Structures Flashcards

1
Q

What are the different datatypes in Java?

A

Java has two different datatypes: primitive and reference.
Primitives are the basic datatypes that come with Java(int, long,short,byte,boolean,float,double).
Reference datatypes are objects that can be created(Strings).

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

What is the value of double z = x/y?

A

Java evaluate the righthand side first. So if x/y are ints it will default to an int first.

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

What is an example of string immutability?

A

Once a string is created it cannot be altered. Example would be to make social security number a string rather than integers because of added protection and security.

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

When would you use an Array over an ArrayList?

A

Array- when you want to work with primitives and you already know the size of the data that you’re working with.

ArrayList- when you want more flexibility and you aren’t sure what the size of your data is. You want to work with objects.

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

What is an Array?

A

An array is a container object that holds a fixed number of values of a single datatype.

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