Exam1 Flashcards

(62 cards)

1
Q

class header

A

public class C1 {

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

main method header

A

public static void main (String [] args) {

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

Random generator with seed

A

Random rand = new Random (seed);

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

random number from rand, to preset max

A

rand.nextInt(MAX+1)

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

create array myArr with howmany integers

A

int [] myArr = new int [howmany];

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

set up Scanner scnr

A

Scanner scnr = new Scanner (System.in);

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

for loop to howmany

A

for (int i = 0; i < howmany; i++) {

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

set x to next typed in integer input

A

x = scnr.nextInt();

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

package header

A

package P1;

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

import Scanner

A

import java.util.Scanner;

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

declare constant max and set as 2

A

final int MAX = 2;

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

for loop internal: print each

A

System.out.print(numbers[i])

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

if a method is not static…

A

it needs an object to call it, even in its own class.

e. g. c1 o1 = new c1();
o1. m1();

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

if a class is hidden public…

A

it can’t be accessed from a different package.

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

how to call a public static method in diff class, same package

A

e.g. class.method();

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

how to call a public static method in diff class, diff package

A

import package, call class.method

e. g. import package.class;
class. method();

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

how to call hidden public method in diff class, same package

A

create object, call object.

e. g. classname object=new classname();
object. method();

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

how to call hidden public method in diff class, diff package

A
import package, create object, call object.
e.g. import package.class;
classname object=new classname();
object.method();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

private methods…

A

cannot be accessed outside their class.

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

UML normal arrow means

A

uses or imports, for example a Random class from Java library. Read from stem to tip.

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

UML diamond with line means

A

aggregates (read from diamond to line)

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

aggregates indicates

A

an object or reference variable has been used

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

deep copy function

A

a new (editable) copy, a separate object, does not continue to reference the original

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

deep copy constructor example

A
C1 obj1 = new C1();
C1 obj2 = new C1(obj1);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
shallow copy function
link two objects that will keep updating each other
26
shallow copy constructor example
``` C1 obj1 = new C1(); C1 obj2; obj2 = obj1; ```
27
this.y
refers to a global variable y, where there is also a local variable y
28
constructor
a special method that is named the same as the class name, and is public, with no return value statement
29
example of default constructor
public C1 () {
30
example of parameterized constructor
public C1(int y) {
31
steps to make a deep copy in constructor class
1. default constructor 2. deep copy constructor
32
steps to make a deep copy in main class
1. create obj1 2. deep copy constructor creates obj2 as referring to obj1
33
interface contains
all abstract methods
34
abstract class contains
at least one abstract method
35
super keyword accesses
constructor in parent class
36
Can normal class inherit normal class?
yes
37
Can normal class inherit 2 abstract classes?
yes
38
Can normal class inherit abstract class?
only if it overwrites any abstract classes
39
Can abstract class inherit from normal class?
yes
40
Can normal class inherit from interface?
normal class can implement interface
41
UML symbol for interface
dotted line arrow
42
UML open triangle arrow
extends or inherits
43
polymorphism
create an object of parent that behaves like child
44
polymorphism example
C1 obj = new C2(); where C1 is parent and C2 inherits from C1
45
disadvantages of normal array
all data must be same type, fixed size, can't delete data (it would just revert to zero at that index, I think)
46
add value to array
myArray[index]=value;
47
make array
int [] myArray = new int [size];
48
Steps to make Arraylist
``` import java.util.Arraylist Arraylist name = new Arraylist(); ```
49
Steps to make a stack
``` import java.util.Stack Stack name = new Stack(); ```
50
populate arraylist
name.add(value);
51
arrays, Arraylists and stacks are
data structures
52
insert array list value at a certain index
name.add(index, value);
53
print arraylist
System.out.println(name);
54
print array
for loop...
55
remove value from arraylist
MyarrayList.remove(index);
56
clear Arraylist
Myarraylist.removeAll;
57
populate stack
myStack.push(value);
58
insert stack value at index
nope. use something else. Stacks are for adding and taking away from the top.
59
return top value of stack
stackName.peek();
60
return and then delete top value of stack
stackName.pop();
61
modifier codes in uml
+ public - private # protected
62
deep copy vs shallow copy described like web links
shallow copy: Now B shares the same URL that A is using. deep copy: Downloaded, copied and pasted all the data from that source - once and done. Now B has all that as its own source, whose values match for the moment.