Skip to content

Commit 4449c90

Browse files
authored
Initial content, ported from previous repo (#8)
From: https://github.com/bowbahdoe/javabook
1 parent df0c20b commit 4449c90

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1812
-5
lines changed

src/SUMMARY.md

Lines changed: 163 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,164 @@
1-
# Summary
1+
<!-- # For Contributors
2+
- [For Contributors](./paths.md)
3+
- [baeldung's getting started course](./examples/baeldung.md)
4+
- [Core Java Volume II](./examples/core_java_vol2.md)
5+
- [dev.java](./examples/dev_java.md)
6+
- [geeksforgeeks](./examples/geeksforgeeks.md)
7+
- [javatpoint](./examples/javatpoint.md)
8+
- [Scala Book](./examples/scala_book.md)
9+
- ["The Java Programming Language" (1st or 2nd ed)](./examples/the_java_programming_language_og.md)
10+
- ["The Java Tutorial" (3rd ed)](./examples/the_java_tutorial_3rd_edition.md)
11+
- [The Java Tutorials, online](./examples/the_java_tutorials.md)
12+
- [Tour of Scala](./examples/tour_of_scala.md)
13+
- [tutorialspoint](./examples/tutorialspoint.md)
14+
- [tutorialspoint paid course](./examples/tutorialspoint_paid.md)
15+
- [w3schools](./examples/w3schools.md) -->
16+
# Getting Started
17+
- [Hello, World](./getting_started/hello_world.md)
18+
# Modern Java
19+
- [Prelude](./prelude.md)
20+
- [First Steps](./first_steps.md)
21+
- [Comments](./first_steps/comments.md)
22+
- [Semicolons](./first_steps/semicolon.md)
23+
- [Formatting](./first_steps/formatting.md)
24+
- [Challenges](./first_steps/challenges.md)
25+
- [Local Variables](./variables.md)
26+
- [Naming](./variables/naming.md)
27+
- [Reassignment](./variables/reassignment.md)
28+
- [Delayed Assignment](./variables/delayed_assignment.md)
29+
- [Types](./variables/types.md)
30+
- [Final Variables](./variables/final_variables.md)
31+
- [Inferred Types](./variables/inferred_types.md)
32+
- [Challenges](./variables/challenges.md)
33+
- [Booleans](./boolean.md)
34+
- [And](./boolean/and.md)
35+
- [Or](./boolean/or.md)
36+
- [Not](./boolean/not.md)
37+
- [Operator Precedance](./boolean/operator_precedance.md)
38+
- [Challenges](./modern/bchallenges.md)
39+
- [Integers](./integers.md)
40+
- [Addition](./integers/addition.md)
41+
- [Subtraction](./integers/subtraction.md)
42+
- [Multiplication](./integers/multiplication.md)
43+
- [Division](./integers/division.md)
44+
- [Remainder](./integers/remainder.md)
45+
- [Equality](./integers/equality.md)
46+
- [Comparison](./integers/comparison.md)
47+
- [Chained Comparisons](./integers/chained_comparisons.md)
48+
- [Operator Precedance](./integers/operator_precedance.md)
49+
- [Reassignment](./integers/reassignment.md)
50+
- [Shorthands for Reassignment](./integers/shorthands_for_reassignment.md)
51+
- [Limits](./integers/limits.md)
52+
- [Challenges](./integers/challenges.md)
53+
- [Floating Point Numbers](./floating_point_numbers.md)
54+
- [Limits](./floating_point_numbers/limits.md)
55+
- [float and double](./numbers/float_and_double.md)
56+
- [Precision]()
57+
- [The "epsilon" Pattern]()
258

3-
- [Chapter 1](./chapter_1.md)
59+
60+
- [Strings](./strings.md)
61+
- [String Theory](./strings/string_theory.md)
62+
- [Escaped Characters](./strings/escaped_characters.md)
63+
- [Multiline Strings](./strings/multiline.md)
64+
65+
- [If and Else]()
66+
- [If Statement]()
67+
- [Relation to Delayed Assignment]()
68+
- [Integer Comparisons]()
69+
- [Floating Point Number Comparisons]()
70+
- [String Comparisons]()
71+
- [Ternary Expression]()
72+
73+
- [While Loop]()
74+
- [Arrays]()
75+
- ["String\[\] args"]()
76+
- [For Each Loop]()
77+
- [Counted For Loop]()
78+
- [Methods]()
79+
- [Arguments]()
80+
- [Return Value]()
81+
- [void]()
82+
- [String Methods]()
83+
- [length]()
84+
- [User Defined Classes]()
85+
- [Fields]()
86+
- [Constructors]()
87+
- [Methods]()
88+
89+
90+
- [Control Flow]()
91+
92+
<!--
93+
byte, short, long
94+
Multiversal Equality
95+
-->
96+
97+
98+
<!--
99+
# Legacy Java
100+
- [Legacy Java]()
101+
- [Prelude]()
102+
- [Subpar]()
103+
- [Short]()
104+
- [Scanner]()
105+
- [File]()
106+
- [Swing]()
107+
- [Date]()
108+
- [Crusty]()
109+
- [Vector]()
110+
- [Hashtable]()
111+
- [Already Removed]()
112+
- [Applets]()
113+
- [Finalization]()
114+
-->
115+
116+
<!--
117+
# Tour of Java
118+
- [Tour of Java](./tour_of_java.md)
119+
- [Introduction]()
120+
- [Basics]()
121+
- [Classes]()
122+
- [Methods]()
123+
- [Interfaces]()
124+
- [Exceptions]()
125+
- [Collections]()
126+
- [Enums]()
127+
- [Records]()
128+
- [Generic Classes]()
129+
- [Inner Classes]()
130+
- [Annotations]()
131+
- [Reflection]()
132+
-->
133+
134+
<!--
135+
- Introduction
136+
- Basics
137+
- Unified Types
138+
- Classes
139+
- Default Parameter Values
140+
- Named Arguments
141+
- Traits
142+
- Tuples
143+
- Class Composition with Mixins
144+
- Higher-order Functions
145+
- Multiple Parameter Lists
146+
- Case Classes
147+
- Pattern Matching
148+
- Singleton Objects
149+
- Regular Expression Patterns
150+
- Extractor Objects
151+
- For Comprehensions
152+
- Generic Classes
153+
- Variances
154+
- Upper Type Bounds
155+
- Lower Type Bounds
156+
- Abstract Type Members
157+
- Implicit Conversions
158+
- Polymorphic Methods
159+
- Type Inference
160+
- Operators
161+
162+
- Packages and Imports
163+
- Top Level Definitions in Packages
164+
-->

src/boolean.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Booleans
2+
3+
4+
A `boolean` is either `true` or `false`.
5+
6+
7+
```java
8+
boolean onFleek = true;
9+
boolean badVibes = false;
10+
```
11+
12+
This is used to represent situations where there are exactly two possible states.
13+

src/boolean/and.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# And
2+
3+
One way multiple booleans can be combined is by using the "and" operator - `&&`.
4+
5+
```java
6+
boolean funToBeAround = true;
7+
boolean believesInFundamentalHumanRights = true;
8+
boolean willAskOnDate = funToBeAround && believesInFundamentalHumanRights;
9+
```
10+
11+
So in this case, I will ask someone on a date if they are fun to be around _and_
12+
they wholeheartedly believe in the assertions made in the [Universal Declaration of Human Rights](https://www.un.org/en/about-us/universal-declaration-of-human-rights).
13+
14+
| funToBeAround | believesInFundamentalHumanRights | willAskOnDate |
15+
|---------------|----------------------------------|---------------|
16+
| true | true | true |
17+
| true | false | false |
18+
| false | true | false |
19+
| false | false | false |

src/boolean/challenges.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Challenges
2+
3+
Remember the rules for this are
4+
* Try to use only the information given up to this point in this book.
5+
* Try not to give up until you've given it a solid attempt
6+
7+
## Challenge 1.
8+
9+
What will this program output when run? Write down your guess and then try running it.
10+
11+
```java
12+
public class Main {
13+
public static void main(String[] args) {
14+
boolean a = true;
15+
boolean b = false;
16+
boolean c = true;
17+
boolean d = false;
18+
19+
boolean result = a || b && c || !d;
20+
21+
System.out.println(result);
22+
}
23+
}
24+
```
25+
26+
## Challenge 2.
27+
28+
What will this program output when run? Write down your guess and then try running it.
29+
30+
```java
31+
public class Main {
32+
public static void main(String[] args) {
33+
boolean a = true;
34+
boolean b = false;
35+
boolean c = true;
36+
boolean d = false;
37+
38+
boolean result = !(a || b && c || !d) || (a && b || c);
39+
40+
System.out.println(result);
41+
}
42+
}
43+
```
44+
45+
## Challenge 3.
46+
47+
Say you have two boolean variables, how could you use the operators we've covered to get the "exclusive or" of the two.
48+
49+
```java
50+
public class Main {
51+
public static void main(String[] args) {
52+
// Change these two variables to test your solution
53+
boolean hasIceCream = true;
54+
boolean hasCookie = false;
55+
56+
boolean validChoice = < YOUR CODE HERE >;
57+
58+
System.out.println(validChoice);
59+
}
60+
}
61+
```
62+
63+
Make sure to test all the possibilities.
64+
65+
| hasIceCream | hasCookie | validChoice |
66+
|-------------|-----------|-------------|
67+
| true | true | false |
68+
| true | false | true |
69+
| false | true | true |
70+
| false | false | false |

src/boolean/not.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Not
2+
3+
Booleans can alsobe "negated" using the "not" operator - `!`.
4+
5+
```java
6+
boolean haveOreosInHouse = true;
7+
boolean stuckToCalorieLimit = !haveOreos;
8+
```
9+
10+
So in this case, I have stuck to my calorie limit if there are _not_ Oreos in the house.
11+
12+
| haveOreosInHouse | stuckToCalorieLimit |
13+
|------------------|---------------------|
14+
| false | true |
15+
| true | false |

src/boolean/operator_precedance.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Operator Precedance
2+
3+
The operators that work on booleans have a "precedance order."
4+
5+
This is defines an order of operations similar to mathematics, where multiplication and division happen before
6+
addition and subtraction.
7+
8+
For booleans `!` always happens first. This is followed by `&&` and then by `||`.
9+
10+
```java
11+
boolean a = true;
12+
boolean b = false
13+
boolean c = false;
14+
15+
// just as 2 + 5 * 3 "evaluates" 5 * 3 before adding 2
16+
// first, !b is true
17+
// second, a && true is true
18+
// third true || c is true.
19+
boolean result = a && !b || c;
20+
```
21+
22+
Also like mathematics, parentheses can be used to control this order.
23+
24+
```java
25+
// Even though || has a lower precedance than &&, we evaluate
26+
// !b || c first because of the parentheses.
27+
boolean result = a && (!b || c);
28+
```

src/boolean/or.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Or
2+
3+
Another way booleans can be combined is by using the "or" operator - `||`.
4+
5+
```java
6+
boolean dogLooksNice = true;
7+
boolean personLooksNice = false;
8+
boolean willAskToPetDog = dogLooksNice || personLooksNice;
9+
```
10+
11+
So in this case, I will ask to pet someone's dog if either the the dog looks nice _or_ the person
12+
walking the dog looks nice.
13+
14+
| dogLooksNice | personLooksNice | willAskToPetDog |
15+
|--------------|-----------------|-----------------|
16+
| true | true | true |
17+
| true | false | true |
18+
| false | true | true |
19+
| false | false | false |
20+
21+
## Exclusive vs. Inclusive
22+
23+
It is important too note that this is not an "exclusive" OR.
24+
25+
An exclusive OR would be something like
26+
a child being allowed to have ice cream _or_ a cookie, but not both.
27+
28+
The `||` operator is an "inclusive" OR, meaning the child is allowed ice cream, a cookie, or both ice cream and the cookie.
29+

src/chapter_1.md

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

0 commit comments

Comments
 (0)