Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 163 additions & 2 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,164 @@
# Summary
<!-- # For Contributors
- [For Contributors](./paths.md)
- [baeldung's getting started course](./examples/baeldung.md)
- [Core Java Volume II](./examples/core_java_vol2.md)
- [dev.java](./examples/dev_java.md)
- [geeksforgeeks](./examples/geeksforgeeks.md)
- [javatpoint](./examples/javatpoint.md)
- [Scala Book](./examples/scala_book.md)
- ["The Java Programming Language" (1st or 2nd ed)](./examples/the_java_programming_language_og.md)
- ["The Java Tutorial" (3rd ed)](./examples/the_java_tutorial_3rd_edition.md)
- [The Java Tutorials, online](./examples/the_java_tutorials.md)
- [Tour of Scala](./examples/tour_of_scala.md)
- [tutorialspoint](./examples/tutorialspoint.md)
- [tutorialspoint paid course](./examples/tutorialspoint_paid.md)
- [w3schools](./examples/w3schools.md) -->
# Getting Started
- [Hello, World](./getting_started/hello_world.md)
# Modern Java
- [Prelude](./prelude.md)
- [First Steps](./first_steps.md)
- [Comments](./first_steps/comments.md)
- [Semicolons](./first_steps/semicolon.md)
- [Formatting](./first_steps/formatting.md)
- [Challenges](./first_steps/challenges.md)
- [Local Variables](./variables.md)
- [Naming](./variables/naming.md)
- [Reassignment](./variables/reassignment.md)
- [Delayed Assignment](./variables/delayed_assignment.md)
- [Types](./variables/types.md)
- [Final Variables](./variables/final_variables.md)
- [Inferred Types](./variables/inferred_types.md)
- [Challenges](./variables/challenges.md)
- [Booleans](./boolean.md)
- [And](./boolean/and.md)
- [Or](./boolean/or.md)
- [Not](./boolean/not.md)
- [Operator Precedance](./boolean/operator_precedance.md)
- [Challenges](./modern/bchallenges.md)
- [Integers](./integers.md)
- [Addition](./integers/addition.md)
- [Subtraction](./integers/subtraction.md)
- [Multiplication](./integers/multiplication.md)
- [Division](./integers/division.md)
- [Remainder](./integers/remainder.md)
- [Equality](./integers/equality.md)
- [Comparison](./integers/comparison.md)
- [Chained Comparisons](./integers/chained_comparisons.md)
- [Operator Precedance](./integers/operator_precedance.md)
- [Reassignment](./integers/reassignment.md)
- [Shorthands for Reassignment](./integers/shorthands_for_reassignment.md)
- [Limits](./integers/limits.md)
- [Challenges](./integers/challenges.md)
- [Floating Point Numbers](./floating_point_numbers.md)
- [Limits](./floating_point_numbers/limits.md)
- [float and double](./numbers/float_and_double.md)
- [Precision]()
- [The "epsilon" Pattern]()

- [Chapter 1](./chapter_1.md)

- [Strings](./strings.md)
- [String Theory](./strings/string_theory.md)
- [Escaped Characters](./strings/escaped_characters.md)
- [Multiline Strings](./strings/multiline.md)

- [If and Else]()
- [If Statement]()
- [Relation to Delayed Assignment]()
- [Integer Comparisons]()
- [Floating Point Number Comparisons]()
- [String Comparisons]()
- [Ternary Expression]()

- [While Loop]()
- [Arrays]()
- ["String\[\] args"]()
- [For Each Loop]()
- [Counted For Loop]()
- [Methods]()
- [Arguments]()
- [Return Value]()
- [void]()
- [String Methods]()
- [length]()
- [User Defined Classes]()
- [Fields]()
- [Constructors]()
- [Methods]()


- [Control Flow]()

<!--
byte, short, long
Multiversal Equality
-->


<!--
# Legacy Java
- [Legacy Java]()
- [Prelude]()
- [Subpar]()
- [Short]()
- [Scanner]()
- [File]()
- [Swing]()
- [Date]()
- [Crusty]()
- [Vector]()
- [Hashtable]()
- [Already Removed]()
- [Applets]()
- [Finalization]()
-->

<!--
# Tour of Java
- [Tour of Java](./tour_of_java.md)
- [Introduction]()
- [Basics]()
- [Classes]()
- [Methods]()
- [Interfaces]()
- [Exceptions]()
- [Collections]()
- [Enums]()
- [Records]()
- [Generic Classes]()
- [Inner Classes]()
- [Annotations]()
- [Reflection]()
-->

<!--
- Introduction
- Basics
- Unified Types
- Classes
- Default Parameter Values
- Named Arguments
- Traits
- Tuples
- Class Composition with Mixins
- Higher-order Functions
- Multiple Parameter Lists
- Case Classes
- Pattern Matching
- Singleton Objects
- Regular Expression Patterns
- Extractor Objects
- For Comprehensions
- Generic Classes
- Variances
- Upper Type Bounds
- Lower Type Bounds
- Abstract Type Members
- Implicit Conversions
- Polymorphic Methods
- Type Inference
- Operators

- Packages and Imports
- Top Level Definitions in Packages
-->
13 changes: 13 additions & 0 deletions src/boolean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Booleans


A `boolean` is either `true` or `false`.


```java
boolean onFleek = true;
boolean badVibes = false;
```

This is used to represent situations where there are exactly two possible states.

19 changes: 19 additions & 0 deletions src/boolean/and.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# And

One way multiple booleans can be combined is by using the "and" operator - `&&`.

```java
boolean funToBeAround = true;
boolean believesInFundamentalHumanRights = true;
boolean willAskOnDate = funToBeAround && believesInFundamentalHumanRights;
```

So in this case, I will ask someone on a date if they are fun to be around _and_
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).

| funToBeAround | believesInFundamentalHumanRights | willAskOnDate |
|---------------|----------------------------------|---------------|
| true | true | true |
| true | false | false |
| false | true | false |
| false | false | false |
70 changes: 70 additions & 0 deletions src/boolean/challenges.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Challenges

Remember the rules for this are
* Try to use only the information given up to this point in this book.
* Try not to give up until you've given it a solid attempt

## Challenge 1.

What will this program output when run? Write down your guess and then try running it.

```java
public class Main {
public static void main(String[] args) {
boolean a = true;
boolean b = false;
boolean c = true;
boolean d = false;

boolean result = a || b && c || !d;

System.out.println(result);
}
}
```

## Challenge 2.

What will this program output when run? Write down your guess and then try running it.

```java
public class Main {
public static void main(String[] args) {
boolean a = true;
boolean b = false;
boolean c = true;
boolean d = false;

boolean result = !(a || b && c || !d) || (a && b || c);

System.out.println(result);
}
}
```

## Challenge 3.

Say you have two boolean variables, how could you use the operators we've covered to get the "exclusive or" of the two.

```java
public class Main {
public static void main(String[] args) {
// Change these two variables to test your solution
boolean hasIceCream = true;
boolean hasCookie = false;

boolean validChoice = < YOUR CODE HERE >;

System.out.println(validChoice);
}
}
```

Make sure to test all the possibilities.

| hasIceCream | hasCookie | validChoice |
|-------------|-----------|-------------|
| true | true | false |
| true | false | true |
| false | true | true |
| false | false | false |
15 changes: 15 additions & 0 deletions src/boolean/not.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Not

Booleans can alsobe "negated" using the "not" operator - `!`.

```java
boolean haveOreosInHouse = true;
boolean stuckToCalorieLimit = !haveOreos;
```

So in this case, I have stuck to my calorie limit if there are _not_ Oreos in the house.

| haveOreosInHouse | stuckToCalorieLimit |
|------------------|---------------------|
| false | true |
| true | false |
28 changes: 28 additions & 0 deletions src/boolean/operator_precedance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Operator Precedance

The operators that work on booleans have a "precedance order."

This is defines an order of operations similar to mathematics, where multiplication and division happen before
addition and subtraction.

For booleans `!` always happens first. This is followed by `&&` and then by `||`.

```java
boolean a = true;
boolean b = false
boolean c = false;

// just as 2 + 5 * 3 "evaluates" 5 * 3 before adding 2
// first, !b is true
// second, a && true is true
// third true || c is true.
boolean result = a && !b || c;
```

Also like mathematics, parentheses can be used to control this order.

```java
// Even though || has a lower precedance than &&, we evaluate
// !b || c first because of the parentheses.
boolean result = a && (!b || c);
```
29 changes: 29 additions & 0 deletions src/boolean/or.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Or

Another way booleans can be combined is by using the "or" operator - `||`.

```java
boolean dogLooksNice = true;
boolean personLooksNice = false;
boolean willAskToPetDog = dogLooksNice || personLooksNice;
```

So in this case, I will ask to pet someone's dog if either the the dog looks nice _or_ the person
walking the dog looks nice.

| dogLooksNice | personLooksNice | willAskToPetDog |
|--------------|-----------------|-----------------|
| true | true | true |
| true | false | true |
| false | true | true |
| false | false | false |

## Exclusive vs. Inclusive

It is important too note that this is not an "exclusive" OR.

An exclusive OR would be something like
a child being allowed to have ice cream _or_ a cookie, but not both.

The `||` operator is an "inclusive" OR, meaning the child is allowed ice cream, a cookie, or both ice cream and the cookie.

3 changes: 0 additions & 3 deletions src/chapter_1.md

This file was deleted.

Loading