Skip to content

Commit

Permalink
Linting issues and prerequisites updated in config.json
Browse files Browse the repository at this point in the history
  • Loading branch information
smcg468 committed Nov 25, 2023
1 parent d06acd0 commit eb987b4
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions concepts/nullability/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ In Java, the [`null` literal][null-keyword] is used to denote the absence of a v

[Primitive variables][primitive-data-types] in java all have a default value and therefore can never be `null`. By convention they start with a lowercase letter e.g `int`

[Reference variables][reference-data-types] contain the memory address of an object and can
[Reference variables][reference-data-types] contain the memory address of an object and can
have a value of null. These variables usually start with an uppercase e.g `String`

Attempting to assign a primitive variable a value of `null` will result in a compile time error as the variable always holds
Expand All @@ -30,6 +30,7 @@ int[] arr = null;
// Throws NullPointerException at runtime
arr.Length;
```

A [`NullPointerException` is thrown][null-pointer-exception] when trying to access a reference variable which is null but requires an object.

To safely work with nullable values, one should check if they are `null` before working with them which can be done using [equality operators][equality-operators] such as `==` or `!=`:
Expand All @@ -49,4 +50,3 @@ if(arr != null) {
[reference-data-types]: https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.3
[null-pointer-exception]: https://docs.oracle.com/javase/8/docs/api/java/lang/NullPointerException.html
[equality-operators]: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/op2.html

2 changes: 1 addition & 1 deletion concepts/nullability/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ Assigning a reference variable a `null` value will not result in a compile time
```java
//No error will occur as the String variable str is nullable
String str = null;
```
```
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@
"nullability"
],
"prerequisites": [
"if-statements",
"if-else-statements",
"strings"
]
}
Expand Down
6 changes: 4 additions & 2 deletions exercises/concept/tim-from-marketing/.docs/hints.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# Hints

## 1. Print a badge for an employee

- [String interpolation][string-interpolation] can be used to create description strings.
- There is a [built-in method to convert a string to uppercase][to-upper-case].

## 2. Print a badge for a new employee

- You should check if the ID is `null` before using it.
- You can use the [equality operators][equality-operators] to compare the value to `null`

## 3. Print a badge for the owner

- You should check if the department is `null` before using it.
- You can use the [equality operators][equality-operators] to compare the value to `null`


[string-interpolation]: https://www.baeldung.com/java-string-interpolation
[to-upper-case]:https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#toUpperCase--
[equality-operators]: https://docs.oracle.com/cd/E21764_01/apirefs.1111/e17787/com/sigmadynamics/util/Null.html#isNull_java_lang_String_
[equality-operators]: https://docs.oracle.com/cd/E21764_01/apirefs.1111/e17787/com/sigmadynamics/util/Null.html#isNull_java_lang_String_
2 changes: 1 addition & 1 deletion exercises/concept/tim-from-marketing/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ Note that it is possible for the owner to also be a new employee:
Badge badge = new Badge();
badge.print(id: null, "Charlotte Hale", department: null);
// => "Charlotte Hale - OWNER"
```
```
2 changes: 1 addition & 1 deletion exercises/concept/tim-from-marketing/.docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ Assigning a reference variable a `null` value will not result in a compile time
```java
//No error will occur as the String variable str is nullable
String str = null;
```
```

0 comments on commit eb987b4

Please sign in to comment.