Skip to content

Update main #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 76 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
2393236
more sections
bowbahdoe May 8, 2023
25924c1
First feedback round
bowbahdoe May 8, 2023
8503233
Update prelude.md
bowbahdoe May 8, 2023
914cd82
...
bowbahdoe May 13, 2023
ff8df0d
Spelling fix
bowbahdoe Jun 9, 2023
9c2678a
Arguments chapter
bowbahdoe Jun 17, 2023
f08cd22
More Challenges
bowbahdoe Jun 25, 2023
f751c08
Run prettier
bowbahdoe Aug 28, 2023
43ea470
user input
bowbahdoe Aug 28, 2023
794c9a0
October 14th, #1
bowbahdoe Oct 14, 2023
2642397
Array challenges
bowbahdoe Oct 14, 2023
94d3205
Delete challenges
bowbahdoe Oct 14, 2023
d7941e7
Null
bowbahdoe Oct 15, 2023
beafad8
...
bowbahdoe Oct 15, 2023
72693cc
Update null_as_absence.md
bowbahdoe Oct 15, 2023
33d0edc
Merge remote-tracking branch 'upstream/develop' into develop
bowbahdoe Nov 19, 2023
9a4b031
Delete out.json
bowbahdoe Nov 19, 2023
d2d6930
Fix quotes
bowbahdoe Nov 19, 2023
adc4811
Add first no_runs
bowbahdoe Nov 19, 2023
91ba156
Fix number example
bowbahdoe Nov 19, 2023
a07e987
...
bowbahdoe Feb 5, 2024
c90c905
Write more of the classes section
bowbahdoe Feb 6, 2024
1fd9a4d
Constructors
bowbahdoe Feb 7, 2024
d4a9dda
Clean up getting started a little
bowbahdoe Feb 7, 2024
62e73ad
Use a duke
bowbahdoe Feb 7, 2024
53cb45b
Don't link anywhere yet
bowbahdoe Feb 7, 2024
cc6cb4f
Increase lines needed to show a duke
bowbahdoe Feb 7, 2024
47627e5
Fix field access section
bowbahdoe Feb 7, 2024
161f934
...
bowbahdoe Feb 7, 2024
fcf44de
...
bowbahdoe Feb 7, 2024
b50a63f
...
bowbahdoe Feb 7, 2024
5067aec
...
bowbahdoe Feb 7, 2024
b455ef1
...
bowbahdoe Feb 7, 2024
e808fdf
switch and enums
bowbahdoe Feb 12, 2024
517973d
Merge remote-tracking branch 'upstream/develop' into develop
bowbahdoe Feb 13, 2024
344512f
Merge remote-tracking branch 'upstream/develop' into develop
bowbahdoe Feb 14, 2024
ed4ee40
Merge remote-tracking branch 'upstream/develop' into develop
bowbahdoe Feb 14, 2024
c0aaf10
Update book.toml
bowbahdoe Feb 14, 2024
cb7b4eb
Density
bowbahdoe Feb 14, 2024
7fd3e45
Update audience.md
bowbahdoe Feb 14, 2024
fdfb5bc
..
bowbahdoe Feb 14, 2024
c8bcf9d
Strings 2
bowbahdoe Feb 14, 2024
eeb4080
Update length.md
bowbahdoe Feb 14, 2024
72ba7e8
Global Fields
bowbahdoe Feb 15, 2024
b4f83e4
Merge remote-tracking branch 'upstream/develop' into develop
bowbahdoe Feb 17, 2024
9899b02
Merge remote-tracking branch 'upstream/develop' into develop
bowbahdoe Feb 17, 2024
e92020a
Input
bowbahdoe Feb 20, 2024
6376800
Update delayed_assignment.md
bowbahdoe Feb 20, 2024
f2d3d2e
...
bowbahdoe Feb 20, 2024
63a2973
...
bowbahdoe Feb 20, 2024
a27e061
Update book.js
bowbahdoe Apr 10, 2024
dc30eb5
Update challenges.md
bowbahdoe Apr 27, 2024
3b857c0
Remove blank Challenge
bowbahdoe Apr 28, 2024
521828f
Fix some issues, push some incomplete sections
bowbahdoe Apr 28, 2024
4457dee
Update challenges.md
bowbahdoe May 7, 2024
be25314
terminal
bowbahdoe May 7, 2024
5a02f25
Update challenges.md
bowbahdoe May 15, 2024
02fa7d6
Switches and visibility
bowbahdoe Jun 18, 2024
2d9ef2c
Growable array
bowbahdoe Jun 18, 2024
62f5d6b
Cli Args
bowbahdoe Jun 18, 2024
620427e
Delete unused
bowbahdoe Jun 18, 2024
7cd05e2
Change url
bowbahdoe Jun 19, 2024
cba4baa
inner classes
bowbahdoe Jun 19, 2024
898c891
Update unchecked_exceptions.md
bowbahdoe Jun 19, 2024
da1ec01
Update checked_exceptions.md
bowbahdoe Jun 19, 2024
d5e9fc1
Update invariants.md
bowbahdoe Jun 19, 2024
04bec4e
Packages
bowbahdoe Jun 20, 2024
02de34b
Records
bowbahdoe Jun 20, 2024
84b78fd
Update the_default_package.md
bowbahdoe Jun 20, 2024
e028ff7
Syntax highlighting wierdness
bowbahdoe Jun 20, 2024
b13d2dc
More records
bowbahdoe Jun 21, 2024
90beb94
Integers, Files, etc.
bowbahdoe Jun 25, 2024
c80e1f4
Move IOException around
bowbahdoe Jun 25, 2024
5a8d5fb
...
bowbahdoe Jun 25, 2024
4452c6a
Merge branch 'Together-Java:develop' into develop
bowbahdoe Jun 26, 2024
cb6e65b
...
bowbahdoe Jun 26, 2024
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
Prev Previous commit
Next Next commit
Packages
  • Loading branch information
bowbahdoe committed Jun 20, 2024
commit 04bec4ed160983a0506ede0febdb2ec4b1c6478e
22 changes: 17 additions & 5 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,24 @@
- [Disambiguation](./inner_classes/disambiguation.md)
- [The anonymous main class](./inner_classes/the_anonymous_main_class.md)
- [Static Inner Classes](./inner_classes/static_inner_classes.md)
- [Private Inner Classes](./inner_classes/private_inner_classes.md)
- [Packages](./packages.md)
- [The Default Package]()
- [Import]()
- [Import Static Methods]()
- [Import Inner Classes]()
- [Declaration](./packages/declaration.md)
- [Visibility](./packages/visibility.md)
- [Public Classes](./packages/public_classes.md)
- [Fully Qualified Class Name](./packages/fully_qualified_class_name.md)
- [Import](./packages/import.md)
- [The Default Package](./packages/the_default_package.md)
- [The anonymous main class](./packages/the_anonymous_main_class.md)
- [Public Methods](./packages/public_methods.md)
- [Package-Private Methods](./packages/package_private_methods.md)
- [Public Fields](./packages/public_fields.md)
- [Package-Private Fields](./packages/package_private_fields.md)
- [The Default Constructor](./packages/the_default_constructor.md)
- [Public Constructors](./packages/public_constructors.md)
- [Package-Private Constructors](./packages/package_private_constructors.md)
- [Subpackages](./packages/subpackages.md)
- [Reverse Domain Name Notation](./packages/reverse_domain_name_notation.md)

- [Visibility II](./visibility_ii.md)
- [Public Classes]()
Expand All @@ -422,7 +435,6 @@
- [Package-Private Methods]()
- [Public Fields]()
- [Package-Private Fields]()
- [Private Inner Classes]()

# Interactive Programs III

Expand Down
20 changes: 20 additions & 0 deletions src/inner_classes/private_inner_classes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Private Inner Classes

Both `static` and regular inner classes can be marked as `private`.

```java
class Human {
// No other class can see this human's thoughts
private class Thoughts {

}

// Nor can they see their feelings
private static class Feelings {

}
}
```

Within the class they are defined, a private inner class works as normal. The
difference is that code outside the class cannot make instances of them.
21 changes: 20 additions & 1 deletion src/inner_classes/scope.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,23 @@ class Main {
}
}
```
One mental model for this is that
One mental model for this is that its as if the inner class
holds a reference to the one it was created in.

```java,no_run
class Car {
int speed = 0;
}

class CarSpeedometer {
private final Car madeBy;

CarSpeedometer(Car madeBy) {
this.madeBy = madeBy;
}

int getSpeed() {
return madeBy.speed;
}
}
```
6 changes: 5 additions & 1 deletion src/inner_classes/static_inner_classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ class Car {
```

I would wager that this is the most common kind of inner class to see
in real code.
in real code, despite requiring more words to define[^theme].

[^theme]: A theme that will start to emerge is that the "best" code sometimes has
a few extra modifiers on it and the "default" behavior isn't what you want. Static
inner classes are way less magic.
11 changes: 10 additions & 1 deletion src/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@

Every class in Java "lives" in a package.

A package is a way to group individual classes.
A package is a way to group individual classes.

```java,no_run
package dungeon;

class BugBear {

}
```

31 changes: 31 additions & 0 deletions src/packages/declaration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Declaration

To put a class into a package you need to do two things.

First, put a "package declaration" at the top of the file. This looks like the word `package` followed by the name of the package and a `;`

```java,no_run
package dungeon;

class BugBear {

}
```

Then you need to make sure that the `.java` file is in a folder matching the name of
that package.

So, for the example above, if your code was previously laid out like this

```
src/
BugBear.java
```

It needs to be changed to this.

```
src/
dungeon/
BugBear.java
```
29 changes: 29 additions & 0 deletions src/packages/fully_qualified_class_name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Fully Qualified Class Name

In order to use a public class from a different package you can
write out the "fully qualified class name."[^fqcn]

This is the name of the class prefixed with the package it is in.

```java,no_run
package village;

public class Villager {}
```

```java,no_run
package dungeon;

class Dwarf {
// Works because we write out the full name
// and because Villager is public.
village.Villager meet() {
return new village.Villager();
}
}
```

This hints that the "real name" of a class isn't what you write after `class`, but instead both that and the package name glued together.

[^fqcn]: People also often call this the "FQCN". Its a fun acronym to write, but I
have no clue how to say it out loud. "Faquacün?"
28 changes: 28 additions & 0 deletions src/packages/import.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Import

If you don't want to write out the fully qualified class name everywhere, and few do,
then you can use an `import`.

To import a class you write `import` followed by the fully qualified class name.
This makes it so that the "simple" class name will be usable.

```java,no_run
package village;

public class Villager {}
```

```java,no_run
package dungeon;

// For the rest of the file, you can
// just write "Villager" and Java will know
// what you mean.
import village.Villager;

class Dwarf {
Villager meet() {
return new Villager();
}
}
```
28 changes: 28 additions & 0 deletions src/packages/package_private_constructors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Package-Private Constructors

A constructor without any other modifier is "package-private" in the
same way as methods and fields.[^private]

```java
package dungeon;

public class Slime {
final int size;

// This constructor is public,
// code in other packages can use it.
public Slime() {
this.size = 5;
}

// This constructor is package-private,
// code in other packages cannot use it.
Slime(int size) {
this.size = size;
}
}
```

[^private]: Your spider-sense might be tingling wondering if `private` constructors
are a thing. They are! I'll talk about them more in-depth later, but they can be
surprisingly useful.
13 changes: 13 additions & 0 deletions src/packages/package_private_fields.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Package-Private Fields

Fields that are marked neither `public` nor `private` are "package-private."

```java
package village;

public class Well {
// Neither of these can be used outside of the "village" package
static final int NUMBER_OF_DEMONS = 4;
boolean exorcismPerformed;
}
```
22 changes: 22 additions & 0 deletions src/packages/package_private_methods.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Package-Private Methods

If a method is neither `public` or `private` then it can
be used only by code in the same package.

We call these methods "package-private" because they are
"private" to code outside the package.

```java
package village;

public class Villager {
void isNotVisible() {
System.out.println("""
This method can be called from code in the "village"
package, but not from other packages.
""");
}
}
```

Which again applies to static methods as well.
11 changes: 11 additions & 0 deletions src/packages/public_classes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Public Classes

To be able to use a class in one package from a different package,
you must first mark that class as `public`.

```java,no_run
package village;

// Now other packages will be able to see it
public class Villager {}
```
35 changes: 35 additions & 0 deletions src/packages/public_constructors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Public Constructors

For a constructor you write to be usable across packages[^youguessed] it needs
to be marked `public`.

```java,no_run
package dungeon;

public class Skeleton {
public final int bones;

public Skeleton() {
this.bones = 206;
}
}
```

```java,no_run
package village;

import dungeon.Skeleton;

class Main {
void main() {
// Now this works
var skeleton = new Skeleton();

// And we get the right number of bones!
System.out.println(skeleton.bones);
}
}
```


[^youguessed]: You guessed it!
14 changes: 14 additions & 0 deletions src/packages/public_fields.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Public Fields

Similarly to methods, for a field to be used from a different package
it must be marked `public`.

```java
package village;

public class Well {
// Both of these you can use from a different package
public static final int DEPTH = 10;
public int remainingWater;
}
```
34 changes: 34 additions & 0 deletions src/packages/public_methods.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Public Methods

Even though a class might itself be marked `public`, the methods
within it will not be unless they are also `public`.

```java,no_run
package village;

// Now other packages will be able to see it
public class Villager {
public void isVisible() {
System.out.println("This method is callable from another package.");
}

void isNotVisible() {
System.out.println("This method is not.")
}
}
```

This applies also to static methods.

```java,no_run
package village;

public class Well {
public static int drawWater() {
System.out.println("""
You need this to be both public and static to
be able to write "Well.drawWater()"
""");
}
}
```
Loading