chapter 5 Flashcards
(27 cards)
What does nextInt() call for?
A number with no decimal point in it.
What does nextDouble() call for?
A number with a decimal point in it.
What does next() call for?
A word ending in a blank space.
What does nextLine() call for?
A line. (or what remains of a line after you’ve already read some data from the line)
What does findWithinHorizon(‘.’, 0).charAt(0) call for?
A single character (such as a letter, digit, or punctuation character).
What are the 3 lines needed to use the Scanner class (in order)?
import java.util.Scanner;
Scanner keyboard = new Scanner(System.in);
keyboard.close();
Where is the Scanner class defined in Java?
In the Java API (java.util package).
What does System.in refer to, and where is it defined?
It refers to keyboard input and is defined in the Java API.
What happens if System.in is replaced with File?
Input is read from a file instead of the keyboard.
Why use import java.util.Scanner instead of the full name?
It shortens your code by avoiding repeated use of the fully qualified class name.
What is import java.util.Scanner an example of?
An import declaration.
What are key tips to remember when writing/running code?
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.
What should you do if you see error markings in your code editor?
Read the error messages for hints, and use quick fixes or review the related code.
What should you do when you see error markings in your editor?
Hover over or right-click them to read the error message and suggested solutions.
How do you view the details of an error in Eclipse?
Hover the mouse over the jagged red line or icon (X or lightbulb) to see the error and quick fix options.
Why shouldn’t you always rely on quick fix suggestions?
Some errors are deeper than syntax or spelling and require manual testing and debugging.
Do method headers end with semicolons?
No. Method headers do not end with semicolons.
Why aren’t quick fixes always accurate, and what should a programmer do instead?
Quick fixes are guesses by the editor. Programmers should review the code carefully, test, and adjust based on logic and understanding.
How can you get better at spotting errors in your code?
By writing more code—your eyes will naturally catch small mistakes over time.
What can be said about two similar quick fix suggestions in your code?
Similar solutions may not give the same result. Each error needs individualized attention.
What is a good way to practice spotting errors in your program and why?
Add errors to working programs to practice troubleshooting. This prepares you for bigger errors later.
What are the two categories of errors in Java?
Compile-time errors (caught while building) and runtime errors (appear during execution).
Example of a runtime error not visible at compile-time?
Changing ‘main’ to ‘Main’ causes a runtime error. Java is case-sensitive, so the JVM can’t find the method.
What’s the difference between compile-time and runtime errors?
Compile-time errors occur during coding in the editor; runtime errors occur when running the program.