Basics_Java Flashcards

1
Q

Where do we put parameters for a function?

A

we use parameters to pass values to function

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

Where do we put the methods for our functions?

A

Inside the curly braces.

In Java the curly brace is on line with function name and return type

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

what is a good function (method name)?

A

clearly identifies the purpose of the function

camelCase notation

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

What is a function?

A

A block of code that performs a task

Think of buttons on a remote

In Java, functions are the smallest building blocks

Ex. functions to validate user info, convert weight to kgs

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

What is a package?

A

A concept for grouping related classes.

We will have hundreds or thousands of classes.

We should organize these classes into packages.

Java creates a namespace for our classes:

com.namespace

*every class we create in our program will belong to this package

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

Where do we specify a return type?

A

A function is a block of code that performs some task.

We specify the return type before the name.

Some functions don’t return anything.

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

Where is the entry point into our program?

A

Every Java program must have one function.

The main function is executed first.

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

What is a class?

A

A container for related functions.

We use classes to organize our code.

Ex. The supermarket has related products in different “classes” or sections.

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

What class must every Java program have?

A

Every program in Java has a main class that contains the main function.

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

What is a method?

A

A method is a function that is part of a class

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

What is an access modifier?

A

A special keyword that determines if other classes and methods can access these classes and methods.

Private

Public

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

What is the naming convention for classes and methods?

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

What are the two steps involved in running a Java program?

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

How do we get byte code?

A

Java Compiler changes our source code into byte code

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

Who developed Java?

A

At Sun Microsystems.

Sun Microsystems was later acquired by Oracle in 2010.

It was originally called Oak named after the tree outside Goslings office.

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

Where can our Java byte code run?

A

Java byte code is platform-independent

It can run on Linux, mac, windows or any operating systems that have a Java Run-Time Environment

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

What is java byte code?

A

The instruction set for the Java Virtual Machine

Assembled code is runnable on a CPU with a specific instruction set, while bytecode can be executed in a virtual machine (such as the Java runtime) on any CPU that can run the VM. Assembly code is (represents) the native code for the processor you are programming.

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

What is a Java Run Time Environment?

A

The Java Runtime environment has a component called Java Virtual Machine (JVM)

JVM translates our byte code into the native executable language for various platforms (Mac, Windows, Linux)

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

What is byte code?

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

What does the Java Virtual Machine (JVM) perform?

A

Converts our Java Byte code into the native code for the operating system we are using like a mac, windows or linux operating system.

This makes applications portable.

Can execute on Linux, Mac or any other operating systems that have a Java Run-Time Environment.

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

Who owns Java?

A

Oracle

Oracle Corporation is the current owner of the official implementation of the Java SE platform, following their acquisition of Sun Microsystems on January 27, 2010.

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

How many editions are there of Java?

A

Four Editions for different types of applications

SE - all the libraries all Java developers must learn

EE - provides additional libraries for building fault-tolerant multi distributed systems

ME - libraries specific for mobile phones

Java Card - for smart cards

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

How many worldwide developers does Java have?

A

9 million developers world wide

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

How many mobile phones run Java?

A

3 billion mobile phones currently run Java

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

What is JDK?

A

Java Development Kit

Software Development Environment

Compiler

Reusable Code

Java Run Time Environment

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

How many TV sets run Java?

A

120 Million TV sets

Every blue-ray device

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

What is JVM?

A

The JVM has two primary functions:

to allow Java programs to run on any device or operating system (known as the “Write once, run anywhere” principle), and

to manage and optimize program memory.

When Java was released in 1995, all computer programs were written to a specific operating system, and program memory was managed by the software developer. So the JVM was a revelation.

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

What is the average US salary for a Java developer?

A

$101,929 USD

Java is everywhere.

There are many opportunities to get hired as a professional Java developer.

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

What topics does this course include?

A

Build clean code

Fix bugs and errors

Understand types

Create algorithms

Package and deploy programs so other people can use them!

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

What’s included in types?

A

Variables and Constants

Primitive and Reference Types

Casting

Numbers, Strings and Arrays

Reading Input

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

What is a variable?

A

A variable is how we temporarily store data in computer memory.

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

What is an identifier?

A

The name of a variable

”=” is assignment operator

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

What can we do with variables?

A

Copy the value of one into another

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

What is the naming convention for variables?

A

Camel case!

lowercase first letter Uppercase other letters!

Ex. int herAge = 30

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

What are the two types in Java?

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

What are the primitive types in Java?

A

int - allow us to store values up to 2 billion

long - store numbers greater than 2 billion

double - storing values with decimal values

float - storing values decimal values

char - storing characters

boolean - store true or false

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

What is best practice for variables?

A

always use meaningful, descriptive names

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

What must we do to a long type in Java?

A

add and L after the value.

By default Java compiler recognizes a number as an integer.

Put an L after to tell Java compiler its a long!

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

What must we do to use a float type?

A

Java see’s numbers with decimals as doubles by default.

We have to add a suffix to represent the number as a float

Add “F”

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

How do we initialize a char type?

A

surround single characters by single quotes

string represents a series of characters

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

What are reference types?

A

objects + their members (data/functions)

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

What is casting?

A

Type conversion

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

How do we initialize reference types (objects)?

A

use the new operator

Allocate memory

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

How will Java execute this statement?

A

First, allocate some memory to store the point object

Next, allocate a separate part in memory to store a reference (the address) to the point object

Finally, assign this reference to the variable name

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

How are primitive types stored in memory?

A

Value is stored in the variable at that memory location

x and y are completely independent of each other

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

What are we copying into pointTwo in this expression?

A

The reference to pointOne object in memory, not the point object

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

What is the crucial difference between how primitive and reference types are stored in memory?

A

When we declare a primitive variable like a byte the value we assign is stored in that memory location.

When we use a reference type our variable holds the reference (address) of the object in memory not the actual value.

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

How does Java store reference types in memory?

A

Variable holds the address or reference of the object in memory, not the actual value.

Two variables can reference the same object.

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

What should we remember about the differences between primitive and reference types?

A

Remember,

reference types are copied by references.

primitives are copied by values and are completed independent of each other.

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

What are strings in Java?

A

Strings are reference types.

We use a short way to create them (can omit the new operator)

Strings are a class so we can access methods with the dot operator!

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

What can we do with strings?

A

because strings are a class,

we can access methods like ends with, length, indexOf(), replace etc.

Ex. check length of user input string

Ex. give the index of the first character

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

What is the difference between parameters and arguments?

A

parameters are the holes we define in our methods.

arguments are actual values we pass to these methods.

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

What are strings in Java?

A

Immutable

We cannot mutate them, we cannot change them

any methods that modify a string create a new string object

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

What is a useful string method in Java?

A

the trim method

used if a user types unnecessary white spaces in form fields

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

What don’t primitive types have?

A

Members

properties (data) or functions

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

What is an object?

A

An instance of a class

A reference type

object/classes have members we can access using the dot operator

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

What type are arrays?

A

Reference types

We need the new operator

we can access elements or items in the array via an index

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

By default, when we print an array what does Java return?

A

Java returns the string of the address in memory

to see the actual items in the array we must use the array’s class

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

What is a shortcut for generating

System.out.println()

?

A

“sout” + Tab

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

How many bytes are used in primitive types?

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

How can we initialize string objects in Java?

A

String is a reference type however, we have a shortcut

Can omit the new operator

JavaRuntime will handle

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

How do we return the string representation of an array?

A

Use the array class .toString method

there is a .toString for every primitive type

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

What two categories of types in java?

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

What is one of the differences between the primitive and reference types in java?

A

Reference types use the new operator to allocate memory for the reference variable

Primitive types don’t require us to allocate memory java run time environment does this for us!

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

What are the four most common String escape sequences?

A

" = "fileNames"

\n = new line

**** = \

\t = tab

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

What is a modern syntax for initializing an array when you know the values ahead of time?

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

What do we use arrays to do?

A

Store a list of items:

numbers

people

message

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

Describe the Arrays class in Java?

A

Defined in Java.util

Has useful methods:

Arrays.toString

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

What can we create in Java?

A

Multi-dimensional array’s

Can create a 2D array to store a matrix

or a 3D array to store data for a cube

These are useful for scientific computations

Ex. two rows and three columns

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

What is the convention for naming constants?

A

all CAPS

add the final

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

What arithmetic operators do we have in Java?

A

All the same in math like “+” “-“ “*” “/”and “%” (modulus or remainder)

/ gives a whole number

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

What is method overloading?

A

In Java.util package

Arrays Class

Arrays.toString method - returns string rep of array

defined for all primitive types

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

What is an expression?

A

A piece of code that produces a value

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

How can we execute a division to produce a decimal result?

A

s are called operands

By default Java returns integer values for integer division.

Cast our input into double

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

What must we do when using division?

A

cast the numbers into a double

76
Q

What is the incrememnt operator?

A

if we want to increment a value

we can add ++

Can say ++x (prefix) OR x++ (suffix) same value

77
Q

What is the x, y and j values be in this expression using increment operator?

A
78
Q

What will the value of x and y by using the increment operator (prefix) in this expression?

A

First, Java will increment x by one x (=2)

Then, Java will copy x value to y (=2)

79
Q

How can we declare a constant in Java?

A

add final keyword

cannot change value later in program

80
Q

What will the value of x and y by using the increment operator as a suffix in this expression?

A

First, Java assigns the value of x (=1) to y

Then, increments x by one x (=2)

81
Q

What happens when we use the increment operation after the assignment operator?

A

if increment as a suffix x++

first value of x is copied to y

then x is incremented by 1

if increment as a prefix ++x

first, x is incremented by 1

then copied to y

82
Q

What is the augmented (compound) assignment operator?

A

We can increment by 2

x+=2 will increment x by 2 and copy into x

83
Q

What are the order of operations in Java

A

If we want a value calculated first,

we can put it in parentheses.

84
Q

What is implicit casting?

A

Automatic casting / automatic conversion

Java allocates an anonymous variable in memory

that variable is another primitive type (byte, int, long)

Java copies value into this new anonymous variable

If the value can be converted into a bigger type, Java automatically does this for us.

short = two bytes

int = four bytes

85
Q

When does implicit data casting happen?

A

when there is no change for data loss

when we are going from a smaller to a larger data type

86
Q

What is explicit casting?

A

convert x to an integer w/o decimal point

x will be added to 2 result = 3

87
Q

When can explicit casting only happen?

A

between compatible types

all number types

cannot cast a string to a number

88
Q

What are wrapper classes?

A

For all primitive types, have wrapper classes

reference type defined in java.lang

reference classes have methods

like parseInt() which takes a string returns a short or int

89
Q

Why does casting matter?

A

in most GUI data from the user is received as a string!

If we have text boxes or drop down lists almost always we receive data as strings

we must convert these strings to numerical representatives

90
Q

What does the Math.max class return?

A

The greater of two values

91
Q

How to comment out a block of code in Java?

A

Control + Shift + /

92
Q

What is the Math.random ( ) method return?

A

A random number (float)

to set between a value, multiple by range

93
Q

How can we explicitly cast and round a random number?

A

pass the random method as an argument to the round method

explicitly cast the value into an integer

94
Q

How can we input data in Java?

A

use the scanner class

Java will do implicit casting to make the int value of age into a string and concatenate

95
Q

What is the shortcut for renaming a variable?

A

Shift + F6

96
Q

How can we read a string using the scanner class?

A

using the scanner.next ( ) method

97
Q

How do we read the whole line using the scanner method?

A

use the scanner.nextLine ( )

98
Q

What is the shortcut for renaming a variable?

A

Shift + F6

99
Q

How can we chain multiple methods to remove whitespace when reading a string in Java?

A

use the dot operator to access members (methods) of the string object

call the trim method

then store value in the name variable

100
Q

How to implement a mortgage calculator?

A

First attempt

No input validation

Written as procedural code

101
Q

What is control flow?

A

controlling the flow of execution of our programs

102
Q

What is control flow?

A

controlling the flow of execution

103
Q

Why do we use loops?

A

executing code repetitively

Ex.

For loops

For each

While loops

Do-while

104
Q

What is covered in this section?

A

Comparison operators

comparing values

Ex.

>= <= ==

Logical operators

implementing real-world rules

Ex.

&& != ||

Conditional statements

making decisions around code execution in our programs

Ex.

If, switch statements

Loops

executing code repetitively

Ex.

for, while loops

105
Q

What are comparison operators?

A

Used for comparing values

greater than

equal to

less than

>=

<=

==

106
Q

When do we use comparison operators?

A

To compare primitive values

Ex. is x and y the same?

107
Q

What is the equality operator?

A

a boolean expression

returns true/false

represented with two equal signs “==”

108
Q

What is the inequality operator?

A

A boolean expression

!=

returns a true/false

109
Q

Why do we use conditional statements?

A

Making decisions in our programs

Ex. If statements

110
Q

What are other equality operators?

A

>=

(greater than or equal)

<=

(less than or equal)

These return boolean (true/false) values

111
Q

How does Java evaluate && logical operator?

A

Evaluates from left to right

First, it looks at the leftmost condition

if false, doesn’t look at other conditions, returns false

112
Q

What do we use logical operators for?

A

Implementing real-world rules

& || !

113
Q

What does a single “=” mean?

A

the assignment operator

we use it to assign a value to a variable

114
Q

When is the || operator true?

A

The or || operator is true if at least one condition is true.

115
Q

When do we use the NOT operator?

A

To reverse a value

if the value hasCriminalRecord = false;

!hasCriminalRecord returns true

116
Q

What is a clean way to simplify an if statement?

A

use a boolean operator

wrap in ( ) to be clear

117
Q

How can we reformat our if-statement so it’s easier to read?

A

Remove { } braces from single statement clauses

put else if on the line below ending curly brace ( { )

118
Q

What’s the problem with declaring a variable in our if-statement?

A

It’s only available within that code block

we cannot access outside

119
Q

How can we read data from the user?

A

Use the Scanner class!

Read from the console:

new Scanner (System.in)

120
Q

How do we implement an if statement?

A

If statement

three clauses

look at format

Hierarchy

parent w/ two children

} else if (condition)

} else

121
Q

Why are if statements extremely powerful?

A

They allow build programs to make decisions based on certain conditions?

Ex. Printing messages on console based on certain conditions

122
Q

What do we type inside the brackets after an if statements?

A

A boolean value

if the condition is true, the statements in curly braces are executed.

123
Q

What is a clause in an if statement?

A

a section

parent and children hierarchy

If only one line of code in the if statement can omit the { }

Technically, people say always have { }

124
Q

What is the problem with this if statement?

A

The variable hasHighIncome is only available within the curly braces!

125
Q

What is one way we can solve the issue of only being able to access a variable within curly braces?

A

Declare the variable outside the if-statement

set the value to true within the statement

**this code look amateurish

126
Q

How can we improve out if-statement?

A

we can set the variable to an initial value.

Or

we can set our variable to an expression and eliminate the if-statement entirely

if the expression is true it will evaluate to true, otherwise it will evaluate to false.

127
Q

Why does Mosh wrap the right side of the expression in parentheses?

A

To make it more clear

now it’s clear that on the right side of the assignment operator we have a boolean expression

128
Q

What kind of code doesn’t a professional programmer write?

A

This kind.

One way to fix this is give the variable an initial value

This can be simplified even further using a ternary operator!

129
Q

How do we use the ternary operator?

A

Condition (boolean expression)? value #1 : value #2

We start with our condition

then we add a “?”

if the first condition is true, value after “?” is assigned

otherwise the value after “:” is assigned

String className = income > 100_000 ? “first” : “economy”

130
Q

When do we use switch statements?

A

To execute different parts of code depending on the value of the expression.

like an if-statement

131
Q

Why do we add a “break” statement to our switch statement?

A

Java will continue to execute the other cases

once it evaluates a break statement it jumps out of the switch statement

132
Q

How do we implement a switch-statement?

A

add a break after each case

default will execute if no cases are met

133
Q

What’s the correct solution to FizzBuzz?

A
134
Q

How do we implement the FizzBuzz method?

A

Put the most specific statements on top

Java evaluates top to bottom

135
Q

What’s the trade-off with this implementation of FizzBuzz?

A

It has a nested structure.

Mosh prefers a flat structure.

Additional nested structures make the code hard to read

136
Q

What three things do we do inside the ( ) of a for loop?

A
  1. Declare a counter variable ( i , j , k) - loop counters
  2. Declare a boolean expression - declare how long loop is executed
  3. Increment loop counter

*If a single expression, don’t need curly braces but if multiple statements must declare a code block

137
Q

How does Java execute a for loop?

A
  1. first it initializes i to zero (first statement)
  2. Then it evaluates the boolean (if true, executes code block)
  3. At end of loop, control moves to increment i to ++
138
Q

How can we implement a for loop using the decrement operator?

A

Output:

Hello World 5

Hello World 4

Hello World 3

Hello World 2

Hello World 1

139
Q

How does the ternary operator work?

A

start with a condition

if the condition is true, evaluate and assign value after “?”

otherwise, if the condition is false, evaluate and assign value after “ : “

140
Q

Why is this not the right solution for FizzBuzz?

A

Because of the way Java executes the if statement

Sequentially executes

Put most complex case first

Simpler cases follow

141
Q

What is the basic syntax for a while loop?

A

initialize a loop variable

set a condition for termination

execute code in the block

decrement the counter variable

142
Q

When should we use a for loop vs. while loop?

A

For Loop:

We know how many times we want to execute one or more statements

While Loop:

We don’t know exactly how long to execute

143
Q

How can we write a while loop to continuously ask a user to enter something until they write quit?

A
144
Q

What are Do..while loops?

A

Similar to while loops

Gets executed at least once

the condition gets checked last

145
Q

What is the syntax for a do-while loop?

A
146
Q

While loops vs. Do…While loops?

A

While loops

check conditions first, if false it never gets executed.

do..While loops

we check the condition last!

Do…while loops are rare and we often use while loops!

147
Q

How does Java execute the break statement?

A

it ignores everything after and break statement and exits out of the loop.

148
Q

What is an example of a for loop?

A

Set counter to count down or count up!

149
Q

What is the continue statement in a while loop?

A

Java sees the continue statement

moves the control to the beginning of the loop

all statements after are ignored

150
Q

What is a common technique used by professional developers when writing while statements?

A

set the while condition to (true)

the loop is executed forever until the break condition is met!

make sure to use a break statement otherwise, you have an infinite loop!

151
Q

What must we include when writing always true while statements?

A

while (true)

include a break statement!

otherwise, you have an infinite loop!

152
Q

What is the basic structure of a for loop?

A

use “for” keyword

a counter variable and initialize

boolean expression determines how many times loop is executed

increment the counter variable

153
Q

When do we use For-Each loops?

A

When iterating over an array or collection!

Replaces a for loop

we don’t have to write a numeric counter

we don’t have to write a boolean expression

we don’t have to increment our counter

154
Q

How do we declare a for-each loop?

A

inside for ( )

include the type of array (collection) we are iterating over

declare a variable to hold the value of each item one at a time in our collection per iteration.

Ex.

155
Q

What are the limitations of for-each loops?

A

For each loop:

  1. Forward only - Cannot iterate end to the beginning.
  2. Don’t have access to index - loop variable stores only one item

For Loop:

can access values by index

156
Q

How can we iterate over an array backwards using a for ( ) loop?

A

Set the counter variable to length of the array

as long as i is greater than 0

print value at the index of counter

decrement counter

157
Q

How can we implement a while loop to handle error validation in our mortgage calculator?

A

Initialize the variables to zero outside the loops!

158
Q

What separates an outstanding programmer from an average programmer?

A

Knowing how to write good code:

Code that is clean and expressive

159
Q

What does Martin Fowler say about clean coding?

A

Mosh puts a lot of emphasis on clean code!

160
Q

What is Mosh going to show us in this section?

A

The most important techniques for writing clean code.

161
Q

What is a parameter variable just like?

A

It’s just the same as if we declared a local variable inside

it’s like a local variable inside the method

162
Q

How do we create a method?

A

camelCase for method name and parameters

parameter is like a local variable inside the method

163
Q

How do we create a method that returns a value?

A

Change return type

call the method from the main class

Give it an argument

store the return value in a variable

164
Q

What is the syntax for multiple method parameters?

A

cameCase for parameter identifiers

separate with a comma

165
Q

How do we return a value from our method?

A

Change return type from void to String

return keyword to return value

*when calling this method can store the return value in a variable

166
Q

What is refactoring?

A

Changing the structure of our code without changing its behavior.

Extracting certain methods and putting them in other methods.

Extracting methods

Refactoring Repetitive Patterns

167
Q

When refactoring, what two things should we look for?

A
  1. Look for conceptually close code - lines of code that always go together. Bring lines together into a separate private method. Can re-use method in the future!
  2. Repetitive patterns in code - code that uses repetitive loops asking the same questions using similar patterns
168
Q

How long should our ideal methods be?

A

5-10 lines of code!

No more than 20 lines!

169
Q

How can we extract a method for calculating the mortgage?

A

Create a method for calculating mortgage

Call this method in the main class

170
Q

How can we extract code into a method using an Intellij shortcut?

A

Right-click the lines

Select Refactor

Select Extract

Choose Method

171
Q

How can we refactor these repetitive loops?

A

Create a readNumber method!

172
Q

What debugging and deploying application topics are covered?

A
173
Q

What are compile-time errors?

A

Syntax errors.

Prevent us from compiling our applications.

Happen when we don’t follow grammar or syntax of Java.

Easy to find and fix!

174
Q

What is a great resource for a syntax error you don’t know?

A

Stackoverflow.com!

Professional programmers and enthusiasts!

Search for error message 99% of time you can find a page on this error!

175
Q

How can we find run time errors?

A

Debugger!

Execute our code line by line.

Look at the value of various variables!

176
Q

What are the two types of errors?

A

Compile-time: syntax or grammar errors, use IntelliJ or StackOverflow

Run-time errors: use Debugger to look at variables

177
Q

What are the common compile-time errors?

A
  1. Forget to specify the data type of variables
  2. Forget to add a semi-colon to the end of statements!
  3. Call a method without using ( )
  4. Print a string without double quotes
  5. misspell or incorrectly capitalize a variable name (Java is case sensitive)
  6. using reserve keywords for identifiers
  7. using a single “=” to compare values”==”
178
Q

Do you have to pay to use Java?

A

Yes and No.

No, it’s open-source.

Yes, there are additional features/support you can pay to use.

179
Q

What is the call stack in the debugger?

A

An area where we can see all the methods that were executed in reverse order!

Useful for debugging large applications!

Can set a breakpoint and watch all the methods to get there!

180
Q

What are watches in the debugger?

A

can set watches to view specific variable values

181
Q

What does deploying web or mobile apps require?

A

Additional steps outside the scope of this course.

182
Q

What is a module?

A

Another layer of abstraction above packages

183
Q

What must we do if we want to share our Java program (console program) with someone else?

A

need to package it into a .jar file

Java Archive - contains all code for distribution

Anyone with Java Run Time environment can run it

184
Q

How do we generate a .jar file in IntelliJ?

A

File -> Project Structure -> Artifacts

Build -> build artifacts

185
Q

What is the IntelliJ shortcut for multi-cursor editing?

A

Option (press) + option (hold) + down arrow