Chapter 5 Flashcards

1
Q

when you are dealing with upscale and dangerous technology, why is it important that everything that is written in a program is written precisely without errors? give a real historic example.

A

NASA scientists caught an error that could have trashed the Mercury space flights. (Yup! These were flights with people on board!) The error was a line with a period instead of a comma. (A computer programmer wrote DO 10 I=1.10 instead of DO 10 I=1,10.)

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

what’s something to keep in mind when it comes to spelling your programs correctly?

A

In Java, consistent spelling and capitalization are very important — if you’re not consistent within a particular program, the program will probably have some nasty, annoying compile-time errors.

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

when making a new project why should you mark the box labeled public static void main(String[] args}?

A

Optionally, you can put a check mark in the box labeled public static void main(String[] args}. If you leave the box unchecked, you’ll have a bit more typing to do when you get to Step 8. Either way (checked or unchecked), it’s no big deal. Click Finish.

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

why should or shouldn’t you copy and paste code rather than writing it yourself?

A

This strategy might be okay, as long as all the spelling when transfered and pasted is spelled correctly as sometimes some symbols like quotation marks may be curly but in Java you must avoid curly quotation marks and instead use straight quotation marks. as long as the spelling results are correct, there should be no problem copying and pasting someong else’s code.

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

what’s something to remember when you want to type inside of the console view after a run?

A

If you forget to click inside the Console view, Eclipse may not send your keystrokes to the running Java program. Instead, Eclipse may send your keystrokes to the editor or (strangely enough) to the Package Explorer.

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

what is keyboard.nextLine( ); ?

A

It is to type a line of text into your code after you run the program.
as you run the code this will stop the code dead in it’s tracks waiting for you to type and input something from your keyboard onto the console view, and then you press enter to gain the results of your code unless you have several keyboard.nextLine( ); in your code will you be prompted again to types something else and then hit enter again. basically it’s to input what you type into the keyboard to affect that part in your code

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

what is calling keyboard.nextInt() for?

A

geting numbers (integers) from the keyboard with no decimal in it.

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

what is calling keyboard.nextLine for?

A

getting a line of text from the keyboard.

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

what is calling keyboard.nextDouble for?

A

getting a number from the keyboard that has a decimal in it.

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

what is calling keyboard.next() for?

A

Typing a word into the console

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

what is calling findWithinHorizon(“.”,0).charAt(0) for?

A

getting a single character from the keyboard, whether it is a letter a number or a punctuation symbol

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

what 3 lines of code are needed to read input from the keyboard when using keyboard.next() keyboard.nextLine keyboard.nextInt etc. ?

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
13
Q

what is the good news and bad news of the 3 important lines of code that are part of the keyboard.next kinds of code?

A

the bad news is the reasoning behind it can be easily misunderstood but the good news is you can just copy and paste it , you dont need to know the reasoning behind it.

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

when using the scanner method, what’s the first line in your code?

A

Make the import java.util.Scanner line the first line in your program.

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

where do you put the Scannr keyboard = new Scanner(System.in) line?

A

Put the Scanner keyboard = new Scanner(System.in) line inside the main method immediately after the public static void main(String args[]) { line.

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

when using a scanner method, where do you place keyboard.close() line?

A

Make the keyboard.close() line the last line in your program.

17
Q

define Scanner

A

The word Scanner is defined in the Java API. A Scanner is something you can use for getting input. This Scanner class belongs to Java versions 5.0 and higher.

18
Q

what is System.in?

A

The words System and in are defined in the Java API. Taken together, the words System.in stand for the computer keyboard.

19
Q

what is an example of an import declaration?
What can you do with it?

A

The line import java.util.Scanner is an example of an import declaration. The optional import declaration allows you to abbreviate names in the rest of your program.

20
Q

how do you get to know the nature of a jagged line error?

A

If you hover the mouse cursor over any of these markers, Eclipse displays a message that attempts to describe the nature of the error. If you hover over the jagged line, Eclipse displays a message and possibly a list of suggested solutions. (Each suggested solution is called a quick fix.) If you right-click the left margin’s marker (or control-click on a Mac) and choose Quick Fix in the resulting context menu, Eclipse displays the suggested solutions. To have Eclipse modify your code automatically (using a suggestion from the quick-fix list), either single-click or double-click the item in the quick-fix list. (That is, single-click anything that looks like a link; double-click anything that doesn’t look like a link.)