Data Structures Flashcards
What are the different datatypes in Java?
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).
What is the value of double z = x/y?
Java evaluate the righthand side first. So if x/y are ints it will default to an int first.
What is an example of string immutability?
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.
When would you use an Array over an ArrayList?
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.
What is an Array?
An array is a container object that holds a fixed number of values of a single datatype.