Skip to content

Commit 5eb16eb

Browse files
committed
feat: Introduce 'Static vs Instance' module, overhaul project README, and configure Vite for GitHub Pages deployment.
1 parent 025fd20 commit 5eb16eb

File tree

6 files changed

+162
-83
lines changed

6 files changed

+162
-83
lines changed

README.md

Lines changed: 154 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,167 @@
1-
# React + TypeScript + Vite
1+
# Java Engineering Masterclass 🚀
22

3-
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
3+
An interactive, production-grade React application for mastering advanced Java/JVM concepts through visual simulations and deep-dive theory.
44

5-
Currently, two official plugins are available:
5+
![React](https://img.shields.io/badge/React-19-blue?logo=react)
6+
![TypeScript](https://img.shields.io/badge/TypeScript-5.9-blue?logo=typescript)
7+
![Vite](https://img.shields.io/badge/Vite-7-purple?logo=vite)
8+
![License](https://img.shields.io/badge/License-MIT-green)
69

7-
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
8-
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
10+
## 🎯 Features
911

10-
## React Compiler
12+
### Interactive Simulators
1113

12-
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
14+
| Module | Description | Visualization |
15+
|--------|-------------|---------------|
16+
| **Garbage Collection** | Eden, Survivor, Old Gen memory pools | Object allocation & GC cycles |
17+
| **Concurrency** | Monitor locks, Entry/Wait sets | Thread state transitions |
18+
| **JIT Compilation** | Tiered compilation (Interpreted → C1 → C2) | Profiling & optimization |
19+
| **Java Memory Model** | CPU caches, Main Memory, Volatile | Cache coherence & visibility |
20+
| **Static vs Instance** | Metaspace vs Heap memory layout | Static field sharing |
1321

14-
## Expanding the ESLint configuration
22+
### Educational Theory
1523

16-
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
24+
Each module includes comprehensive "Engineer's Guide" content covering:
25+
- Under-the-hood JVM internals
26+
- Best practices and anti-patterns
27+
- Thread safety considerations
28+
- Performance implications
1729

18-
```js
19-
export default defineConfig([
20-
globalIgnores(['dist']),
21-
{
22-
files: ['**/*.{ts,tsx}'],
23-
extends: [
24-
// Other configs...
30+
## 🏗️ Architecture
2531

26-
// Remove tseslint.configs.recommended and replace with this
27-
tseslint.configs.recommendedTypeChecked,
28-
// Alternatively, use this for stricter rules
29-
tseslint.configs.strictTypeChecked,
30-
// Optionally, add this for stylistic rules
31-
tseslint.configs.stylisticTypeChecked,
32+
Built following **SOLID principles** with a modular, scalable architecture:
3233

33-
// Other configs...
34-
],
35-
languageOptions: {
36-
parserOptions: {
37-
project: ['./tsconfig.node.json', './tsconfig.app.json'],
38-
tsconfigRootDir: import.meta.dirname,
39-
},
40-
// other options...
41-
},
42-
},
43-
])
4434
```
35+
src/
36+
├── components/ # Reusable UI components
37+
│ ├── Layout/ # Header, Layout wrapper
38+
│ ├── UI/ # Button, Console, MemoryBlock
39+
│ └── Hub/ # Module selection grid
40+
├── features/ # Feature modules (one per topic)
41+
│ ├── gc/ # Garbage Collection
42+
│ ├── threads/ # Concurrency
43+
│ ├── jit/ # JIT Compilation
44+
│ ├── jmm/ # Java Memory Model
45+
│ └── static/ # Static vs Instance
46+
├── hooks/ # Custom React hooks (simulation logic)
47+
├── contexts/ # React Context providers
48+
├── types/ # TypeScript type definitions
49+
└── App.tsx # Root application component
50+
```
51+
52+
## 🚀 Getting Started
53+
54+
### Prerequisites
55+
56+
- Node.js 18+
57+
- npm or yarn
58+
59+
### Installation
60+
61+
```bash
62+
# Clone the repository
63+
git clone https://github.com/pramithamj/java-masterclass.git
64+
cd java-masterclass
65+
66+
# Install dependencies
67+
npm install
68+
69+
# Start development server
70+
npm run dev
71+
```
72+
73+
Open [http://localhost:5173](http://localhost:5173) in your browser.
4574

46-
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
47-
48-
```js
49-
// eslint.config.js
50-
import reactX from 'eslint-plugin-react-x'
51-
import reactDom from 'eslint-plugin-react-dom'
52-
53-
export default defineConfig([
54-
globalIgnores(['dist']),
55-
{
56-
files: ['**/*.{ts,tsx}'],
57-
extends: [
58-
// Other configs...
59-
// Enable lint rules for React
60-
reactX.configs['recommended-typescript'],
61-
// Enable lint rules for React DOM
62-
reactDom.configs.recommended,
63-
],
64-
languageOptions: {
65-
parserOptions: {
66-
project: ['./tsconfig.node.json', './tsconfig.app.json'],
67-
tsconfigRootDir: import.meta.dirname,
68-
},
69-
// other options...
70-
},
71-
},
72-
])
75+
### Build for Production
76+
77+
```bash
78+
npm run build
79+
npm run preview # Preview production build locally
7380
```
81+
82+
## 🌐 Deployment
83+
84+
### GitHub Pages
85+
86+
The app is configured for GitHub Pages deployment:
87+
88+
1. Build the project: `npm run build`
89+
2. Push to your repository
90+
3. Enable GitHub Pages in repository settings (deploy from `gh-pages` branch or `/docs` folder)
91+
92+
> **Note**: The `base` path in `vite.config.ts` must match your repository name.
93+
94+
## 📚 Module Details
95+
96+
### Garbage Collection Simulator
97+
98+
Visualize the **Generational Hypothesis** in action:
99+
- **Eden Space**: Where new objects are allocated
100+
- **Survivor Space**: Objects that survive Minor GC
101+
- **Old Generation**: Long-lived objects (tenured)
102+
- Trigger Minor GC and Full GC to see object lifecycle
103+
104+
### Concurrency Simulator
105+
106+
Understand Java's **Monitor Lock** mechanism:
107+
- See threads competing for synchronized blocks
108+
- Watch Entry Set (blocked) and Running states
109+
- Visualize lock acquisition and release
110+
111+
### JIT Compilation Simulator
112+
113+
Watch code get "hot" and tiered compilation kick in:
114+
- **Interpreted**: Initial slow execution
115+
- **C1 Compiler**: Quick compilation, basic optimizations
116+
- **C2 Compiler**: Aggressive optimization (inlining, escape analysis)
117+
118+
### Java Memory Model Lab
119+
120+
Understand **visibility** and **happens-before**:
121+
- CPU L1 caches vs Main Memory
122+
- Volatile writes flush to memory
123+
- Non-volatile reads may see stale data
124+
125+
### Static vs Instance Lab
126+
127+
Visualize where static and instance members live:
128+
- **Metaspace**: Class-level static fields (shared)
129+
- **Heap**: Per-instance fields (unique per object)
130+
- See how static changes affect ALL instances
131+
132+
## 🛠️ Technology Stack
133+
134+
- **React 19** - UI framework with hooks
135+
- **TypeScript 5.9** - Type safety
136+
- **Vite 7** - Fast build tool with HMR
137+
- **CSS Modules** - Scoped styling
138+
- **ESLint** - Code quality
139+
140+
## 📝 Design Principles
141+
142+
1. **Single Responsibility (SRP)**: Each component/hook has one clear purpose
143+
2. **Open/Closed (OCP)**: Easy to add new modules without modifying core
144+
3. **Dependency Inversion (DIP)**: Contexts provide injectable dependencies
145+
4. **Interface Segregation (ISP)**: Small, focused type interfaces
146+
147+
## 🤝 Contributing
148+
149+
Contributions are welcome! Please feel free to submit a Pull Request.
150+
151+
1. Fork the repository
152+
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
153+
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
154+
4. Push to the branch (`git push origin feature/AmazingFeature`)
155+
5. Open a Pull Request
156+
157+
## 📄 License
158+
159+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
160+
161+
## 🙏 Acknowledgments
162+
163+
- Inspired by the need for better JVM education tools
164+
- Built with modern React best practices
165+
- Designed for developers learning advanced Java concepts
166+
167+
---

src/App.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { NavigationProvider, ConsoleProvider, useNavigation, isModuleView } from './contexts';
77
import { Layout, ModuleHub, ModuleTabs } from './components';
8-
import { GCModule, ThreadsModule, JITModule, JMMModule } from './features';
8+
import { GCModule, ThreadsModule, JITModule, JMMModule, StaticModule } from './features';
99
import type { ModuleId } from './types';
1010

1111
/**
@@ -25,6 +25,7 @@ function ModuleRenderer() {
2525
threads: ThreadsModule,
2626
jit: JITModule,
2727
jmm: JMMModule,
28+
static: StaticModule,
2829
};
2930

3031
const ModuleComponent = moduleComponents[currentView];

src/components/Hub/ModuleHub.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { useNavigation } from '../../contexts';
7-
import { MODULE_REGISTRY, type ModuleId } from '../../types';
7+
import { MODULE_REGISTRY } from '../../types';
88
import styles from './ModuleHub.module.css';
99

1010
export function ModuleHub() {

src/features/threads/ThreadsSimulator.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Button, Console } from '../../components';
99
import styles from './ThreadsSimulator.module.css';
1010

1111
export function ThreadsSimulator() {
12-
const { threads, lock, blockedQueue, runningQueue, spawnThread } = useThreadSimulator();
12+
const { threads, lock, spawnThread } = useThreadSimulator();
1313
const { logs } = useModuleConsole('threads');
1414

1515
// Filter active (non-terminated) threads for display

src/hooks/useThreadSimulator.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,26 +72,6 @@ export function useThreadSimulator(): IUseThreadSimulator {
7272
});
7373
}, [log]);
7474

75-
const acquireLock = useCallback((thread: IThread) => {
76-
const updatedThread = { ...thread, state: 'running' as const };
77-
78-
log(`Thread-${thread.id} acquired Lock. Executing...`, 'success');
79-
80-
// Schedule release
81-
lockTimeoutRef.current = setTimeout(() => {
82-
releaseLock(updatedThread);
83-
}, THREAD_CONSTANTS.LOCK_HOLD_DURATION_MS);
84-
85-
setState((prev) => ({
86-
...prev,
87-
threads: prev.threads.map((t) =>
88-
t.id === thread.id ? updatedThread : t
89-
),
90-
lock: { isLocked: true, owner: updatedThread },
91-
runningQueue: [updatedThread],
92-
}));
93-
}, [log, releaseLock]);
94-
9575
const spawnThread = useCallback(() => {
9676
const newThread: IThread = {
9777
id: nextThreadId.current++,

vite.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ import react from '@vitejs/plugin-react'
44
// https://vite.dev/config/
55
export default defineConfig({
66
plugins: [react()],
7+
// Base path for GitHub Pages deployment
8+
// Change this to match your repository name
9+
base: '/java-masterclass/',
710
})
11+

0 commit comments

Comments
 (0)