Skip to content

Commit d7941e7

Browse files
committed
Null
1 parent 94d3205 commit d7941e7

File tree

13 files changed

+87
-80
lines changed

13 files changed

+87
-80
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
Book teaching how to write modern and effective Java. It is maintained by the community, anyone can contribute.
88

9-
Feel free to join our [discord server](https://discord.com/invite/XXFUXzK)
9+
Feel free to join our [discord server](https://discord.gg/together-java-272761734820003841)
1010
if you have any questions, or require assistance with the project. :relaxed:
1111

1212
## Getting started

src/SUMMARY.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,17 @@
9595
# Control Flow I
9696

9797
- [Branching Paths](./branching_paths.md)
98+
9899
- [If](./branching_logic/if.md)
99-
- [Else](./branching_logic/else.md)
100100
- [Nested Ifs](./branching_logic/nested_ifs.md)
101+
- [Else](./branching_logic/else.md)
101102
- [Else If](./branching_logic/else_if.md)
102103
- [Relation to Delayed Assignment](./branching_logic/relation_to_delayed_assignment.md)
103104
- [Scoped Variables](./branching_logic/scoped_variables.md)
104105
- [Conditional Operator](./branching_logic/conditional_operator.md)
105106
- [Boolean Expressions](./branching_logic/boolean_expressions.md)
106107
- [Challenges](./branching_logic/challenges.md)
108+
107109
- [Loops](./loops.md)
108110
- [While](./loops/while.md)
109111
- [Endless Loops](./loops/endless_loops.md)
@@ -165,11 +167,10 @@
165167
- [Declaration](./methods/declaration.md)
166168
- [Invocation](./methods/invocation.md)
167169
- [Scope](./methods/scope.md)
168-
- [Return](./methods/return.md)
169-
- [Unreachable Statements](./methods/unreachable_statements.md)
170170
- [main](./methods/main.md)
171171
- [Challenges](./methods/challenges.md)
172172
- [Arguments](./arguments.md)
173+
173174
- [Declaration](./arguments/declaration.md)
174175
- [Invocation with Arguments](./arguments/invocation_with_arguments.md)
175176
- [Reassignment](./arguments/reassignment.md)
@@ -179,19 +180,16 @@
179180
- [Inferred Types](./arguments/inferred_types.md)
180181
- [Challenges](./arguments/challenges.md)
181182

182-
- [Return Values](./return_values.md)
183-
- [void](./return_values/void.md)
183+
- [Return](./return_values.md)
184+
- [Return Values](./return_values/return_values.md)
184185
- [Conversion](./return_values/conversion.md)
186+
- [void](./return_values/void.md)
187+
- [Unreachable Statements](./return_values/unreachable_statements.md)
185188
- [Pure Functions](./return_values/pure_functions.md)
186189
- [Impure Functions](./return_values/impure_functions.md)
187190

188-
189-
190191
# Data Types III
191192

192-
- [Identity Types](./identity_types.md)
193-
- [Comparison with ==](./identity_types/comparison_with_equalsequals.md)
194-
- [Primitive Types](./primitive_types.md)
195193
- [null](./null.md)
196194
- [Checking for null](./null/checking_for_null.md)
197195
- [Field Access](./null/field_access.md)
@@ -205,7 +203,7 @@
205203
- [Unboxing Conversion](./boxed_primitives/unboxing_conversion.md)
206204
- [Boxing Conversion](./boxed_primitives/boxing_conversion.md)
207205
- [Arrays of Boxed Primitives](./boxed_primitives/arrays_of_boxed_primitives.md)
208-
- [Challenges](./arguments/challenges.md)
206+
- [Challenges](./boxed_primitives/challenges.md)
209207
- [Arrays II](./arrays_ii.md)
210208
- [Default Values](./arrays_ii/default_values.md)
211209
- [Populate Array]()

src/arguments/challenges.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ void main() {
5353
```
5454

5555
## Challenge 3.
56+

src/arguments/final_arguments.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,5 @@ This has the same use as regular final variables. If there are lots of lines
3232
of code where a variable might be reassigned, it can be useful to not have
3333
to read all that code to know that it does happen.[^opinion]
3434

35-
[^opinion]:
36-
Adding `final` to all arguments can make it harder to read the code, simply
35+
[^opinion]: Adding `final` to all arguments can make it harder to read the code, simply
3736
because of visual noise.

src/boxed_primitives/challenges.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Challenges

src/first_steps.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,4 @@ public class Main {
109109
You should get in the habit of, whenever you see some bit of code, trying to physically type it out, run it,
110110
tweak it, and play with it.
111111
112-
So try playing around with this program. If you are not actively engaging then the whole thing is a bit of a wash.
112+
So try playing around with this program. If you actively engage then you will retain information better.

src/methods/challenges.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ Remember the rules for this are
99

1010
Declare a method named `printSquare`. When invoked it should print a square.
1111

12+
```
13+
*****
14+
*****
15+
*****
16+
*****
17+
```
18+
1219
```java
1320
// CODE HERE
1421

src/methods/return_values.md

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/null.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,40 @@
11
# null
22

3-
There is a special value called `null` which is assignable to
4-
any `String`
3+
There is a special value called `null` which is assignable to most types.
4+
5+
```java
6+
void main() {
7+
String name = null;
8+
int[] numbers = null;
9+
10+
System.out.println(name);
11+
System.out.println(numbers);
12+
}
13+
```
14+
15+
The only types which `null` cannot be assigned to are `int`, `double`, `char`, and `boolean`.[^aswellas]
16+
17+
```java
18+
void main() {
19+
// Will not work
20+
int x = null;
21+
}
22+
```
23+
24+
When something has the value of `null` it represents the absence of a "legitimate" value.
25+
26+
A good example is when a puppy is born. It starts without a name and it is later given a name.
27+
`null` is a way to represent the state of the world in the time before it is named.
28+
29+
```java
30+
void main() {
31+
// Just born, it has no name
32+
String puppyName = null;
33+
System.out.println("At the start, the name is " + puppyName);
34+
35+
puppyName = "Sally";
36+
System.out.println("Later it was given the name " + puppyName);
37+
}
38+
```
39+
40+
[^aswellas]: As well as `long`, `short`, `byte`, and `float` but I haven't shown you those yet.

src/return_values.md

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Return Values
1+
# Return
22

33
In addition to running some code, a method can return a value to the code that is calling it.
44

@@ -10,28 +10,3 @@ int returnsEight() {
1010
return 8;
1111
}
1212
```
13-
14-
When the method is called, that expression can be used on the right hand side of an `=` to get the value returned by the method.
15-
16-
```java
17-
int returnsEight() {
18-
return 8;
19-
}
20-
21-
void main() {
22-
int value = returnsEight();
23-
System.out.println(value);
24-
}
25-
```
26-
27-
The method call can also be used directly in expressions without assigning its value to a variable first.
28-
29-
```java
30-
String returnsName() {
31-
return "Mariah";
32-
}
33-
34-
void main() {
35-
System.out.println(returnsName() + " is my name");
36-
}
37-
```

0 commit comments

Comments
 (0)