Chapter 4 Flashcards

1
Q

when a programmer is faced with someone else’s code, how fast should they be to be considered average or above average?

A

Even experienced programmers approach a new project slowly and carefully.

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

is programming meant to seem daunting and difficult to do?

A

don’t be intimidated. When you get the hang of it, programming is pretty easy. Yes, it’s fun, too.

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

is coding a lot of work, or is it all an easy breeze?

A

I admit that writing and running a Java program is a lot of work just to get the words Chocolate, royalties, sleep to appear on somebody’s computer screen, but every endeavor has to start somewhere.

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

what is a GUI?

A

it is the program that is created that contains buttons, menus, windows, text fields and other widgets that users can interact with . an example would be a software program that contains menus, buttons, text fields, windows and other widgets in like FL studio

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

as Java is considered a language like English,what are their similarities and what’s the difference between English and Java?

A

both English and Java are called languages and that is no coincidence. You use a language to express ideas. English expresses ideas to people, and Java expresses ideas to computers. What’s more, both English and Java have things like words, names, and punctuation. In fact, the biggest difference between the two languages is that Java is easier to learn than English. (If English were easy, computers would understand English. Unfortunately, they can’t.)

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

how does english grammar have similarities as java ?

A

In your high school grammar class, you worried about verbs, adjectives, and other such things. But in this book, you think in terms of keywords and identifiers

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

how is a keyword similar to words in english?

A

a keyword is a dictionary word — a word that’s built right into a language.

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

do keywords ever change their meaning or i should say function?

A

Each Java keyword has a specific meaning — a meaning that remains unchanged from one program to another. For example, whenever I write a Java program, the word public always signals a part of the program that’s accessible to any other piece of code.

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

when it comes to writing keywords what is something you should keep in mind if you want to avoid errors?

A

The java proGRAMMing lanGUage is case-sensitive. ThIS MEans that if you change a lowerCASE LETTer in a wORD TO AN UPPercase letter, you chANge the wORD’S MEaning. ChangiNG CASE CAN MakE the enTIRE WORD GO FROM BeiNG MEANINGFul to bEING MEaningless. In Listing 4-1, you can’t replace public with Public. If you do, the WHOLE PROGRAM STOPS WORKING.

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

what is the complete list of Java keywords and how many is there?

A

abstract continue for new switch assert default goto package synchronized boolean do if private this break double implements protected throw byte else import public throws case enum instanceof return transient catch extends int short try char final interface static void class finally long strictfp volatile const float native super while///// there are 50 keywords in Java

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

are the words, “true, false and null” considered keywords?

A

In Java, the words true, false, and null have specific meanings. As with the keywords in Table 4-1, you can’t use true, false, and null to mean anything other than what they normally mean in a Java program. But for reasons that concern only the fussiest Java experts, true, false, and null are not called Java keywords. One way or another, if you scribble the words true, false, and null into Table 4-1, you’ll be okay.

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

is it possible to change the meaning of a keyword? why or why not?

A

Here’s one thing to remember about keywords: In Java, each keyword has an official, predetermined meaning. The people at Oracle, who have the final say on what constitutes a Java program, created all of Java’s keywords. You can’t make up your own meaning for any of the Java keywords. For example, you can’t use the word public in a calculation: //This is BAD, BAD CODE: public = 6;

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

are there any keywords that you should avoid using in Java?

A

Despite my ardent claims in this section, two of Java’s keywords have no meaning in a Java program. Those keywords — const and goto — are reserved for nonuse in Java. If you try to create a variable named goto, Eclipse displays an Invalid VariableDeclaratorId error message. The creators of Java figure that if you use either of the words const or goto in your code, you should be told politely to move to the C++ programmers’ table.

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

what is an identifier?

A

In computer programming, an identifier is a noun of some kind. An identifier refers to a value, a part of a program, a certain kind of structure, or any number of things.

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

what’s the difference between a keyword and an identifier?

A

identifiers are the made-up words ThingsILike and args. class ThingsILike { public static void main(String args[]) { Just as the names Ann and Chrisanta have no special meaning in English, the names ThingsILike and args have no special meaning in Java. keywords cannot be changed as their meanings are set and cannot be changed and identifiers can be changed as they have no special meaning. As long as you update their name in the code, you can change the identifier name.

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

is it recommended to name identifiers any random name? why or why not?

A

Make up sensible, informative names for the things in your Java programs. Names like GooseGrease are legal, and they’re certainly cute, but they don’t help you keep track of your program-writing strategy. if you write whatever for an identifier’s name it will also confuse other users and programmers reading your code so make sure their names make sense according to the program you are building.

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

should you use keywords as identifiers?

A

When I name my Java program, I can use ThingsILike or GooseGrease, but I can’t use the word public. Words like class, public, static, and void are keywords in Java.

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

when it comes to boiler plate code such as public static void main string args, should you change the name of args since it is an identifier?

A

The args in (String args[]) holds anything extra that you type when you issue the command to run a Java program. For example, if you get the program to run by typing java ThingsILike won too 3, then args stores the extra values won, too, and 3. As a beginning programmer, you don’t need to think about this feature of Java. Just paste (String args[]) into each of your programs.

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

where do you find the definitions of the identifiers that were created by Java?

A

In Java, almost all these identifiers are defined in the Java API.

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

define the agreed upon meanings of main, string, system, out and println?

A

Here’s a quick rundown on the meaning of each of these names (and more detailed descriptions appear throughout this book): main: The main starting point for execution in every Java program. String: A bunch of text; a row of characters, one after another. System: A canned program in the Java API. This program accesses some features of your computer that are outside the direct control of the Java Virtual Machine (JVM). out: The place where a text-based program displays its text. (For a program running in Eclipse, the word out represents the Console view. To read more about text-based programs, check the first several paragraphs of Chapter 3.) println: Displays text on your computer screen.

21
Q

when typing println what is something to pay attention and correct in case you type it wrong? LN tells the computer to do what?

A

The name println comes from the words “print a line.” If you were allowed to write the name in uppercase letters, it would be PRINTLN, with a letter L near the end of the word. When the computer executes println, the computer puts some text in Eclipse’s Console view and then immediately moves to the beginning of the next line in preparation for whatever else will appear in the Console view.

22
Q

what is a literal?

A

A literal is a chunk of text that looks like whatever value it represents.

23
Q

when using numbers for values , if they represent no other meaning then what are they refered to as?

A

Most of the numbers that you use in computer programs are literals. If you put the statement mySalary = 1000000.00; in a computer program, then 1000000.00 is a literal. It stands for the number 1000000.00 (one million).

24
Q

what can you do so that your code is easier to read when typing large numbers?

A

If you don’t enjoy counting digits, you can put the following statement in your Java 7 program: mySalary = 1_000_000.00; Starting with Java 7, numbers with underscores are permissible as literals.

25
Q

is missing a punctuation symbol in your program important?

A

Each bracket, each brace, each squiggle of any kind plays a role in making the program meaningful.

26
Q

what is punctuation used for in Java?

A

the code’s punctuation guides the indenting of certain lines. The indentation shows which parts of the program are subordinate to which other parts

27
Q

what is the purpose for curly braces?

A

a pair of curly braces acts like a box. To make the program’s structure visible at a glance, you indent all the stuff inside of each box.

28
Q

why is it important to indent your code?

A

I can’t emphasize this point enough: If you don’t indent your code or if you indent but you don’t do it carefully, your code still compiles and runs correctly. But this successful run gives you a false sense of confidence. The minute you try to update some poorly indented code, you become hopelessly confused.

29
Q

what should you do so you won’t worry about going back to your code later to correct indentation?

A

Take my advice: Keep your code carefully indented at every step in the process. Make its indentation precise, whether you’re scratching out a quick test program or writing code for a billionaire customer.

30
Q

what’s a quick way to indent a big chunk of code without having to do it manually?

A

Eclipse can indent your code automatically for you. Select the .java file whose code you want to indent. Then, on Eclipse’s main menu, choose Source ⇒ Format. Eclipse rearranges the lines in the editor, indenting things that should be indented and generally making your code look good.

31
Q

what are comments and how are they useful?

A

A comment is text that’s outside the normal flow. In Figure 4-2, the words “That’s a sentence” aren’t part of the Ann sentence. Instead, these words are about the Ann sentence. The same is true of comments in computer programs. The first five lines in Listing 4-1 form one big comment. The computer doesn’t act on this comment. There are no instructions for the computer to perform inside this comment. Instead, the comment tells other programmers something about your code.

32
Q

if you set aside your projects for a while and come back to it, how are comments beneficial?

A

Comments are for your own benefit, too. Imagine that you set aside your code for a while and work on something else. When you return later to work on the code again, the comments help you remember what you were doing.

33
Q

how many kinds of comments does the java language use and what are their names?

A

The Java programming language has three kinds of comments: traditional comments, end of line comments, javadoc comments

34
Q

what is a traditional comment?

A

Traditional comments: this comment begins with /* and ends with /. Everything between the opening / and the closing */ is for human eyes only.

35
Q

what gets translated by the compiler when using traditional comments?

A

Nothing between /* and */ gets translated by the compiler.

36
Q

what can be said if you write a traditional comment that spills over to the second, third and fourth lines?

A

extra asterisks can be placed in the second, third, and fourth lines. these asterisks are called “extra” because these asterisks aren’t required when you create a comment.

37
Q

what’s the purpose for extra asterisks when a traditional comment reaches the second, third and fourth lines?

A

They just make the comment look pretty and for some reason that I don’t entirely understand, most Java programmers add these extra asterisks.

38
Q

what’s the purpose for extra asterisks when a traditional comment reaches the second, third and fourth lines?

A

They just make the comment look pretty and for some reason that I don’t entirely understand, most Java programmers add these extra asterisks.

39
Q

what’s the purpose for extra asterisks when a traditional comment reaches the second, third and fourth lines?

A

They just make the comment look pretty and for some reason that I don’t entirely understand, most Java programmers add these extra asterisks.

40
Q

how does an end-of-line comment look like?

A

An end-of-line comment starts with two slashes and extends to the end of a line of type.

41
Q

what is it to comment out code? how is this useful? give an example

A

When you’re writing a program and something’s not working correctly, it often helps to try removing some of the code. If nothing else, you find out what happens when that suspicious code is removed. Of course, you may not like what happens when the code is removed, so you don’t want to delete the code completely. Instead, you turn your ordinary Java statements into comments. For example, turn System.out.println(“Sleep”); into /* System.out.println(“Sleep”); */. This keeps the Java compiler from seeing the code while you try to figure out what’s wrong with your program.

42
Q

what does a javadoc comment look like?

A

Javadoc comments: A special Javadoc comment is any traditional comment that begins with an extra asterisk:

43
Q

where does a javadoc comment come from?

A

The Java SE software that you download from Oracle’s website includes a little program called javadoc.

44
Q

the javadoc program does what to a javadoc comment?

A

The javadoc program looks for these special comments in your code.

45
Q

what is a javadoc used for?

A

The program uses these comments to create a brand-new web page — a customized documentation page for your code.

46
Q

if you wanted to know more about turning javadoc comments into web pages, what can you do?

A

To find out more about turning Javadoc comments into web pages, visit this book’s website (http://allmycode.com/BeginProg).

47
Q

What is a method?

A

In Java, a method is a list of things to do. Every method has a name, and you tell the computer to do the things in the list by using the method’s name in your program. Whatever you call it in your favorite programming language, a method is a bunch of instructions collected together and given a new name.

48
Q

what 2 parts make up the method declaration?

A

the header, and the call If you have a basic understanding of what a method is and how it works (see preceding section), you can dig a little deeper into some useful terminology: If I’m being lazy, I refer to the code in Listing 4-2 as a method. If I’m not being lazy, I refer to this code as a method declaration.

49
Q

what makes up the method declaration?

A

The method declaration in Listing 4-2 has two parts. The first line (the part with the name fixTheAlternator in it, up to but not including the open curly brace) is called a method header. The rest of Listing 4-2 (the part surrounded by curly braces) is a method body. The term method declaration distinguishes the list of instructions in Listing 4-2 from the instruction in Listing 4-3, which is known as a method call. (in other words the entire piece of code both header and body is the declaration.