Arrays And Methods Flashcards

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

What are Primitive Data Types?

A

Static - set amount of memory, actual valve stored in memory location, pass by value
ex: int, double, boolean, float, etc

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

What are Object Type variables?

A

Reference Type, memory set aside varies, pass by reference
ex: String, Array

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

What is an array?

A
  • Data structure that can hold multiple valves of the same type (advantage)
  • can store primitive and non primitive data types (advantage)
  • faster, takes less memory (advantage)
  • fixed size - static (disadvantage)
  • has less buit in methods (than array list) (disadvantage)
  • Initializing: int[] list = new int [10];
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a 2D Array?

A
  • an array of arrays (ex: chessboard)
  • declaring: int [] [] array = new int [4] [3];
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is an Arraylist?

A
  • a class in java that can hold any type of object (No Primitive data types - boolean, char, int)
  • can grow or shrink while program is running (advantage)
  • has additional methods that are helpful (advantage)
  • more flexibility and more dynamic (advantage)
  • slower due to memory demands (disadvantage)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do we declare an Arraylist?

A

1) import jan package: import java.util.Array List;
2) ArrayList < Type> arrayName = new ArrayList < Type> ();

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

How do we declare an Arraylist?

A

1) import jan package: import java.util.Array List;
2) ArrayList < Type> arrayName = new ArrayList < Type> ();

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

What is Method Overloading?

A

When there are two or more methods within the same class that share the same name but different parameters

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

What are methods?

A
  • breaks code to smaller parts (advantage)
  • easier to debug (advantage)
  • more efficient and organized (advantage)
  • can reuse code (advantage)
  • best used to separate calculations, check data, etc
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the types of methods?

A
  • Functional - return type - executes code, then returns a value
  • Procedural - void type - executes code, but doesn’t return value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Parts to a method

A

sum = getSum (num1 , num2); – argument
public static int getSum (int num1, int num2) { – modifiers, return type, method name, parameters

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

What is scope of variables?

A
  • part of program that variables can be accessed from
  • variables can only be accessed from the block it’s in
  • ex: variable in a method can be used throught method but not in other methods
  • variables cannot be accessed before they are declared
  • Local variables cannot be accessed outside of the method
  • variables defined in a block can only be accessed within the block
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is Pass by Value?

A
  • When a copy of variable is sent to the method
  • if value of variable is changed in the method there is no effect on the original copy, because they are discarded after exiting the method
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is Pass by Reference?

A
  • When a memory location of the value is sent to the method
  • this changes the values of the reference because they are not copies
  • ex: array
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Similarities and Differences between Bubble Sort and Improved

A

Bubble Sort: uses rested for loops , best case # of comparasions: n (n-1) / 2 , best case time: O (n^2)

Similarities: Worst case for # of comparisons: n (n-1) / 2, Worst case for time: O (n^2)

Improved: uses boolean variable, uses while condition, more efficient, Best # case: n- I, Best time case: O (n)

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

Similarities and Differences between Bubble Sort and Improved

A

Bubble Sort: uses rested for loops , best case # of comparasions: n (n-1) / 2 , best case time: O (n^2)

Similarities: Worst case for # of comparisons: n (n-1) / 2, Worst case for time: O (n^2)

Improved: uses boolean variable, uses while condition, more efficient, Best # case: n- I, Best time case: O (n)