Skip to content
Merged

V2 #3

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
Binary file modified .DS_Store
Binary file not shown.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ pdf/*
epub/*
ZCW-JS-Prep.epub
ZCW-JS-Prep.pdf
.DS_Store
reader/ReadingJava/.DS_Store
reader/ReadingJava/Programs/.DS_Store
reader/ReadingJava/.DS_Store
reader/ReadingJava/Programs/.DS_Store
IntroAndWorkBook/.DS_Store
Binary file modified IntroAndWorkBook/.DS_Store
Binary file not shown.
Binary file added IntroAndWorkBook/JavaIntroCover.pdf
Binary file not shown.
Binary file added IntroAndWorkBook/JavaIntroCover.png.pdf
Binary file not shown.
55 changes: 30 additions & 25 deletions IntroAndWorkBook/aastartwithjshell.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,24 @@ Java changed all of that in 2017 with the introduction of **jshell** - an intera
programming environment that lets you write and test Java code instantly.
Think of it as having a conversation with the Java language itself.

Now, this section is going to mention some things you have not been introduced to yet.
Don't let that bother you.
`jshell` is a powerful thing, and we have to start somewhere, so just kind of move through these ideas as smoothly as you can.

=== Why jshell is Revolutionary for Learning

==== Immediate Feedback

Traditional Java programming requires this cycle:

```
Write code Save to file Compile Run See results
Write code > Save to file > Compile > Run > See results
```

With jshell, it's simply:

```
Type code See results immediately
Type code > See results immediately
```

This instant feedback loop is **crucial** for learning because:
Expand All @@ -37,7 +41,7 @@ This instant feedback loop is **crucial** for learning because:

==== No Ceremony, Just Code

In traditional Java, even the simplest program requires a lot of "ceremony":
In traditional Java, even the simplest program requires a lot of "ceremony". In many languages, you can just write a line of code and see what happens. But Java requires you to wrap everything in a class and a main method:

[source]
----
Expand All @@ -48,7 +52,9 @@ public class HelloWorld {
}
----

In jshell, you just type:
This can be intimidating for beginners who just want to see how a simple line of code works.

With jshell, you can skip all that boilerplate:

[source]
----
Expand All @@ -59,6 +65,8 @@ Hello, World!
All that extra code (the class definition, main method, etc.) is handled automatically by jshell.
You can focus on learning Java concepts without getting bogged down in syntax you don't understand yet.

And that is going make the following chapters much easier to understand, letting you learn the concepts without the extra noise.

=== Getting Started with jshell

==== Starting jshell
Expand Down Expand Up @@ -184,7 +192,7 @@ jshell> numbers
numbers ==> int[5] { 1, 2, 10, 4, 5 }
----

==== Prototyping Methods
==== Defining Methods

You can even define and test methods instantly:

Expand Down Expand Up @@ -219,7 +227,10 @@ $17 ==> 9

==== Exploring Object Methods

jshell makes it easy to explore what you can do with Java objects.
jshell makes it easy to explore what you can do with Java objects. Each object has methods you can call to perform actions or retrieve information.
The fact is that you can discover these methods interactively is a huge advantage.
The methods are in fact part of the object's *class*, but we will get to that much later.
For now, just know that you can explore what methods are available on an object.
Use tab completion to discover methods:

[source]
Expand Down Expand Up @@ -259,9 +270,9 @@ jshell> String name =
...>
...> System.out.println(name.length())
| Error:
| variable name might not have been initialized
| System.out.println(name.length())
| ^--^
| incompatible types: void cannot be converted to java.lang.String
| System.out.println(name.length());
| ^-------------------------------^
----

These immediate error messages help you understand Java's type system and requirements.
Expand Down Expand Up @@ -306,27 +317,18 @@ jshell> /help
jshell> /exit
----

=== Why This Matters for Learning
(Your help output may vary based on your jshell version.)

==== Builds Confidence
=== Why This Matters for Learning

When you can immediately test ideas and see them work, you build confidence in your programming abilities.
- **Builds Confidence** When you can immediately test ideas and see them work, you build confidence in your programming abilities.
There's no long, intimidating compilation process - just immediate results.

==== Encourages Experimentation

jshell makes it safe to try things.
- **Encourages Experimentation** jshell makes it safe to try things.
If something doesn't work, you haven't "broken" anything.
You just try again with a different approach.

==== Reinforces Learning

The immediate feedback loop means concepts stick better.
- **Reinforces Learning** The immediate feedback loop means concepts stick better.
When you see cause and effect immediately, you understand the relationship between code and results.

==== Reduces Friction

By eliminating the ceremony of full programs, jshell lets you focus on learning Java concepts rather than fighting with tools and syntax.
- **Reduces Friction** By eliminating the complexity of full java programs, jshell lets you focus on learning Java concepts rather than fighting with tools and syntax.

=== Practical Learning Strategy

Expand All @@ -351,12 +353,15 @@ jshell prepares you for this transition because:

=== The Bottom Line

jshell isn't just a tool - it's a philosophy of learning.
jshell isn't just a toy or simple tool - it's a philosophy of learning.
It embodies the idea that programming should be interactive, experimental, and immediately rewarding.

When you use jshell, you're not just learning Java syntax.
You're developing a programmer's mindset: curious, experimental, and comfortable with iteration.

Many Java programmers have learned Java without `jshell` and have struggled with the initial complexity of the language.
But with `jshell`, you have a powerful ally that makes learning Java more accessible and enjoyable.

So as you work through this book, remember: jshell is your coding playground.
Use it freely, experiment boldly, and enjoy the immediate satisfaction of seeing your code come to life.

Expand Down
11 changes: 10 additions & 1 deletion IntroAndWorkBook/access-modifiers.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
=== Access Modifiers

This is an advanced topic, and you can skip it for now if you want.

Access modifiers in Java control who can see and use your classes, methods, and variables.
Think of them as different levels of privacy - like having a public park, a private home, a family room, or a room shared with neighbors.

Expand Down Expand Up @@ -178,7 +180,14 @@ public class MathUtils {

==== Real-World Example: Bank Account Class

Here's a complete example showing proper use of access modifiers:
Here's a complete example showing proper use of access modifiers.

Notice how the methods are `public` but the instance variables that hold the
key information about the account are marked `private`.
This ensures that anyone using this class in their code can only adjust
the _private_ variables using the _public_ methods.

That is a **very** common pattern used in Java programs.

[source]
----
Expand Down
Loading