4 Flashcards

1
Q
switch (var) {
case 1://if var = 1
//What happens
break;
case 2
\://if var = 2
//What happens
break;
default://Otherwise
//What happens
break;
}
A

How do you make a Switch statement?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
for (int i; i < 10; i++) {
//Program
}
A

How do you make loops?

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

In java, we have primitive types & objects.

Primitive types hold the actual value in memory.

Object hold references in memory.

A

What is a primitive type in Java?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. Is a - inheritance
  2. Has a - composition / aggregation

V47

A

Describe 2 classes can have.

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

BSILF DB CS

byte
short
int
long
float

double
boolean

char
String

A

Name 9 primitive types

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. Almost all inheritance can be rewritten
  2. Less about modeling the real world and more about modeling interactions in a system and roles and responsibilities
  3. Inheritance is difficult to maintain

V52

A

Name 3 reasons why favor composition over inheritance

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

x = x + 3;

A

What is this “x+=3” the equivalent of?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
=
\+=
-=
*=
/=
%=
-----------------
v20
A

What are 6 assignment operators?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  1. Treated like a primitive type (can be assigned w/o the New keyword) but it’s an object
  2. They’re immutable (can’t be changed). If you give a string a different value, it create an new string in memory.

Java Fundamentals - v22

A

Name to things about strings in Java.

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

System.out.println(firstName.indexOf(‘e’));

v23

A

Given: String firstName = “reynald”;

Writhe the line of code to out the index of letter ‘a’

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

int[] numbers = new int[3];

A
  1. Create an Array called ‘number’ w/ 3 slots

2. Write out the 2nd number

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

Calls the default constructor on the Printer class.

A

What does the ‘new’ key word do here when creating an instance?

Printer myPrinter = new Printer();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
  1. String[] colors = new String[] {“red”,”blue”, “Green”};
  2. for (String c : colors){
    System.out.println(c);
    }

v42

A

Create an array called ‘colors’ and add to it :”red”,”blue”, “Green”

    1. Create a foreach loop the writes out the contents of the arra
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
int ten = 10;
while(copies > ten)
{ 
System.out.println("Reynald");
copies --;
}
A
  1. Define a variable that = to ten.

2. Create a while loop that prints you name tens time.

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

public void printColors()
{
String[] colors = new String[] {“red”,”blue”, “green”,”yellow”};

for (String c : colors)
{
if("green".equals(c))
continue;
System.out.println(c); 
} 
}
A

Given this method below, implements ‘continue’ or ‘break’ statement if color is ‘green’

public void printColors()
{
String[] colors = new String[] {“red”,”blue”, “green”,”yellow”};

for (String c : colors)
{
System.out.println(c); 
} 
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Classes in OOP, are related to each other & they’re going to be related through an “IS-A” relationship or “HAS-A” relationship.

> IS-A relationship result from inheritance
HAS-A relationship result from composition

This comes from the need to reuse code.

v47

A

In OOP, describe is-a or has-relationships?

17
Q

Allows you to restrict the types that can be used in generics based on a class or interface.

v60

A

What are bounded types in Java?

18
Q

It’s useful to force code to execute whether or not an exception is thrown. It’s useful for IO operations to close files.

A

What’s the purpose of the Finally Block

19
Q

1) Checked Exception is required to be handled by compile time while Unchecked Exception doesn’t.
2) Checked Exception is direct sub-Class of Exception while Unchecked Exception are of RuntimeException.

A

What are checked & unchecked exceptions.

20
Q

Map - Look in module about collections.

A

What’s the equivalent of a dictionary in Java? Please create an example.