chapter 4 Flashcards

(43 cards)

1
Q

Do programmers type code as fast as 100 words per minute?

A

No, programming is tedious. You must check for mistakes while writing and test the code multiple times.

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

Is learning programming difficult?

A

No, but it requires patience and step-by-step learning.

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

Is writing and running a Java program a lot of work?

A

Yes. Even displaying a simple sentence requires extra lines of code.

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

How is Java different from English?

A

Java is for communicating with computers; English is for humans. Java is easier since computers don’t understand English.

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

What are Java keywords?

A

Words with a fixed meaning that never changes across programs.

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

Is Java case-sensitive?

A

Yes, but identifiers (names for variables, methods, etc.) are not.

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

How many keywords are in Java?

A
  1. const and goto exist but are unused.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which words look like keywords but aren’t?

A

true, false, null are not keywords.

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

Can you redefine a keyword?

A

No. Keywords are set by Oracle and cannot be used as identifiers.

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

What is an identifier?

A

A name used to label something in a program.

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

What happens if you change an identifier name?

A

Only the name changes, but modifying standard API names can confuse other programmers.

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

What is the standard API?

A

A list of commonly used identifier names in Java.

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

What is a literal?

A

A fixed value (like a number or text) written directly in code.

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

How do you write large numbers clearly in Java?

A

Use underscores (e.g., 1_000_000.00).

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

How do number separators vary in Java?

A

Different regions use commas, underscores, or no separators at all.

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

Why is punctuation important in Java?

A

Every bracket, brace, and symbol has a role in making code functional.

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

What is indentation in Java?

A

Indentation makes code structure clear by showing hierarchy.

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

How do curly braces relate to indentation?

A

They act like ‘boxes’ that group related code together.

19
Q

How can Eclipse auto-indent code?

A

Select the Java file, then go to Source > Format in the menu.

20
Q

What is a comment in Java?

A

A note for programmers that the computer ignores.

21
Q

Why use comments?

A

Helps programmers remember their code when revisiting later.

22
Q

What is a traditional comment?

A

A comment enclosed in /* … */. Extra * can be added for neat formatting.

23
Q

What is an end-of-line comment in Java?

A

An end-of-line comment starts with two slashes (//) and extends to the end of the line.

24
Q

How do you switch off parts of your program without deleting code?

A

Comment out the code; it’s like turning it on/off by adding/removing the comment symbols.

25
What is a Javadoc comment?
A Javadoc comment starts with /** and helps generate documentation for your code using Oracle’s Javadoc tool.
26
What is a Java method?
A Java method is a block of code with a name that performs a specific task when called.
27
What is a method declaration?
It’s the method's signature, including the name and parameters (if any), followed by the method body enclosed in curly braces.
28
What is a method call?
A method call invokes the method to execute its instructions.
29
What can be said about calling the main method into action?
The main method is called automatically when the program runs.
30
When are instructions in a method executed?
When the method is called. If it's main, it's called automatically.
31
Can a statement also be a method call?
Yes. Example: System.out.println("Hello"); is both a method call and a statement.
32
What symbol ends every statement in Java?
A semicolon ;.
33
Why do some call OOP 'Class-Oriented Programming'?
Because everything in Java is written inside a class.
34
What is the purpose of curly braces {}?
To mark where a block of code starts and ends, interpreted by the computer
35
Why do we indent code?
To make code easier for humans to read and follow.
36
What symbols must be used to properly indent and structure code?
Curly braces {} for blocks, and spaces/tabs for visual indentation.
37
What is an escape sequence in Java?
A special character preceded by a backslash (\) used to represent characters that can’t be typed directly into a string.
38
What does the escape sequence \" do?
Inserts a double quote (") inside a string.
39
What does the escape sequence \' do?
Inserts a single quote (') inside a string.
40
What does the escape sequence \\ do?
Inserts a backslash (\) into the string.
41
What does the escape sequence \n do?
Moves the output to a new line (newline).
42
What does the escape sequence \t do?
Inserts a horizontal tab (adds spacing).
43
What are the rules for creating valid identifier names in Java?
Follow these rules to create valid identifier names in Java: ✅ Must start with a letter (A–Z or a–z), an underscore (_) or dollar sign ($). ✅ Can contain letters, digits (0–9), underscores, and dollar signs after the first character. ❌ Cannot start with a digit (e.g., 7name is invalid). ❌ Cannot contain spaces or special characters like @, #, /, or -. ❌ Cannot use reserved keywords (e.g., public, class, static, etc.). ✅ Java is case-sensitive (myVar ≠ MyVar).