chapter 5 Flashcards

(27 cards)

1
Q

What does nextInt() call for?

A

A number with no decimal point in it.

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

What does nextDouble() call for?

A

A number with a decimal point in it.

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

What does next() call for?

A

A word ending in a blank space.

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

What does nextLine() call for?

A

A line. (or what remains of a line after you’ve already read some data from the line)

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

What does findWithinHorizon(‘.’, 0).charAt(0) call for?

A

A single character (such as a letter, digit, or punctuation character).

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

What are the 3 lines needed to use the Scanner class (in order)?

A

import java.util.Scanner;

Scanner keyboard = new Scanner(System.in);

keyboard.close();

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

Where is the Scanner class defined in Java?

A

In the Java API (java.util package).

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

What does System.in refer to, and where is it defined?

A

It refers to keyboard input and is defined in the Java API.

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

What happens if System.in is replaced with File?

A

Input is read from a file instead of the keyboard.

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

Why use import java.util.Scanner instead of the full name?

A

It shortens your code by avoiding repeated use of the fully qualified class name.

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

What is import java.util.Scanner an example of?

A

An import declaration.

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

What are key tips to remember when writing/running code?

A

Don’t expect perfect code on first try.

Errors are normal—read them carefully.

Check spelling, punctuation, and case.

Be patient.

Take breaks if frustrated.

Don’t doubt your ability—learning takes time.

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

What should you do if you see error markings in your code editor?

A

Read the error messages for hints, and use quick fixes or review the related code.

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

What should you do when you see error markings in your editor?

A

Hover over or right-click them to read the error message and suggested solutions.

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

How do you view the details of an error in Eclipse?

A

Hover the mouse over the jagged red line or icon (X or lightbulb) to see the error and quick fix options.

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

Why shouldn’t you always rely on quick fix suggestions?

A

Some errors are deeper than syntax or spelling and require manual testing and debugging.

17
Q

Do method headers end with semicolons?

A

No. Method headers do not end with semicolons.

18
Q

Why aren’t quick fixes always accurate, and what should a programmer do instead?

A

Quick fixes are guesses by the editor. Programmers should review the code carefully, test, and adjust based on logic and understanding.

19
Q

How can you get better at spotting errors in your code?

A

By writing more code—your eyes will naturally catch small mistakes over time.

20
Q

What can be said about two similar quick fix suggestions in your code?

A

Similar solutions may not give the same result. Each error needs individualized attention.

21
Q

What is a good way to practice spotting errors in your program and why?

A

Add errors to working programs to practice troubleshooting. This prepares you for bigger errors later.

22
Q

What are the two categories of errors in Java?

A

Compile-time errors (caught while building) and runtime errors (appear during execution).

23
Q

Example of a runtime error not visible at compile-time?

A

Changing ‘main’ to ‘Main’ causes a runtime error. Java is case-sensitive, so the JVM can’t find the method.

24
Q

What’s the difference between compile-time and runtime errors?

A

Compile-time errors occur during coding in the editor; runtime errors occur when running the program.

25
When should you use public class instead of a regular class?
Use public class if you want it accessible to other packages; avoid it if only internal access is needed.
26
how can two programs written by two different programmers with the same result be compared to snowflakes?
no two programs are alike when written by two different programmers
27
what's something to watch out for when writing quotation marks?
make sure you use straight quotation marks and not curly ones