Skip to content

Commit 23cb244

Browse files
committed
shifting to intepretation
1 parent 1adb4ca commit 23cb244

File tree

9 files changed

+997
-19
lines changed

9 files changed

+997
-19
lines changed

README.md

Lines changed: 88 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,99 @@
1-
# Java Small
1+
# Code Interpreters: Understanding How Programming Languages Run
22

3-
`fork` this repository and `clone` it to your local machine.
3+
Welcome to your introduction to programming with Java and Python! This repository contains beginner-friendly tutorials for both languages, focusing on how code gets executed on your computer.
44

5-
This repository contains small Java projects and guides for beginners.
5+
## What is Code Interpretation vs Compilation?
66

7-
There are three markdown files that will lead you thru a series of
8-
steps to learn some beginner Java programming.
7+
When you write code, your computer doesn't understand it directly. Programming languages need to be translated into machine language (1s and 0s) that your computer can execute. There are two main ways this happens:
98

10-
You will use `jshell` to learn about variables, methods, and classes.
11-
**Make sure you TYPE the snippets from the markdown files into `jshell`**.
12-
Not typing, doing copy/paste, will not help you learn (and is cheating at this point of the course)
9+
### Compiled Languages (Traditional Java)
10+
**Compilation** is like translating an entire book before anyone can read it:
11+
- You write your Java code in a `.java` file
12+
- A **compiler** (like `javac`) translates your entire program into bytecode
13+
- The Java Virtual Machine (JVM) then runs this compiled bytecode
14+
- If there are errors anywhere in your code, the compiler catches them before anything runs
15+
- You must fix all errors before your program can run
1316

14-
## Getting Started
17+
**Example workflow:**
18+
```
19+
Write code → Compile (javac) → Run (java) → See results
20+
↓ ↓ ↓
21+
hello.java → hello.class → Output
22+
```
1523

16-
To get started, clone this repository to your local machine:
24+
### Interpreted Languages (Python)
25+
**Interpretation** is like having a live translator who translates as you speak:
26+
- You write Python code and run it immediately
27+
- The **interpreter** reads your code line by line and executes it instantly
28+
- Errors are found and reported as the program runs, not before
29+
- You can test small pieces of code quickly without compiling
1730

18-
```bash
19-
cd ~/Projects
20-
git clone https://github.com/ZipCodeCore/JavaSmall
31+
**Example workflow:**
32+
```
33+
Write code → Run directly → See results immediately
34+
↓ ↓
35+
hello.py → Output (no compilation step)
2136
```
2237

23-
Then, navigate to the repository:
38+
## The Best of Both Worlds: JShell
2439

25-
```bash
26-
cd JavaSmall
27-
```
40+
Traditionally, Java required you to write a complete program, compile it, and then run it. This made experimenting with small code snippets difficult for beginners.
41+
42+
**JShell** (introduced in Java 9) changed this by adding an **interpreter** to Java:
43+
- Type Java code and see results immediately
44+
- Test methods, variables, and expressions interactively
45+
- No need to write a complete class structure for simple experiments
46+
- Perfect for learning and prototyping
47+
48+
Think of jshell as giving Java programmers the same "try it now" experience that Python programmers have always had.
49+
50+
## Why This Matters for Beginners
51+
52+
### Learning with Interpreters (Python & JShell)
53+
- **Immediate feedback**: See results instantly
54+
- **Experiment freely**: Try code snippets without writing full programs
55+
- **Learn incrementally**: Build understanding one concept at a time
56+
- **Quick debugging**: Test small pieces to understand what went wrong
57+
58+
### Learning with Compilers (Traditional Java)
59+
- **Catch errors early**: The compiler finds many mistakes before running
60+
- **Understand program structure**: Learn how complete programs are organized
61+
- **Build discipline**: Write more complete, thoughtful code
62+
- **Performance benefits**: Compiled code typically runs faster
63+
64+
## What's in This Repository
65+
66+
This repository contains parallel tutorials for both languages:
67+
68+
### Java Directory (`/java/`)
69+
- **README.md**: Getting started with Java and jshell
70+
- **JavaSmall.md**: Interactive Java programming with jshell
71+
- **VARS.md**: Understanding Java variables using jshell
72+
- **ClassPerson.md**: Creating Java classes interactively
73+
74+
### Python Directory (`/python/`)
75+
- **README.md**: Getting started with Python interpreter
76+
- **PythonSmall.md**: Interactive Python programming
77+
- **VARS.md**: Understanding Python variables
78+
- **ClassPerson.md**: Creating Python classes
79+
80+
## Learning Path
81+
82+
1. **Start with either language** - both directories teach the same concepts
83+
2. **Use the interpreters** - jshell for Java, python3 for Python
84+
3. **Type, don't copy-paste** - build muscle memory and understanding
85+
4. **Experiment beyond the examples** - interpreters make this safe and fun
86+
87+
## Key Takeaways
88+
89+
- **Interpreters** let you run code immediately, line by line
90+
- **Compilers** translate entire programs before running
91+
- **JShell** brings interpreter-style learning to Java
92+
- **Python** has always been interpreted, making it beginner-friendly
93+
- Both approaches have their place in programming
94+
95+
## The Big Picture
96+
97+
Understanding how your code runs helps you become a better programmer. Interpreters are great for learning and quick experiments. Compilers help you build robust, efficient programs. Modern development often uses both approaches - interpreters for testing ideas, compilers for building final applications.
2898

29-
Use a browser to be able to see the markdown files.
30-
Start with `JavaSmall.md` and follow the links to the other guides.
99+
Ready to start? Pick either `/java/` or `/python/` and begin your programming journey!
File renamed without changes.
File renamed without changes.

java/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Java Small
2+
3+
`fork` this repository and `clone` it to your local machine.
4+
5+
This repository contains small Java projects and guides for beginners.
6+
7+
There are three markdown files that will lead you thru a series of
8+
steps to learn some beginner Java programming.
9+
10+
You will use `jshell` to learn about variables, methods, and classes.
11+
**Make sure you TYPE the snippets from the markdown files into `jshell`**.
12+
Not typing, doing copy/paste, will not help you learn (and is cheating at this point of the course)
13+
14+
## Getting Started
15+
16+
To get started, clone this repository to your local machine:
17+
18+
```bash
19+
cd ~/Projects
20+
git clone https://github.com/ZipCodeCore/JavaSmall
21+
```
22+
23+
Then, navigate to the repository:
24+
25+
```bash
26+
cd JavaSmall
27+
```
28+
29+
Use a browser to be able to see the markdown files.
30+
Start with `JavaSmall.md` and follow the links to the other guides.
File renamed without changes.

python/ClassPerson.md

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
# Understanding Python Classes: A Guide to Creating a Person Class
2+
3+
## What is a Class?
4+
A class is a blueprint or template that defines the properties (attributes) and behaviors (methods) that all objects of that type can have.
5+
6+
## The Person Class Step by Step Guide
7+
8+
### Step 1: Basic Class Structure
9+
Here's how to create a simple Person class in the Python interpreter:
10+
11+
```python
12+
class Person:
13+
def __init__(self, name, age):
14+
self.name = name
15+
self.age = age
16+
```
17+
18+
### Step 2: Understanding the Constructor
19+
The `__init__` method is Python's constructor. It helps initialize a new Person object with specific values:
20+
21+
```python
22+
class Person:
23+
def __init__(self, name, age):
24+
self.name = name
25+
self.age = age
26+
```
27+
28+
### Step 3: Creating Person Objects
29+
Let's create some Person objects using our class:
30+
31+
```python
32+
>>> person1 = Person("Alice", 25)
33+
>>> person1
34+
<__main__.Person object at 0x7f8b8c0b7040>
35+
36+
>>> person2 = Person("Bob", 30)
37+
>>> person2
38+
<__main__.Person object at 0x7f8b8c0b7070>
39+
```
40+
41+
### Step 4: Accessing Object Properties
42+
You can access the properties of a Person object using dot notation:
43+
44+
```python
45+
>>> person1.name
46+
'Alice'
47+
48+
>>> person1.age
49+
25
50+
```
51+
52+
### Step 5: Adding Methods
53+
Let's add some methods to our Person class:
54+
55+
```python
56+
class Person:
57+
def __init__(self, name, age):
58+
self.name = name
59+
self.age = age
60+
61+
def say_hello(self):
62+
print(f"Hello, my name is {self.name}")
63+
64+
def have_birthday(self):
65+
self.age = self.age + 1
66+
print(f"Happy Birthday! {self.name} is now {self.age}")
67+
```
68+
69+
### Step 6: Using Methods
70+
Now we can use these methods with our Person objects:
71+
72+
```python
73+
>>> person1.say_hello()
74+
Hello, my name is Alice
75+
76+
>>> person1.have_birthday()
77+
Happy Birthday! Alice is now 26
78+
```
79+
80+
## Practice Exercise
81+
Try creating your own Person class with:
82+
1. Create the basic class structure
83+
2. Add properties (name and age)
84+
3. Create a constructor (`__init__` method)
85+
4. Create two Person objects
86+
5. Access their properties
87+
6. Add and use methods
88+
89+
## Common Mistakes to Avoid
90+
1. Forgetting `self` as the first parameter in methods
91+
2. Not using proper indentation (Python uses indentation instead of braces)
92+
3. Forgetting to use `self.` when accessing instance variables
93+
4. Not initializing variables in the `__init__` method
94+
95+
## Tips for Success
96+
1. Always test your class by creating objects and using their methods
97+
2. Use meaningful names for variables and methods
98+
3. Keep your code organized and properly indented
99+
4. Remember that each object is independent and has its own set of values
100+
5. Use `self` to refer to the current instance
101+
102+
## Checking Your Work
103+
You can use these Python interpreter commands to verify your work:
104+
- `dir(person1)` - shows all attributes and methods of the person1 object
105+
- `vars(person1)` - shows all instance variables
106+
- `help(Person)` - shows documentation for the Person class
107+
108+
## Extended Example
109+
Here's a more complete Person class:
110+
111+
```python
112+
class Person:
113+
def __init__(self, name, age):
114+
self.name = name
115+
self.age = age
116+
117+
def print_details(self):
118+
print(f"Name: {self.name}")
119+
print(f"Age: {self.age}")
120+
121+
def is_adult(self):
122+
return self.age >= 18
123+
124+
def have_birthday(self):
125+
self.age = self.age + 1
126+
print(f"Happy Birthday! {self.name} is now {self.age}")
127+
```
128+
129+
Try using this extended example:
130+
```python
131+
>>> person = Person("John", 17)
132+
>>> person.print_details()
133+
Name: John
134+
Age: 17
135+
>>> print(person.is_adult())
136+
False
137+
>>> person.have_birthday()
138+
Happy Birthday! John is now 18
139+
>>> print(person.is_adult())
140+
True
141+
```
142+
143+
This guide should give you a solid foundation for understanding
144+
how to create and use classes in Python.
145+
Remember to practice by creating your own variations of the Person
146+
class and experimenting with different properties and methods.
147+
148+
Maybe add a method that sets and gets a person's "chirality" (left-handed or right-handed) or "handedness" (ambidextrous, left-handed, right-handed).
149+
What type of variable would be best for this?
150+
What would be the default value?
151+
152+
You have to add a variable declaration for the handedness in the `__init__` method.
153+
And add a getter and setter for the handedness.
154+
Be sure to add a method to print out the handedness.
155+
156+
```python
157+
class Person:
158+
def __init__(self, name, age, handedness="right-handed"):
159+
self.name = name
160+
self.age = age
161+
self.handedness = handedness
162+
163+
def get_handedness(self):
164+
return self.handedness
165+
166+
def set_handedness(self, handedness):
167+
valid_options = ["left-handed", "right-handed", "ambidextrous"]
168+
if handedness in valid_options:
169+
self.handedness = handedness
170+
else:
171+
print(f"Invalid handedness. Choose from: {valid_options}")
172+
173+
def print_handedness(self):
174+
print(f"{self.name} is {self.handedness}")
175+
176+
def print_details(self):
177+
print(f"Name: {self.name}")
178+
print(f"Age: {self.age}")
179+
print(f"Handedness: {self.handedness}")
180+
```
181+
182+
Save it in a file called `person.py` and also do the trinity of github commands:
183+
184+
```bash
185+
git add .
186+
git commit -m "Add Person class work"
187+
git push
188+
```
189+
190+
## Python vs Java Differences
191+
1. **No explicit type declarations**: Python figures out types automatically
192+
2. **`self` instead of implicit `this`**: Always use `self` as first parameter
193+
3. **Indentation matters**: Python uses indentation instead of braces
194+
4. **`__init__` instead of constructor**: Python's special method for initialization
195+
5. **Snake_case naming**: Python uses snake_case for method names
196+
197+
## Conclusion
198+
199+
Classes and Objects are an essential part of object-oriented programming in Python.
200+
201+
Be sure to do commit of all this work to your GitHub repository.
202+
203+
```bash
204+
touch finished.txt
205+
git add .
206+
git commit -m "Finished"
207+
git push
208+
```

0 commit comments

Comments
 (0)