Final Flashcards

1
Q

How to use a try/catch?

A

try
{

}
catch(exceptionclass objectofexceptionclass)
{

}

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

Resources that have to be closed you can use:

Using this it closes it before exception is passed to handler

A
Try(PrintWriter outfile = newPrintWriter(“pets.txt”);
{
     outfile.println(“Chloe”);

}

//outfile.close() occurs after

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

__________ block always excecutes

A

finally

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

If an exception occurs in a finally block is is raised to it:

A

Handler

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

If clean other then close method is required, use:

A

Finally block

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

Finally block:

A

try
{

}
catch
{

}
finally
{
      Cleanup //occurs whether or not exception
                     //occurs
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

If there is no input when nextInt or nextDouble is called it was cause what exception?

A

No such element exception

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

I’m order to avoid NoSuchElementException use:

A

hasNextInt method

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

How to use hasNextInt() method:

A

Example:

If(in.hasNextInt())
{
int value = in.nextInt();
}

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

How to convert strings to ints?:

A

int year = Integers.parseInt(“2018”);

double price = Double.parseDouble(“10.99”);

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

How to use a delimiter?

A
Scanner in = new Scanner(. . .);
in.useDelimiter(“, “);

Separates at every “, “

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

How to process a file:

A
while(in.hasNext())
{
     String input = in.next();
     System.out.println(input);
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

An array collects collects a sequence of values of the ________ data type

A

Same

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

General format of array:

A

Ex:

double[] values = new double[10]

By Default each number is 0.0

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

How can you input data such as 1,2,3,4,5 into an array:

A

int[] example = { 1, 2, 3, 4, 5};

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

If you have to use array.length do not use:

A

Parentheses

17
Q

double[] values = new double[10];

System.out.println(“index 1: “ + values[4];

values[4] = 35.0;

System.out.println(“index 2: “ + values[4];

What is the output?

A

index 1: 0.0

Index 2: 35.0

18
Q

To grow an array that has run out of space use:

A

Array.copyOf method

19
Q

Array.copyOf method _________ the length of an array

A

Doubles

20
Q

With a partially filled array, you need to remember:

A

How many elements are filled

21
Q

a _________ belongs to the class, motto any of the objects of the class

A

Static variable

22
Q

All objects created from the class have access to the _________ static variable

A

Same