<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[Codies Coder Newsletter]]></title><description><![CDATA[Each month, we dive deep into a single topic in software engineering, breaking it down in a way that’s easy to grasp and fun to explore. Whether you're just starting out or already a pro, you'll always walk away with something new to think about.]]></description><link>https://codiescoder.substack.com</link><image><url>https://substackcdn.com/image/fetch/$s_!vCfG!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff574545e-ca46-4752-8376-f6508575c6ec_96x96.png</url><title>Codies Coder Newsletter</title><link>https://codiescoder.substack.com</link></image><generator>Substack</generator><lastBuildDate>Mon, 13 Apr 2026 02:55:53 GMT</lastBuildDate><atom:link href="https://codiescoder.substack.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Ajay Negi]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[codiescoder@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[codiescoder@substack.com]]></itunes:email><itunes:name><![CDATA[Ajay Negi]]></itunes:name></itunes:owner><itunes:author><![CDATA[Ajay Negi]]></itunes:author><googleplay:owner><![CDATA[codiescoder@substack.com]]></googleplay:owner><googleplay:email><![CDATA[codiescoder@substack.com]]></googleplay:email><googleplay:author><![CDATA[Ajay Negi]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[The Definitive Guide to Package Managers]]></title><description><![CDATA[A package manager is software that automates finding, installing, upgrading, configuring and removing software packages in a consistent manner. Packages are archives that combine program files plus metadata (name, version, dependencies, checksums, scripts). Package managers maintain a local package database and interact with remote repositories to satisfy user requests and resolve dependencies.What they are, how they work, when to pick which one and the tradeoffs you must manage]]></description><link>https://codiescoder.substack.com/p/the-definitive-guide-to-package-managers</link><guid isPermaLink="false">https://codiescoder.substack.com/p/the-definitive-guide-to-package-managers</guid><dc:creator><![CDATA[Ajay Negi]]></dc:creator><pubDate>Sun, 14 Dec 2025 19:41:14 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/022be396-af40-4d61-a9a7-2e07fec61a1b_1376x768.avif" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>A <strong>package manager</strong> is software that automates finding, installing, upgrading, configuring and removing software packages in a consistent manner. Packages are archives that combine program files plus metadata (name, version, dependencies, checksums, scripts). Package managers maintain a local package database and interact with remote repositories to satisfy user requests and resolve dependencies.</p><h3>Core concepts (building blocks)</h3><ol><li><p><strong>Package</strong> &#8212; an archive with program files and metadata (version, dependencies, install scripts).</p></li><li><p><strong>Repository (registry)</strong> &#8212; remote store of packages.</p></li><li><p><strong>Package database (local state)</strong> &#8212; tracks installed packages, versions, files, and metadata.</p></li><li><p><strong>Dependency metadata</strong> &#8212; declares what other packages (and versions) are required.</p></li><li><p><strong>Resolver</strong> &#8212; algorithm that finds a set of package versions that satisfy constraints.</p></li><li><p><strong>Installer/unpacker</strong> &#8212; extracts files, runs pre/post scripts, updates database.</p></li><li><p><strong>Signing &amp; checksums</strong> &#8212; integrity and authenticity mechanisms.</p></li></ol><h3>Architecture and flow (high level)</h3><ol><li><p>User requests install/update of package <code>A</code>.</p></li><li><p>Client queries configured repositories for available versions and metadata.</p></li><li><p>Resolver constructs dependency graph (transitive dependencies + version constraints).</p></li><li><p>Resolver computes an install plan (order, conflict resolution).</p></li><li><p>Client downloads package archives, verifies checksums and signatures.</p></li><li><p>Installer unpacks packages, runs lifecycle scripts, updates local database.</p></li><li><p>Post-install validation and cleanup.</p></li></ol><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Vxhe!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff70515ea-45a1-4985-ae6a-184a0ad2c6d7_1690x779.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Vxhe!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff70515ea-45a1-4985-ae6a-184a0ad2c6d7_1690x779.png 424w, https://substackcdn.com/image/fetch/$s_!Vxhe!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff70515ea-45a1-4985-ae6a-184a0ad2c6d7_1690x779.png 848w, https://substackcdn.com/image/fetch/$s_!Vxhe!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff70515ea-45a1-4985-ae6a-184a0ad2c6d7_1690x779.png 1272w, https://substackcdn.com/image/fetch/$s_!Vxhe!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff70515ea-45a1-4985-ae6a-184a0ad2c6d7_1690x779.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Vxhe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff70515ea-45a1-4985-ae6a-184a0ad2c6d7_1690x779.png" width="1456" height="671" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f70515ea-45a1-4985-ae6a-184a0ad2c6d7_1690x779.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:671,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:188758,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://codiescoder.substack.com/i/181595484?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff70515ea-45a1-4985-ae6a-184a0ad2c6d7_1690x779.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Vxhe!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff70515ea-45a1-4985-ae6a-184a0ad2c6d7_1690x779.png 424w, https://substackcdn.com/image/fetch/$s_!Vxhe!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff70515ea-45a1-4985-ae6a-184a0ad2c6d7_1690x779.png 848w, https://substackcdn.com/image/fetch/$s_!Vxhe!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff70515ea-45a1-4985-ae6a-184a0ad2c6d7_1690x779.png 1272w, https://substackcdn.com/image/fetch/$s_!Vxhe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff70515ea-45a1-4985-ae6a-184a0ad2c6d7_1690x779.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><h2>Language-level Package Managers</h2><p><strong>Language-level Package Managers</strong> are tools that manage libraries and dependencies for a specific programming language. They handle installing, updating, removing, and resolving versions of packages required by a project.</p><p>They operate within the ecosystem of one language, ensuring compatibility with that language&#8217;s runtime, syntax and conventions. These managers typically use a configuration file to declare dependencies and a registry or repository to fetch them.</p><h4>JavaScript / TypeScript</h4><p><strong>npm</strong></p><ul><li><p>What: Default package registry and CLI for Node and front-end packages.</p></li><li><p>When: Use for Node projects and most JS dependency management; default for publishing to the npm registry.</p></li><li><p>Advantages: Ubiquitous, integrated with Node, lockfile (<code>package-lock.json</code>), huge ecosystem.</p></li><li><p>Disadvantages: Historically large <code>node_modules</code>, occasional supply-chain risks, some legacy behavior surprising (flat vs nested deps historically).</p></li></ul><p><strong>yarn (classic / berry)</strong></p><ul><li><p>What: Alternative npm client with performance and UX improvements (Berry = modern Yarn).</p></li><li><p>When: Use for faster installs, workspace monorepos, or when you need deterministic installs.</p></li><li><p>Advantages: Workspaces, offline cache, deterministic installs, performance.</p></li><li><p>Disadvantages: Divergent configs across versions; switching costs; some plugins required for parity with npm.</p></li></ul><p><strong>pnpm</strong></p><ul><li><p>What: Disk-efficient package manager using a global content-addressable store and hard links.</p></li><li><p>When: Use for large mono-repos or when you want strict node_modules invariants and minimal disk usage.</p></li><li><p>Advantages: Extremely fast; saves significant disk space; strict dependency resolution prevents &#8220;phantom dependencies&#8221; (accessing unlisted packages).</p></li><li><p>Disadvantages: Symlink-based <code>node_modules</code> structure can break specific tools (some React Native, Electron, or serverless setups); requires strict declaration of all dependencies unlike flat-node_modules managers.</p></li></ul><p><strong>bun</strong></p><ul><li><p>What: JavaScript/TypeScript runtime with a built-in, high-performance package manager (<code>bun install</code>) compatible with <code>package.json</code> and npm packages.</p></li><li><p>When: Use when install speed and runtime performance matter, or for greenfield projects that benefit from an integrated toolchain (install, run, test, bundle).</p></li><li><p>Advantages: Very fast installs and startup, single binary toolchain, supports workspaces and standard npm dependency semantics.</p></li><li><p>Disadvantages: Younger ecosystem than npm/yarn/pnpm; some native modules and edge tooling may be incompatible; higher risk for large or legacy codebases.</p></li></ul><div><hr></div><h4>Python</h4><p><strong>pip</strong> (+ <code>wheel</code>)</p><ul><li><p>What: Python package installer; installs wheels/archives from PyPI.</p></li><li><p>When: Use for installing packages and simple apps; base tool in Python ecosystem.</p></li><li><p>Advantages: Standard, simple, broad PyPI coverage.</p></li><li><p>Disadvantages: Dependency resolution historically weaker (improved), no built-in env isolation.</p></li></ul><p><strong>venv / virtualenv</strong> (env managers)</p><ul><li><p>What: Create isolated Python environments.</p></li><li><p>When: Always use for per-project isolation.</p></li><li><p>Advantages: Simple, standard.</p></li><li><p>Disadvantages: Manual activate step; dependency and reproducibility needs lockfiles.</p></li></ul><p><strong>pipenv</strong></p><ul><li><p>What: Combines <code>pip</code> + virtualenv + lockfile.</p></li><li><p>When: Use when you want managed virtualenvs + automated lockfile workflow.</p></li><li><p>Advantages: <code>Pipfile</code> + <code>Pipfile.lock</code> for reproducible installs.</p></li><li><p>Disadvantages: Performance and reliability complaints historically.</p></li></ul><p><strong>poetry</strong></p><ul><li><p>What: Dependency management and packaging tool with built-in lockfile and publish flow.</p></li><li><p>When: Use for modern project management, building, and publishing Python packages/app.</p></li><li><p>Advantages: Good UX, deterministic builds, <code>pyproject.toml</code> support.</p></li><li><p>Disadvantages: Different command set; some ecosystem edge cases (C extensions) need care.</p></li></ul><p><strong>conda</strong></p><ul><li><p>What: Environment and package manager for Python (and binaries) focused on data science.</p></li><li><p>When: Use for data-science stacks, binary-heavy dependencies (numpy, MKL) and cross-language packages.</p></li><li><p>Advantages: Solves &#8220;binary compatibility&#8221; hell by managing non-Python libraries (libc, compilers) within the environment; truly isolated environments.</p></li><li><p>Disadvantages: Large installation footprint; slower dependency solver than pip/uv; separate channel ecosystem (conda-forge vs defaults) can cause conflicts.</p></li></ul><div><hr></div><h4>Java / JVM languages (Java, Kotlin, Scala)</h4><p><strong>Maven</strong></p><ul><li><p>What: Build and dependency management using POM XML and Maven Central.</p></li><li><p>When: Enterprise Java builds, artifact publishing, transitive dependency management.</p></li><li><p>Advantages: Mature, strong repository ecosystem, plugin-rich.</p></li><li><p>Disadvantages: Verbose XML config; slower builds historically.</p></li></ul><p><strong>Gradle</strong></p><ul><li><p>What: Modern build tool (Groovy/Kotlin DSL) that replaces Maven for many projects.</p></li><li><p>When: Use for faster, scriptable builds, Android, Kotlin/Java projects.</p></li><li><p>Advantages: Incremental builds, flexible DSL, performance.</p></li><li><p>Disadvantages: Learning curve; complex build scripts can become hard to maintain.</p></li></ul><p><strong>SBT (Scala)</strong></p><ul><li><p>What: Scala build tool with its own dependency model.</p></li><li><p>When: Scala projects.</p></li><li><p>Advantages: Scala-centric features, interactive shell.</p></li><li><p>Disadvantages: Slow startup historically, idiosyncratic config.</p></li></ul><div><hr></div><h4>Rust</h4><p><strong>cargo</strong></p><ul><li><p>What: Build system and package manager for Rust (crates.io).</p></li><li><p>When: Always use for Rust projects.</p></li><li><p>Advantages: Integrated build + test + publish; excellent dependency resolution; lockfile.</p></li><li><p>Disadvantages: Tied to Rust ecosystem only (not a drawback in practice).</p></li></ul><div><hr></div><h4>Go</h4><p><strong>Go modules (</strong><code>go mod</code><strong>)</strong></p><ul><li><p>What: Native dependency management tracking modules and versions.</p></li><li><p>When: Use for all modern Go projects.</p></li><li><p>Advantages: Simple, versioned modules, reproducible builds with <code>go.sum</code>.</p></li><li><p>Disadvantages: Module proxy complexity and historic GOPATH transition confusion (now stabilized).</p></li></ul><div><hr></div><h4>Ruby</h4><p><strong>RubyGems</strong></p><ul><li><p>What: Package format and installer for Ruby gems.</p></li><li><p>When: Use for installing libraries and CLI tools in Ruby.</p></li><li><p>Advantages: Standard, integrated with Ruby ecosystem.</p></li><li><p>Disadvantages: Gem native extension builds can be painful across platforms.</p></li></ul><p><strong>Bundler</strong></p><ul><li><p>What: Dependency manager that locks gem versions for apps.</p></li><li><p>When: Use for app dependency management and reproducible deployments.</p></li><li><p>Advantages: <code>Gemfile.lock</code> determinism; widely adopted.</p></li><li><p>Disadvantages: Management of native gems remains an operational concern.</p></li></ul><div><hr></div><h4>PHP</h4><p><strong>Composer</strong></p><ul><li><p>What: Dependency manager for PHP (Packagist registry).</p></li><li><p>When: Use for PHP projects and frameworks.</p></li><li><p>Advantages: Semantic versioning, autoloading support, lockfile.</p></li><li><p>Disadvantages: Dependency resolution can pull large graphs; autoload metadata overhead.</p></li></ul><div><hr></div><h4>.NET (C#, F#, VB)</h4><p><strong>NuGet</strong></p><ul><li><p>What: Package manager and registry for .NET assemblies.</p></li><li><p>When: Use for .NET library and app dependencies.</p></li><li><p>Advantages: Tight integration with MS build tooling and Visual Studio.</p></li><li><p>Disadvantages: Multi-targeting and runtime-compat issues require attention.</p></li></ul><div><hr></div><h4>C and C++</h4><p><strong>conan</strong></p><ul><li><p>What: C/C++ package manager for binaries and sources.</p></li><li><p>When: Use to manage C/C++ libraries across platforms and compilers.</p></li><li><p>Advantages: Binary recipe support, configurable build profiles.</p></li><li><p>Disadvantages: Extra learning; build matrix complexity.</p></li></ul><p><strong>vcpkg</strong></p><ul><li><p>What: Microsoft-backed C++ package manager focused on Windows and cross-platform.</p></li><li><p>When: Use for quick consumption of popular C++ libs in MS ecosystems.</p></li><li><p>Advantages: Good Windows integration, simple consumption.</p></li><li><p>Disadvantages: Less flexible for custom build pipelines.</p></li></ul><div><hr></div><h4>Swift / Objective-C (iOS/macOS)</h4><p><strong>Swift Package Manager (SPM)</strong></p><ul><li><p>What: Official package manager for Swift.</p></li><li><p>When: Use for Swift libraries and apps, server-side Swift.</p></li><li><p>Advantages: Native integration with Swift toolchain; simple manifest.</p></li><li><p>Disadvantages: Historically less feature-rich than CocoaPods for iOS resources (closing gap).</p></li></ul><p><strong>CocoaPods</strong></p><ul><li><p>What: Dependency manager for Obj-C/Swift with a Podspec system.</p></li><li><p>When: Use for iOS projects that rely on wide third-party pods.</p></li><li><p>Advantages: Mature, handles resources and frameworks.</p></li><li><p>Disadvantages: Alters project files, slower installs.</p></li></ul><p><strong>Carthage</strong></p><ul><li><p>What: Decentralized iOS dependency manager producing binary frameworks.</p></li><li><p>When: Use when you want minimal project modification.</p></li><li><p>Advantages: Non-invasive.</p></li><li><p>Disadvantages: Less automated than CocoaPods; manual integration steps.</p></li></ul><div><hr></div><h4>Haskell</h4><p><strong>Cabal / Stack</strong></p><ul><li><p>What: Cabal is package format; Stack is a build tool that pins resolver snapshots.</p></li><li><p>When: Use Stack for reproducible builds; Cabal for library packaging.</p></li><li><p>Advantages: Strong type-level package bounds, curated Stackage snapshots.</p></li><li><p>Disadvantages: Learning curve; platform-specific build complexity.</p></li></ul><div><hr></div><h4>Elixir / Erlang</h4><p><strong>Hex (Hex.pm)</strong></p><ul><li><p>What: Package manager for Erlang/Elixir packages.</p></li><li><p>When: Use for Elixir/Erlang dependencies.</p></li><li><p>Advantages: Lightweight, mix integration (Elixir build tool).</p></li><li><p>Disadvantages: Smaller ecosystem than mainstream languages.</p></li></ul><p><strong>rebar3</strong> (Erlang)</p><ul><li><p>What: Erlang build tool and dependency manager.</p></li><li><p>When: Erlang projects.</p></li><li><p>Advantages: Erlang-focused features.</p></li><li><p>Disadvantages: Less ergonomic than some newer tools.</p></li></ul><div><hr></div><h4>R</h4><p><strong>CRAN</strong> / tools like <strong>packrat</strong>, <strong>renv</strong></p><ul><li><p>What: CRAN is the central R repository; renv/packrat manage project environments.</p></li><li><p>When: Use renv/packrat for reproducible R project environments.</p></li><li><p>Advantages: Statistical-package ecosystem; renv gives per-project reproducibility.</p></li><li><p>Disadvantages: Binary dependencies and system libs complicate reuse.</p></li></ul><div><hr></div><h4>Perl</h4><p><strong>CPAN / cpanminus (cpanm)</strong></p><ul><li><p>What: CPAN is the central archive; cpanm is a lightweight client.</p></li><li><p>When: Use cpanm for fast installs; CPAN for published modules.</p></li><li><p>Advantages: Huge historical collection.</p></li><li><p>Disadvantages: Native extensions and build tooling variability.</p></li></ul><div><hr></div><h4>Lua</h4><p><strong>LuaRocks</strong></p><ul><li><p>What: Package manager for Lua modules.</p></li><li><p>When: Use for Lua dependencies.</p></li><li><p>Advantages: Simple, ecosystem-focused.</p></li><li><p>Disadvantages: Platform-native builds can be brittle.</p></li></ul><div><hr></div><h4>Dart</h4><p><strong>pub</strong></p><ul><li><p>What: Package manager and hosting for Dart/Flutter packages.</p></li><li><p>When: Use for Dart and Flutter projects.</p></li><li><p>Advantages: Integrated, pub.dev ecosystem, lockfile support.</p></li><li><p>Disadvantages: None major; tied to Dart ecosystem.</p></li></ul><div><hr></div><h2>OS-level Package Managers</h2><p><strong>OS-level Package Managers</strong> are tools that manage system-wide software and libraries for an operating system. They install, update, remove, and maintain applications and system dependencies used by both users and programs.</p><p>They operate at the operating system level, handling compiled binaries, system services, and shared libraries. These managers ensure compatibility with the OS, manage permissions, and maintain system stability.</p><h4>Linux (Debian-based)</h4><p><strong>APT (Advanced Package Tool)</strong></p><ul><li><p>What: Package manager for Debian, Ubuntu, and derivatives using <code>.deb</code> packages.</p></li><li><p>When: Use for system libraries, services, CLI tools on Debian/Ubuntu systems.</p></li><li><p>Advantages: Stable, large repositories, strong dependency handling, signed repos.</p></li><li><p>Disadvantages: Older versions in stable releases; mixing PPAs can break systems.</p></li></ul><p><strong>dpkg</strong></p><ul><li><p>What: Low-level <code>.deb</code> package tool used by APT.</p></li><li><p>When: Use for manual install/remove of local <code>.deb</code> files.</p></li><li><p>Advantages: Direct control, minimal abstraction.</p></li><li><p>Disadvantages: No dependency resolution by itself.</p></li></ul><div><hr></div><h4>Linux (Red Hat&#8211;based)</h4><p><strong>YUM</strong> (legacy) / <strong>DNF</strong> (modern)</p><ul><li><p>What: Package manager for RHEL, CentOS, Fedora using <code>.rpm</code> packages.</p></li><li><p>When: Use for system management on Red Hat-family systems.</p></li><li><p>Advantages: Strong dependency resolution, modular repos, enterprise support.</p></li><li><p>Disadvantages: Slower metadata operations; repo fragmentation across vendors.</p></li></ul><p><strong>RPM</strong></p><ul><li><p>What: Low-level package format and tool.</p></li><li><p>When: Inspect or install RPMs directly.</p></li><li><p>Advantages: Fine-grained control.</p></li><li><p>Disadvantages: No dependency resolution alone.</p></li></ul><div><hr></div><h4>Linux (Arch-based)</h4><p><strong>pacman</strong></p><ul><li><p>What: Package manager for Arch Linux and derivatives.</p></li><li><p>When: Rolling-release systems requiring latest software.</p></li><li><p>Advantages: Simple, fast, consistent syntax.</p></li><li><p>Disadvantages: Rolling releases can introduce breaking changes.</p></li></ul><div><hr></div><h4>Linux (Universal / Cross-distro)</h4><p><strong>Snap</strong></p><ul><li><p>What: Canonical&#8217;s sandboxed package system.</p></li><li><p>When: Use for isolated desktop/server apps across distros.</p></li><li><p>Advantages: Self-contained, auto-updates, sandboxing.</p></li><li><p>Disadvantages: Larger disk usage; slower startup; centralized control.</p></li></ul><p><strong>Flatpak</strong></p><ul><li><p>What: Desktop-focused sandboxed package system.</p></li><li><p>When: Use for GUI apps on Linux.</p></li><li><p>Advantages: Strong isolation, distro-agnostic.</p></li><li><p>Disadvantages: Not ideal for system services; runtime duplication.</p></li></ul><p><strong>AppImage</strong></p><ul><li><p>What: Single-file portable Linux application format.</p></li><li><p>When: Use for standalone apps without installation.</p></li><li><p>Advantages: Zero install, portable.</p></li><li><p>Disadvantages: No auto-updates or dependency management.</p></li></ul><div><hr></div><h4>Linux (Functional / Reproducible)</h4><p><strong>Nix (NixOS / nix-env / nix-shell)</strong></p><ul><li><p>What: Purely functional package manager with immutable store.</p></li><li><p>When: Use for reproducible builds, dev environments, infra-as-code.</p></li><li><p>Advantages: Reproducibility, rollback, no dependency conflicts.</p></li><li><p>Disadvantages: Steep learning curve; nonstandard filesystem layout.</p></li></ul><p><strong>Guix</strong></p><ul><li><p>What: GNU functional package manager similar to Nix.</p></li><li><p>When: Same use cases as Nix, GNU-centric systems.</p></li><li><p>Advantages: Declarative, reproducible.</p></li><li><p>Disadvantages: Smaller ecosystem than Nix.</p></li></ul><div><hr></div><h4>macOS</h4><p><strong>Homebrew</strong></p><ul><li><p>What: Widely used macOS package manager for Unix tools and apps.</p></li><li><p>When: Install developer tools, CLIs, runtimes on macOS.</p></li><li><p>Advantages: Massive ecosystem (&#8221;bottles&#8221;); easy installation of latest versions; handles distinct formulas and casks (GUI apps).</p></li><li><p>Disadvantages: Rolling-release model makes version pinning and rollback difficult (non-deterministic); modifies <code>/usr/local</code> or <code>/opt/homebrew</code> with user permissions, effectively bypassing some system isolation protections.</p></li></ul><p><strong>MacPorts</strong></p><ul><li><p>What: macOS package manager with isolated prefix.</p></li><li><p>When: Need strict dependency isolation.</p></li><li><p>Advantages: Predictable builds, isolation.</p></li><li><p>Disadvantages: Slower; smaller community than Homebrew.</p></li></ul><div><hr></div><h4>Windows</h4><p><strong>Chocolatey</strong></p><ul><li><p>What: Windows package manager for apps and tools.</p></li><li><p>When: Automate Windows dev machine setup.</p></li><li><p>Advantages: Scriptable installs, wide catalog.</p></li><li><p>Disadvantages: Packages often wrap installers; quality varies.</p></li></ul><p><strong>Winget</strong></p><ul><li><p>What: Official Windows Package Manager by Microsoft.</p></li><li><p>When: Standardized Windows app installation.</p></li><li><p>Advantages: Native, improving rapidly, trusted source.</p></li><li><p>Disadvantages: Smaller ecosystem than Chocolatey (for now).</p></li></ul><p><strong>Scoop</strong></p><ul><li><p>What: Lightweight Windows CLI package manager.</p></li><li><p>When: Install developer tools without admin rights.</p></li><li><p>Advantages: Simple, user-local installs.</p></li><li><p>Disadvantages: Smaller catalog.</p></li></ul><div><hr></div><h4>BSD Systems</h4><p><strong>pkg</strong> (FreeBSD)</p><ul><li><p>What: Binary package manager for FreeBSD.</p></li><li><p>When: Manage system packages on FreeBSD servers/desktops.</p></li><li><p>Advantages: Clean dependency handling, stable repos.</p></li><li><p>Disadvantages: Smaller ecosystem vs Linux.</p></li></ul><p><strong>Ports Collection</strong></p><ul><li><p>What: Source-based package system.</p></li><li><p>When: Custom compile-time options needed.</p></li><li><p>Advantages: Maximum control.</p></li><li><p>Disadvantages: Slow builds; manual effort.</p></li></ul><div><hr></div><h4>Solaris / Illumos</h4><p><strong>IPS (Image Packaging System)</strong></p><ul><li><p>What: Package system for Solaris-derived OSes.</p></li><li><p>When: Enterprise Solaris environments.</p></li><li><p>Advantages: ZFS integration, atomic updates.</p></li><li><p>Disadvantages: Niche ecosystem.</p></li></ul><div><hr></div><h3>When to use OS-level vs Language-level managers</h3><p><strong>Use OS-level package managers when:</strong></p><ul><li><p>Installing system-wide services, kernels, or drivers.</p></li><li><p>Managing base server images and security patches.</p></li><li><p>Exception: Functional package managers like <strong>Nix </strong>and<strong> Guix</strong> are OS-level tools that <em>can</em> handle per-project isolation effectively, blurring this line.</p></li></ul><p><strong>Do NOT use OS-level managers when:</strong></p><ul><li><p>Managing application dependencies inside a project</p></li><li><p>You need per-project version isolation</p></li><li><p>Reproducibility across machines matters</p></li></ul><p>Use <strong>language-level managers</strong> for apps, <strong>OS-level managers</strong> for the system.</p><h3>Dependency resolution &#8212; the hard part</h3><p>Dependency resolution is where most complexity and subtle bugs happen.</p><ul><li><p><strong>Constraint types</strong>: exact, range (semver), open (latest), exclusion.</p></li><li><p><strong>Solver strategies</strong>:</p><ul><li><p>Greedy (fast, may fail on complex constraints)</p></li><li><p>Backtracking SAT-like solvers (complete but slower)</p></li><li><p>Deterministic pinning (freeze a full lockfile)</p></li></ul></li><li><p><strong>Conflicts</strong>: two packages require incompatible versions of the same dependency &#8212; resolution strategies include upgrade, downgrade, multiple side-by-side installations, or refusing install.</p></li><li><p><strong>Transitive explosion</strong>: small change can pull many packages; lockfiles and reproducible builds mitigate this.</p></li></ul><p>Practical pattern: for applications, prefer <strong>lockfiles</strong> (exact pins) and reproducible installs. For system packages, use conservative upgrades and well-curated repositories.</p><h3>Security: integrity, provenance, and supply-chain risks</h3><p>Key controls:</p><ul><li><p><strong>Checksums</strong>: verify downloaded archives against published hashes.</p></li><li><p><strong>Signing</strong>: GPG/PGP signatures for packages and repository metadata; prevents tampering and impersonation.</p></li><li><p><strong>TLS + repo auth</strong>: secure transport and authenticated registries for private packages.</p></li><li><p><strong>Least-privilege install</strong>: avoid running install scripts as root when unnecessary.</p></li><li><p><strong>Reproducible builds</strong>: allow independent verification that binaries come from source.</p></li><li><p><strong>Monitoring &amp; scanning</strong>: vulnerability scanners (Snyk, OSS Index), artifact scanning in CI.</p></li></ul><p>Reality: public registries have been exploited (typosquatting, malicious packages). Mitigations: scoped registries, allowlist, signing, internal mirrors or proxies.</p><h3>Operational patterns and CI/CD integration</h3><ul><li><p><strong>Artifact repositories</strong>: publish built artifacts (binaries/wheels/images) to a controlled registry from CI. Avoid building in production environments.</p></li><li><p><strong>Promotion model</strong>: publish to staging repo &#8594; run integration tests &#8594; promote to production repo (immutable artifact promotion).</p></li><li><p><strong>Immutable artifacts + rollbacks</strong>: keep old artifacts for rollback; use exact pins in deployment.</p></li><li><p><strong>Cache layers / proxies</strong>: use caching proxies (e.g., Artifactory, Verdaccio) to reduce external outages and improve reproducibility.</p></li><li><p><strong>Automated dependency updates</strong>: Dependabot/renovate for PRs; but guard with tests and gated promotion.</p></li></ul><h3>Common failure modes and how to avoid them</h3><ul><li><p><strong>Dependency hell</strong>: conflicting transitive deps. Avoid by strict pinning and prefer single-source dependencies when possible.</p></li><li><p><strong>Left-pad problem / small malicious packages</strong>: one small package can break large ecosystems. Favor vetted, well-maintained dependencies.</p></li><li><p><strong>Broken install scripts</strong>: lifecycle scripts run with privileges can cause system instability. Avoid unnecessary scripts; validate before merging.</p></li><li><p><strong>Registry outages</strong>: use mirrors and caches; vendor critical dependencies.</p></li><li><p><strong>Ambiguous ownership</strong>: packages overwritten in repos by mistake. Enforce signing, access controls, and CI gates.</p></li></ul><h3>Design considerations for writing and maintaining packages</h3><p>For package authors:</p><ul><li><p>Provide <strong>complete metadata</strong> (name, description, license, homepage, author, version, dependencies).</p></li><li><p>Keep <strong>install scripts idempotent</strong> and safe to re-run.</p></li><li><p>Avoid assuming global mutable state; allow relocatable installation where feasible.</p></li><li><p>Include <strong>checksums and signatures</strong> for binary artifacts.</p></li><li><p>Publish <strong>artifacts built in CI</strong> (not developer machines); store build logs and provenance.</p></li><li><p>Maintain a clear deprecation and migration path for breaking changes.</p></li></ul><p>For repository maintainers:</p><ul><li><p>Enforce <strong>review policies</strong>, sign packages, and scan for known vulnerabilities.</p></li><li><p>Support <strong>artifact immutability</strong> and retention policies.</p></li><li><p>Expose clear <strong>version compatibility</strong> and support windows for major breaking changes.</p></li></ul><h3>Emerging trends and alternatives</h3><ul><li><p><strong>Functional/package managers (Nix, Guix)</strong>: treat packages as immutable derivations, enabling per-user installs and reproducible environments.</p></li><li><p><strong>Artifact registries &amp; SBOMs</strong>: Software Bill of Materials (SBOM) for supply-chain visibility.</p></li><li><p><strong>Container-centric deployments</strong>: shift packaging from language managers to OCI images, reducing cross-language dependency issues but shifting complexity to image build pipelines.</p></li><li><p><strong>Package signing adoption</strong>: more registries require signatures and provenance metadata.</p><p></p></li></ul><div class="pullquote"><p><em>Do you know someone who loves engineering or has a curiosity for tech? &#129300;<br>Why not share the joy of simplifying complex ideas with them? Forward this newsletter and spread the knowledge&#8212;<strong>learning is always better when it&#8217;s shared!</strong> &#128640;</em></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://codiescoder.substack.com/?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share&quot;,&quot;text&quot;:&quot;Share Codies Coder Newsletter&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://codiescoder.substack.com/?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share"><span>Share Codies Coder Newsletter</span></a></p></div>]]></content:encoded></item><item><title><![CDATA[Ever Wonder Why Your Containers Just Work Everywhere?]]></title><description><![CDATA[Meet OCI &#8211; The Quiet Revolution That Broke Vendor Lock-in Forever]]></description><link>https://codiescoder.substack.com/p/ever-wonder-why-your-containers-just</link><guid isPermaLink="false">https://codiescoder.substack.com/p/ever-wonder-why-your-containers-just</guid><dc:creator><![CDATA[Ajay Negi]]></dc:creator><pubDate>Wed, 09 Jul 2025 16:05:13 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!VzqD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd534e0e4-92e1-4413-af7d-07489b20e4bd_937x856.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Imagine shipping a product worldwide. Boxes go by boat, train, and truck&#8212;each designed for one transport method. Chaos, right? Now picture standardized shipping containers fitting seamlessly on <em>any</em> vehicle. That&#8217;s exactly what the <strong>Open Container Initiative (OCI)</strong> did for software.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!VzqD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd534e0e4-92e1-4413-af7d-07489b20e4bd_937x856.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!VzqD!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd534e0e4-92e1-4413-af7d-07489b20e4bd_937x856.webp 424w, https://substackcdn.com/image/fetch/$s_!VzqD!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd534e0e4-92e1-4413-af7d-07489b20e4bd_937x856.webp 848w, https://substackcdn.com/image/fetch/$s_!VzqD!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd534e0e4-92e1-4413-af7d-07489b20e4bd_937x856.webp 1272w, https://substackcdn.com/image/fetch/$s_!VzqD!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd534e0e4-92e1-4413-af7d-07489b20e4bd_937x856.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!VzqD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd534e0e4-92e1-4413-af7d-07489b20e4bd_937x856.webp" width="500" height="456.7769477054429" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d534e0e4-92e1-4413-af7d-07489b20e4bd_937x856.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:856,&quot;width&quot;:937,&quot;resizeWidth&quot;:500,&quot;bytes&quot;:99732,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://codiescoder.substack.com/i/167913291?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd534e0e4-92e1-4413-af7d-07489b20e4bd_937x856.webp&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!VzqD!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd534e0e4-92e1-4413-af7d-07489b20e4bd_937x856.webp 424w, https://substackcdn.com/image/fetch/$s_!VzqD!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd534e0e4-92e1-4413-af7d-07489b20e4bd_937x856.webp 848w, https://substackcdn.com/image/fetch/$s_!VzqD!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd534e0e4-92e1-4413-af7d-07489b20e4bd_937x856.webp 1272w, https://substackcdn.com/image/fetch/$s_!VzqD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd534e0e4-92e1-4413-af7d-07489b20e4bd_937x856.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3><strong>Why Containers Needed Standardization</strong></h3><p>Before 2015, containers were exploding in popularity&#8212;thanks largely to Docker. But every platform used its own image format and runtime tools. Want to move a container from Docker to CoreOS? Good luck. This "Babel tower" of incompatible formats stifled innovation and tied users to specific vendors .</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://codiescoder.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Codies Coder Newsletter! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>Enter the OCI. Founded in June 2015 by Docker, CoreOS, and industry leaders like Google and Microsoft, its mission was simple:</p><blockquote><p><em>"Create open, vendor-neutral standards so containers run anywhere, regardless of who built them."</em> </p></blockquote><p>Docker kickstarted it by donating its core container format and runtime code&#8212; proving this wasn&#8217;t just theory, but a practical shift.</p><h3><strong>What is OCI, Really?</strong></h3><p>Think of OCI as the "rulebook" for containers. It defines three critical standards:</p><ol><li><p><strong>Runtime Specification (runtime-spec)</strong></p><ul><li><p>Governs how a container <em>runs</em>.</p></li><li><p>Defines setup, execution, and isolation using Linux features like <code>cgroups</code> and namespaces.</p></li><li><p>Tools like <code>runc</code> (the reference implementation) use this to start/stop containers.</p></li></ul></li><li><p><strong>Image Specification (image-spec)</strong></p><ul><li><p>The blueprint for container <em>images</em>.</p></li><li><p>Images are built in <strong>layers</strong> (like a cake). Each layer adds files or changes (e.g., installing Python, then your app).</p></li><li><p>A manifest file stitches layers together, while a config file sets environment variables or commands.</p></li></ul></li><li><p><strong>Distribution Specification (distribution-spec)</strong></p><ul><li><p>Rules for pushing/pulling images to registries (like Docker Hub).</p></li><li><p>Uses a standardized HTTP API&#8212;so <em>any</em> registry works with <em>any</em> client.</p></li></ul></li></ol><h3><strong>OCI Real-World Impact</strong></h3><p>OCI standards freed containers from Docker&#8217;s orbit. Today, they&#8217;re the invisible backbone of modern tech:</p><ul><li><p><strong>Kubernetes Compatibility:</strong> Tools like CRI-O (a lightweight Docker alternative) use OCI runtimes to launch Kubernetes pods. No Docker needed.</p></li><li><p><strong>Innovation in Runtimes:</strong></p><ul><li><p><strong>gVisor:</strong> Adds security "sandboxes" (Google Cloud).</p></li><li><p><strong>Kata Containers:</strong> Uses lightweight VMs for hardware-level isolation.</p></li><li><p><strong>Firecracker:</strong> Powers AWS Lambda with micro-VMs.</p></li></ul></li><li><p><strong>Multi-Architecture Support:</strong><br>OCI images include manifests for ARM, x86, and more. Build once, run on any chip </p></li></ul><h3><strong>Why Should </strong><em><strong>You</strong></em><strong> Care?</strong></h3><ol><li><p><strong>No More Vendor Lock-in</strong><br>Build an image with Google <code>kaniko</code>, store it in AWS ECR, run it on Azure with <code>runc</code>&#8212;all seamlessly.</p></li><li><p><strong>Security by Default</strong><br>Standards ensure images are scanned, signed, and run in isolated environments. OCI <code>config.json</code> even controls permissions.</p></li><li><p><strong>The Innovation Engine</strong><br>New runtimes (like WebAssembly-based <code>wasmEdge</code>) plug into OCI ecosystems. No reinventing the wheel.</p></li></ol><h3><strong>The Future: What&#8217;s Next for OCI?</strong></h3><p>Recent updates hint at where OCI is headed:</p><ul><li><p><strong>2024:</strong> Image and Distribution Specs v1.1 improved artifact references (e.g., linking Helm charts to containers).</p></li><li><p><strong>Security Focus:</strong> Projects like <code>ocicy</code> verify image signatures before pulling.</p></li><li><p><strong>Beyond Linux:</strong> Runtimes like <code>runj</code> now support FreeBSD Jails.</p></li></ul><p><em>Hungry for more? Dive into the specs at <a href="https://opencontainers.org/">opencontainers.org</a></em></p><div class="pullquote"><p><em>Do you know someone who loves engineering or has a curiosity for tech? &#129300;<br>Why not share the joy of simplifying complex ideas with them? Forward this newsletter and spread the knowledge&#8212;<strong>learning is always better when it&#8217;s shared!</strong> &#128640;</em></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://codiescoder.substack.com/?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share Codies Coder Newsletter&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://codiescoder.substack.com/?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share Codies Coder Newsletter</span></a></p></div>]]></content:encoded></item><item><title><![CDATA[Docker Architecture]]></title><description><![CDATA[Docker has revolutionized how applications are built, shipped, and run by using a technology called &#8220;containerization.&#8221; Instead of running a whole separate operating system like a virtual machine, Docker runs your application in a container&#8212;a lightweight, isolated environment that shares the host&#8217;s OS kernel]]></description><link>https://codiescoder.substack.com/p/docker-architecture</link><guid isPermaLink="false">https://codiescoder.substack.com/p/docker-architecture</guid><dc:creator><![CDATA[Ajay Negi]]></dc:creator><pubDate>Mon, 21 Apr 2025 15:04:27 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/32194230-557c-4f33-9925-34d13b6fc877_3652x2631.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Docker has revolutionized how applications are built, shipped, and run by using a technology called &#8220;containerization.&#8221; Instead of running a whole separate operating system like a virtual machine, Docker runs your application in a container&#8212;a lightweight, isolated environment that shares the host&#8217;s OS kernel.</p><h2>What is Docker and Containerization?</h2><h3>The Big Picture</h3><ul><li><p><strong>Docker</strong> is a platform that helps you package an application along with everything it needs&#8212;like libraries and settings&#8212;so it can run reliably in any environment.</p></li><li><p><strong>Containers</strong> are like small, portable mini-computers inside your computer. They run as isolated processes, but they don&#8217;t require an entire operating system on their own.</p></li></ul><h3>Containers vs. Virtual Machines</h3><ul><li><p><strong>Virtual Machines (VMs):</strong> These emulate complete hardware systems and run separate operating systems. They are heavy and require more resources.</p></li><li><p><strong>Containers:</strong> These share the host&#8217;s operating system kernel and are much lighter, making them faster to start and more resource-efficient.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!QFvh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19c2a713-44c2-483d-8974-ecc71da86989_1163x772.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!QFvh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19c2a713-44c2-483d-8974-ecc71da86989_1163x772.webp 424w, https://substackcdn.com/image/fetch/$s_!QFvh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19c2a713-44c2-483d-8974-ecc71da86989_1163x772.webp 848w, https://substackcdn.com/image/fetch/$s_!QFvh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19c2a713-44c2-483d-8974-ecc71da86989_1163x772.webp 1272w, https://substackcdn.com/image/fetch/$s_!QFvh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19c2a713-44c2-483d-8974-ecc71da86989_1163x772.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!QFvh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19c2a713-44c2-483d-8974-ecc71da86989_1163x772.webp" width="562" height="373.0558899398108" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/19c2a713-44c2-483d-8974-ecc71da86989_1163x772.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:772,&quot;width&quot;:1163,&quot;resizeWidth&quot;:562,&quot;bytes&quot;:41514,&quot;alt&quot;:&quot;Virtual Machines vs Containers &quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://codiescoder.substack.com/i/161671779?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19c2a713-44c2-483d-8974-ecc71da86989_1163x772.webp&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Virtual Machines vs Containers " title="Virtual Machines vs Containers " srcset="https://substackcdn.com/image/fetch/$s_!QFvh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19c2a713-44c2-483d-8974-ecc71da86989_1163x772.webp 424w, https://substackcdn.com/image/fetch/$s_!QFvh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19c2a713-44c2-483d-8974-ecc71da86989_1163x772.webp 848w, https://substackcdn.com/image/fetch/$s_!QFvh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19c2a713-44c2-483d-8974-ecc71da86989_1163x772.webp 1272w, https://substackcdn.com/image/fetch/$s_!QFvh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19c2a713-44c2-483d-8974-ecc71da86989_1163x772.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Virtual Machines vs Containers </figcaption></figure></div></li></ul><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://codiescoder.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Codies Coder Newsletter! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h2>Docker Architecture</h2><div class="image-gallery-embed" data-attrs="{&quot;gallery&quot;:{&quot;images&quot;:[{&quot;type&quot;:&quot;image/png&quot;,&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e5f56b58-42f6-4b58-be53-63cdcf79a5f8_1400x701.png&quot;}],&quot;caption&quot;:&quot;Docker Architecture&quot;,&quot;alt&quot;:&quot;Docker Architecture&quot;,&quot;staticGalleryImage&quot;:{&quot;type&quot;:&quot;image/png&quot;,&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e5f56b58-42f6-4b58-be53-63cdcf79a5f8_1400x701.png&quot;}},&quot;isEditorNode&quot;:true}"></div><h4>Docker Client</h4><ul><li><p>The Docker Client is the part you use. When you type something like <code>docker run myapp</code>, it sends that command to the Docker Host using a <strong>REST API</strong>. It doesn&#8217;t run containers itself &#8212; it just tells the <strong>Docker engine</strong> what to do.</p></li></ul><h4>Docker Host/Server</h4><ul><li><p>When the client says &#8220;run this app,&#8221; the Docker <strong>Daemon</strong> (also called Docker Engine) starts working.</p></li><li><p>Checks if the image is available</p><ul><li><p>If not present, it pulls the image from the <strong>Docker Registry</strong>.</p></li><li><p>If available, it uses the image to <strong>create a container</strong>.</p></li></ul></li><li><p>Docker Engine uses several internal components to manage containers:</p><ul><li><p><strong>containerd</strong>: A background service that manages the full container lifecycle (start, stop, delete, etc.)</p></li><li><p><strong>runc</strong>: lightweight tool used by <code>containerd</code> to run containers. It talks directly to the <strong>Linux kernel</strong> using <strong>namespaces</strong> (for isolation) and <strong>cgroups</strong> (for resource limits), following the OCI runtime spec.</p></li><li><p><strong>OCI</strong> (Open Container Initiative): A global standard that Docker, containerd, and runc all follow, so everything works smoothly and is compatible.</p></li></ul></li><li><p>An image is a read-only template that includes your application code, libraries, and dependencies. Images are built in <strong>Layered Structure</strong> using a mechanism called a union file system.</p></li><li><p>A container is an instance of an image. When you run an image, Docker creates a container. Containers share the host&#8217;s OS kernel but run as isolated processes, so they don&#8217;t interfere with each other.</p></li></ul><h4>Docker Registry</h4><ul><li><p>A <strong>registry</strong> is like a big online storage center for Docker images. The most common one is <strong>Docker Hub</strong>, but you can also use private registries.</p></li><li><p>You can pull images from a registry to run them or push your own images to share with others.</p></li></ul><h2>How Docker Works at a Low Level</h2><p>Let&#8217;s understand <strong>how containers share the host&#8217;s OS kernel</strong>, yet run in completely <strong>isolated environments</strong>, using the Linux kernel.</p><p>Starting around <strong>Docker 1.0 (2014)</strong>, Docker moved away from depending on LXC and introduced its own execution driver called <code>libcontainer</code> (which later became <code>runc</code>, the OCI runtime).</p><p>After getting instructions from Docker (via <code>containerd</code>), <code>runc</code> uses <strong>Linux system calls</strong> to set up a container. These system calls are like direct messages to the Linux kernel. It creates a new container process with:</p><ul><li><p><strong>New namespaces</strong> (for isolation)</p></li><li><p><strong>New cgroup assignments</strong> (for resource control)</p></li></ul><h4>A. Namespaces: The Isolation Tool</h4><ul><li><p>Namespaces are a Linux kernel feature that creates isolated environments. They ensure that a process in one container cannot see or affect processes in another container or on the host. To isolate the container from the rest of the system, <code>runc</code> uses the system call with special flags.</p></li><li><p>Namespaces are created for the container via the <code>unshare</code> system call</p></li><li><p><strong>Types of Namespaces:</strong></p><ul><li><p><strong>PID Namespace:</strong> Isolates process IDs so each container thinks it is the only one running.</p></li><li><p><strong>Network Namespace:</strong> Gives each container its own network stack.</p></li><li><p><strong>Mount Namespace:</strong> Provides isolated file system views.</p></li><li><p><strong>Others:</strong> There are additional namespaces for user IDs, inter-process communication (IPC), etc.</p></li></ul></li></ul><h4>B. Cgroups (Control Groups): Managing Resources</h4><ul><li><p>After setting up namespaces, <code>runc</code> assigns the process to a <strong>cgroup</strong>. It does this by writing to special files in <code>/sys/fs/cgroup/</code>.</p></li><li><p>Cgroups allow Docker to limit, prioritize, and isolate the resources (like CPU, memory, and disk I/O) each container can use.</p></li><li><p>This ensures that no single container can hog all the resources, making the system more stable and efficient.</p></li></ul><h4>C. Union File Systems: Layering Made Easy</h4><ul><li><p>Docker sets up the <strong>container&#8217;s file system</strong> using a union file system (like OverlayFS, AUFS). </p></li><li><p>Each Docker image is made of layers &#8212; and Docker doesn&#8217;t copy all files. Instead, it mounts the layers together and uses <strong>copy-on-write</strong>:</p><ul><li><p>Read-only base image layers are shared</p></li><li><p>A writable layer is added on top just for this container</p></li></ul></li><li><p>This is done using system calls like <code>mount()</code> and union mount options.</p><p></p></li></ul><div class="pullquote"><p><em>Do you know someone who loves engineering or has a curiosity for tech? &#129300;<br>Why not share the joy of simplifying complex ideas with them? Forward this newsletter and spread the knowledge&#8212;<strong>learning is always better when it&#8217;s shared!</strong> &#128640;</em></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://codiescoder.substack.com/?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share&quot;,&quot;text&quot;:&quot;Share Codies coder&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://codiescoder.substack.com/?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share"><span>Share Codies coder</span></a></p></div>]]></content:encoded></item><item><title><![CDATA[Understanding Multithreading in Java]]></title><description><![CDATA[When it comes to running multiple tasks on a computer, the terms multitasking and multithreading often pop up. But what do they really mean, and how do they relate to the Java programming language?]]></description><link>https://codiescoder.substack.com/p/understanding-multithreading-in-java</link><guid isPermaLink="false">https://codiescoder.substack.com/p/understanding-multithreading-in-java</guid><dc:creator><![CDATA[Ajay Negi]]></dc:creator><pubDate>Wed, 19 Feb 2025 13:56:13 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/f4e4289c-9628-41bb-94b1-af1fbbf5d024_4331x2522.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When it comes to running multiple tasks on a computer, the terms <strong>multitasking</strong> and <strong>multithreading</strong> often pop up. But what do they really mean, and how do they relate to the Java programming language? Before we dive into the intricacies of <strong>multithreading</strong>, let&#8217;s first understand a few foundational concepts.</p><div><hr></div><h3>The Building Blocks of a Computer's Task Management</h3><p>At the heart of every computer is the <strong>CPU</strong> (Central Processing Unit)&#8212;often called the brain of the computer. It&#8217;s responsible for executing instructions, performing calculations, and managing everything that runs on your system. In other words, the CPU handles all the tasks your computer needs to perform.</p><h4>What is a Core?</h4><p>Modern CPUs aren&#8217;t just single-task processors; they have <strong>cores</strong>. Think of each core as a mini-brain that can handle its own set of tasks. For example, a quad-core processor can run <strong>four</strong> different tasks simultaneously. Imagine this: one core manages your web browser, another plays music, another handles a download, and the fourth manages background system updates&#8212;all at the same time!</p><h4>Program vs. Process</h4><p>A <strong>program</strong> is a set of instructions that tell your computer what to do. For example, Microsoft Word is a program designed to help you create and edit documents.</p><p>When you open a program, it doesn&#8217;t just run by itself. The operating system creates a <strong>process</strong> to handle its execution. So, when you launch Microsoft Word, it becomes a running process in the operating system&#8212;essentially <strong>an active instance of the program</strong>.</p><h4>What is a Thread?</h4><p>Inside each process, there are smaller units of execution called <strong>threads</strong>. Think of a thread as a line of activity within a program. A process can have multiple threads, all working together but able to perform different tasks independently.</p><p>For instance, in a web browser like <strong>Google Chrome</strong>, each tab might run in its own thread, allowing you to browse different websites simultaneously without interruptions.</p><blockquote><p>Each thread requires an allocation of stack memory whose default size ranges from 64 KB to 1 MB, depending on the OS.</p></blockquote><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!_NqC!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6fd63be-e557-415e-892d-7bbe6a456090_1448x836.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_NqC!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6fd63be-e557-415e-892d-7bbe6a456090_1448x836.jpeg 424w, https://substackcdn.com/image/fetch/$s_!_NqC!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6fd63be-e557-415e-892d-7bbe6a456090_1448x836.jpeg 848w, https://substackcdn.com/image/fetch/$s_!_NqC!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6fd63be-e557-415e-892d-7bbe6a456090_1448x836.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!_NqC!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6fd63be-e557-415e-892d-7bbe6a456090_1448x836.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_NqC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6fd63be-e557-415e-892d-7bbe6a456090_1448x836.jpeg" width="592" height="341.7900552486188" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d6fd63be-e557-415e-892d-7bbe6a456090_1448x836.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:836,&quot;width&quot;:1448,&quot;resizeWidth&quot;:592,&quot;bytes&quot;:205820,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!_NqC!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6fd63be-e557-415e-892d-7bbe6a456090_1448x836.jpeg 424w, https://substackcdn.com/image/fetch/$s_!_NqC!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6fd63be-e557-415e-892d-7bbe6a456090_1448x836.jpeg 848w, https://substackcdn.com/image/fetch/$s_!_NqC!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6fd63be-e557-415e-892d-7bbe6a456090_1448x836.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!_NqC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6fd63be-e557-415e-892d-7bbe6a456090_1448x836.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><h3>What is Multitasking?</h3><p>Now, let&#8217;s talk about <strong>multitasking</strong>&#8212;the ability to run multiple tasks at once. If you&#8217;re on a <strong>single-core CPU</strong>, multitasking works by switching between tasks so rapidly that you feel like everything is running at the same time. This process is known as <strong>time-sharing</strong>. </p><p>In <strong>multi-core CPUs</strong>, real multitasking happens. The operating system can assign each task to a different core, allowing them to run truly in parallel, which results in better performance.</p><p>For example, you might be listening to music, downloading a file, and browsing the web all at once. Each of these tasks can be distributed across different cores, improving efficiency.</p><div><hr></div><h3>Introduction to Multithreading</h3><p>Here&#8217;s where things get interesting&#8212;<strong>multithreading</strong>.</p><p>At a high level, multithreading refers to executing <strong>multiple threads</strong> within a single process <strong>concurrently</strong>. This allows a single application to perform several tasks at once. For example, in a web browser, separate threads may handle things like rendering the page, processing JavaScript, and managing user input all at the same time. This makes the application more responsive and efficient.</p><h4><strong>Why is Multithreading Important?</strong></h4><p>The main benefit of multithreading is <strong>efficiency</strong>. By breaking tasks into smaller, manageable threads, your computer can utilize its CPU resources better, especially in multi-core systems.</p><div><hr></div><h2>How Does Multithreading Work in Java?</h2><p>In Java, multithreading is built into the language. <strong>Every thread in Java</strong> is controlled by an object of the <code>java.lang.Thread</code> class. This class helps the thread know what tasks it should perform and when to stop.</p><p>When you run a program in Java, there&#8217;s always a special thread called the <strong>main thread</strong> that starts the program. This thread runs the <code>main()</code> method, which is where your program begins. Here&#8217;s a simple illustration:</p><ol><li><p><strong>Main Thread</strong>: When you run a Java application, a thread is automatically created to execute the <code>main()</code> method. This is your <strong>main thread</strong>.</p></li><li><p><strong>Additional Threads</strong>: If you want to do other things in parallel, you can create new threads.</p></li></ol><h3>How Do We Create Threads in Java?</h3><p>There are two main ways to create threads in Java:</p><ol><li><p><strong>By implementing the </strong><code>Runnable</code><strong> interface</strong></p></li><li><p><strong>By extending the </strong><code>Thread</code><strong> class</strong></p></li></ol><p>Let&#8217;s dive deeper into each method and understand why and when you might choose one over the other.</p><h3>1. Creating Threads by Implementing the <code>Runnable</code> Interface</h3><p>The <code>Runnable</code> interface is a simple way to create threads in Java. It&#8217;s like writing a to-do list, where you define the tasks you want the thread to do. When a thread is created using <code>Runnable</code>, it doesn&#8217;t directly extend the <code>Thread</code> class. Instead, it implements the <code>Runnable</code> interface and overrides the <code>run()</code> method to specify the code that will run on the thread.</p><pre><code><code>class MyTask implements Runnable {
    public void run() {
        // Code that you want the thread to execute
        System.out.println("Task is running!...");
    }
}

// You can then create a new thread and pass an instance of MyTask to it
public class Main {
    public static void main(String[] args) {
        MyTask task = new MyTask();
        Thread thread = new Thread(task);
        thread.start(); // Starts a new thread to run the task
    }
}</code></code></pre><h4>Why Use <code>Runnable</code>?</h4><ul><li><p><strong>No Multiple Inheritance</strong>: Java doesn&#8217;t support multiple inheritance. If you extend the <code>Thread</code> class, your class can&#8217;t extend any other class. But if you use <code>Runnable</code>, your class can still extend another class and do other things as well. So, if your class needs to inherit from another class, <strong>using </strong><code>Runnable</code><strong> is a better choice</strong>.</p></li><li><p><strong>Flexibility</strong>: If you only care about making your code run in a thread, implementing <code>Runnable</code> is often more lightweight and doesn&#8217;t add unnecessary overhead.</p></li></ul><h3>2. Creating Threads by Extending the <code>Thread</code> Class</h3><p>Another way to create a thread is by directly extending the <code>Thread</code> class. This is the more traditional way of working with threads in Java. You create a new class that extends <code>Thread</code>, and override the <code>run()</code> method to define the tasks you want the thread to perform.</p><pre><code><code>class MyTask extends Thread {
    public void run() {
        // Code that you want the thread to execute
        System.out.println("Task is running!");
    }
}

// Create a new instance of MyTask and start the thread like this
public class Main {
    public static void main(String[] args) {
        MyTask task = new MyTask();
        task.start(); // Starts a new thread to run the task
    }
}</code></code></pre><h4>Why Use <code>Thread</code>?</h4><ul><li><p><strong>Simple and Direct</strong>: If your class doesn't need to inherit from any other class, extending <code>Thread</code> is a simpler approach. It&#8217;s direct, and all thread-related methods (like <code>start()</code>, <code>sleep()</code>, etc.) are already available.</p></li><li><p><strong>Slightly Overhead</strong>: If your class needs to do more than just run a thread (i.e., extend another class), then this method might not be the best choice because it forces your class to extend <code>Thread</code>.</p></li></ul><h3>Why Choose One Over the Other?</h3><p>Now that you know how to create threads in Java, you might wonder, &#8220;Which method should I use?&#8221; Here&#8217;s the basic rule of thumb:</p><ul><li><p><strong>Use </strong><code>Runnable</code><strong> when</strong> you want flexibility. For example, if your class needs to extend another class or if you don&#8217;t want the overhead of the <code>Thread</code> class.</p></li><li><p><strong>Use </strong><code>Thread</code><strong> when</strong> you need a simple solution and don&#8217;t need to extend any other class.</p></li></ul><h2><strong>Thread Lifecycle</strong></h2><p>A Java thread goes through several states as it is created, executed, and eventually ends. Here&#8217;s how it works:</p><ul><li><p><strong>New: </strong>When you create a thread (for example, by calling a constructor of <code>Thread</code> or implementing <code>Runnable</code>), it is in the &#8220;new&#8221; state. At this point, the thread exists in your program&#8217;s memory but is not yet scheduled for execution by the Java Virtual Machine (JVM).</p></li><li><p><strong>Runnable: </strong>Once you call the <code>start()</code> method, the thread becomes runnable. This means it is ready to run and is waiting in a queue for the CPU to pick it up. Note that &#8220;runnable&#8221; does not necessarily mean the thread is running at that exact moment. The thread scheduler, which is part of the JVM and underlying operating system, decides which runnable thread gets CPU time. This scheduling can vary by platform and by thread priority.</p></li><li><p><strong>Running: </strong>When the thread scheduler picks your thread from the runnable queue, it starts executing the code in its <code>run()</code> method. In many cases, &#8220;running&#8221; is considered a subset of &#8220;runnable&#8221;&#8212;only one thread can actually be executing on a given CPU core at any moment. If your machine has multiple cores, several threads may truly run simultaneously.</p></li><li><p><strong>Blocked/Waiting/Timed Waiting: </strong>A thread is in this state when it is waiting for a resource or for another thread to perform an action. While running, a thread may need to pause for various reasons:</p><ul><li><p><strong>Blocked:</strong> The thread is waiting to acquire a lock (for example, when entering a synchronized block).</p></li><li><p><strong>Waiting:</strong> The thread is waiting indefinitely for a specific condition to occur, typically because it called <code>wait()</code> and is waiting for a notification (using <code>notify()</code> or <code>notifyAll()</code>).</p></li><li><p><strong>Timed Waiting:</strong> The thread is paused for a specified amount of time (for example, when calling <code>sleep(long millis)</code> or <code>join(long millis)</code>).</p></li></ul></li><li><p><strong>Terminated:</strong> Once a thread completes its task&#8212;whether it reaches the end of the <code>run()</code> method or is interrupted&#8212;it enters the terminated state. A terminated  thread cannot be restarted. Proper cleanup and resource management (such as closing files or releasing locks) should be handled before a thread finishes.</p></li></ul><div class="image-gallery-embed" data-attrs="{&quot;gallery&quot;:{&quot;images&quot;:[{&quot;type&quot;:&quot;image/png&quot;,&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/57c17f0f-b185-44b7-9972-e969196b90f0_1591x851.png&quot;}],&quot;caption&quot;:&quot;Thread Lifecycle&quot;,&quot;alt&quot;:&quot;Thread Lifecycle&quot;,&quot;staticGalleryImage&quot;:{&quot;type&quot;:&quot;image/png&quot;,&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/57c17f0f-b185-44b7-9972-e969196b90f0_1591x851.png&quot;}},&quot;isEditorNode&quot;:true}"></div><h2><strong>Thread methods</strong></h2><ol><li><p><strong>start( ):</strong> This method tells the JVM to schedule your thread for execution. It creates a new call stack for the thread and then calls the <code>run()</code> method. (Tip: Never call <code>run()</code> directly if you want concurrent execution.)</p></li><li><p><strong>run( )</strong>: The entry point for the thread. When the thread is started, the <code>run()</code> method is invoked. If the thread was created using a class that implements <code>Runnable</code>, the <code>run()</code> method will execute the <code>run()</code> method of that <code>Runnable</code> object.  Override this method to define what the thread should do when it runs. Although it contains your code, calling it directly executes the code in the current thread rather than in a new one.</p></li><li><p><strong>sleep(long millis):</strong> Pauses the current thread for a specified number of milliseconds. This is useful for delaying execution or simulating time-consuming tasks. Always be prepared to handle an <code>InterruptedException</code>.</p></li><li><p><strong>join(): </strong>Makes one thread wait for another to finish. For example, if you have a main thread that must wait for a background thread to complete, you call <code>join()</code> on the background thread.</p></li><li><p><strong>yield(): </strong>A hint to the scheduler that the current thread is willing to pause and let other threads run. However, the scheduler may ignore this hint, so its behavior is platform-dependent.  <code>Thread.yield()</code> is a static method</p></li><li><p><strong>interrupt(): </strong>Sets an internal flag that tells the thread it should stop what it&#8217;s doing&#8212;especially useful if the thread is sleeping or waiting. Many blocking methods will throw an <code>InterruptedException</code> when this flag is set.</p></li><li><p><strong>setPriority(int newPriority):</strong> Assigns a priority (from 1 to 10) to the thread. Higher-priority threads are more likely to be chosen by the scheduler, but thread priority is only a hint and may not strictly control execution order on all systems.</p></li><li><p><strong>setDaemon(boolean): </strong>Marks a thread as a daemon thread. Daemon threads run in the background (for example, for tasks like garbage collection) and do not prevent the JVM from exiting when all non-daemon threads have finished.</p></li></ol><pre><code>package com.shieldme;

public class ThreadDemo {

    static class MyThread extends Thread {
        public MyThread(String name) {
            super(name); // Sets the thread's name
        }

        @Override
        public void run() {
            System.out.println("[" + getName() + "] Starting. Priority: " + getPriority());

            // Display current thread info using currentThread()
            System.out.println("[" + Thread.currentThread().getName() + "] is running (via currentThread()).");

            // Loop to simulate work, using sleep() and yield()
            for (int i = 1; i &lt;= 5; i++) {
                System.out.println("[" + getName() + "] Loop iteration " + i);
                try {
                    Thread.sleep(500); // Pause for 500 milliseconds
                } catch (InterruptedException e) {
                    System.out.println("[" + getName() + "] Interrupted during sleep");
                    return; // Exit if interrupted
                }
                // Yield gives a hint to the scheduler to switch to another thread
                Thread.yield();
            }
            System.out.println("[" + getName() + "] Finished.");
        }
    }

    // A runnable task that demonstrates interruption.
    static class InterruptibleTask implements Runnable {
        @Override
        public void run() {
            System.out.println("[" + Thread.currentThread().getName() + "] Starting Interruptible Task");
            try {
                Thread.sleep(3000); // Sleep for 3000ms to simulate a long task.
                System.out.println("[" + Thread.currentThread().getName() + "] Completed without interruption");
            } catch (InterruptedException e) {
                System.out.println("[" + Thread.currentThread().getName() + "] Interrupted during sleep");
            }
            System.out.println("[" + Thread.currentThread().getName() + "] Task finished");
        }
    }

    public static void main(String[] args) throws InterruptedException {
        // Display main thread info using currentThread()
        System.out.println("Main thread starting. Name: " + Thread.currentThread().getName());

        // 1. Create and start a custom thread (MyThread)
        MyThread thread1 = new MyThread("Worker-1");
        thread1.setPriority(Thread.MAX_PRIORITY); // Set high priority (10)
        thread1.start();

        // 2. Create and start an interruptible thread using Runnable
        Thread thread2 = new Thread(new InterruptibleTask(), "Worker-2");
        thread2.setPriority(Thread.MIN_PRIORITY); // Set low priority (1)
        thread2.start();

        // 3. Use join() to wait for thread1 to finish
        System.out.println("Main thread waiting for " + thread1.getName() + " to finish.");
        thread1.join();
        System.out.println(thread1.getName() + " has finished. Current state: " + thread1.getState());

        // 4. Check if thread2 is alive using isAlive()
        System.out.println(thread2.getName() + " is alive: " + thread2.isAlive());

        // 5. Interrupt thread2 after a short pause (to demonstrate interrupt())
        Thread.sleep(1000);
        System.out.println("Main thread interrupting " + thread2.getName());
        thread2.interrupt();

        // Wait for thread2 to finish
        thread2.join();
        System.out.println(thread2.getName() + " has finished. Current state: " + thread2.getState());

        // 6. Create and start a daemon thread
        Thread daemonThread = new Thread(() -&gt; {
            while (true) {
                System.out.println("[" + Thread.currentThread().getName() + "] Daemon thread running in background...");
                try {
                    Thread.sleep(700);
                } catch (InterruptedException e) {
                    System.out.println("[" + Thread.currentThread().getName() + "] Daemon thread interrupted");
                    break;
                }
            }
        }, "Daemon-Thread");
        daemonThread.setDaemon(true); // Mark this thread as daemon (must be set before start)
        daemonThread.start();

        // Let the daemon run for a short period
        Thread.sleep(2000);
        System.out.println("Main thread ending. Daemon thread will terminate automatically when main finishes.");
    }
}
</code></pre><p>Output: </p><pre><code>Main thread starting. Name: main
Main thread waiting for Worker-1 to finish.
[Worker-2] Starting Interruptible Task
[Worker-1] Starting. Priority: 10
[Worker-1] is running (via currentThread()).
[Worker-1] Loop iteration 1
[Worker-1] Loop iteration 2
[Worker-1] Loop iteration 3
[Worker-1] Loop iteration 4
[Worker-1] Loop iteration 5
[Worker-1] Finished.
Worker-1 has finished. Current state: TERMINATED
Worker-2 is alive: true
[Worker-2] Completed without interruption
[Worker-2] Task finished
Main thread interrupting Worker-2
Worker-2 has finished. Current state: TERMINATED
[Daemon-Thread] Daemon thread running in background...
[Daemon-Thread] Daemon thread running in background...
[Daemon-Thread] Daemon thread running in background...
Main thread ending. Daemon thread will terminate automatically when main finishes.</code></pre><p>While creating individual threads in Java can be straightforward, there&#8217;s a better way to manage threads when you have a lot of tasks to handle. This is where <strong>thread pools</strong> come into play.</p><p>A <strong>thread pool</strong> is essentially a collection of pre-created threads that are available for use. Instead of creating a new thread each time a task needs to be executed, you can reuse threads from the pool, which can greatly improve performance, reduce overhead, and simplify thread management.</p><div><hr></div><h3>Final Thoughts</h3><p>Whether you&#8217;re just getting started or you&#8217;re an experienced software engineer, understanding multithreading is key to writing high-performance applications. From efficient task management to making the most of CPU resources, multithreading has a lot to offer. But like any tool, it&#8217;s essential to understand the underlying principles first to avoid potential pitfalls when implementing it in your code.</p><div class="pullquote"><p><em>Do you know someone who loves engineering or has a curiosity for tech? &#129300;<br>Why not share the joy of simplifying complex ideas with them? Forward this newsletter and spread the knowledge&#8212;<strong>learning is always better when it&#8217;s shared!</strong> &#128640;</em></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://codiescoder.substack.com/?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share&quot;,&quot;text&quot;:&quot;Share Codies coder&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://codiescoder.substack.com/?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share"><span>Share Codies coder</span></a></p></div>]]></content:encoded></item><item><title><![CDATA[How Does Java Really Work? Inside the JVM Architecture]]></title><description><![CDATA[Have you ever wondered what really happens when you run a Java program?&#160; How does Java go from the code you write to something your computer can actually run? And how does it manage to do all of this across different platforms with the same code? If so, you're in the right place.]]></description><link>https://codiescoder.substack.com/p/java-architecture</link><guid isPermaLink="false">https://codiescoder.substack.com/p/java-architecture</guid><dc:creator><![CDATA[Ajay Negi]]></dc:creator><pubDate>Tue, 21 Jan 2025 04:23:47 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/a9edc41f-9d3e-45b5-9eb3-f8a426a74291_12649x6647.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Have you ever wondered what really happens when you run a Java program? How does Java go from the code you write to something your computer can actually run? And how does it manage to do all of this across different platforms with the same code? If so, you're in the right place.</p><p>Java&#8217;s power lies in the Java Virtual Machine (JVM), but before we get there, let&#8217;s take a quick look at the big picture: Java has the <strong>JDK</strong> (Java Development Kit) to compile your code. The JDK contains the <strong>JRE</strong> (Java Runtime Environment), and inside the JRE is the <strong>JVM</strong>&#8212;the heart of it all.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://codiescoder.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Codies coder! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>Imagine this as a container where everything works together. First, let&#8217;s visualize how all these parts fit:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!7aRB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17d41493-eefa-4e76-bf46-de9539ff9923_1148x1011.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!7aRB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17d41493-eefa-4e76-bf46-de9539ff9923_1148x1011.png 424w, https://substackcdn.com/image/fetch/$s_!7aRB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17d41493-eefa-4e76-bf46-de9539ff9923_1148x1011.png 848w, https://substackcdn.com/image/fetch/$s_!7aRB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17d41493-eefa-4e76-bf46-de9539ff9923_1148x1011.png 1272w, https://substackcdn.com/image/fetch/$s_!7aRB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17d41493-eefa-4e76-bf46-de9539ff9923_1148x1011.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!7aRB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17d41493-eefa-4e76-bf46-de9539ff9923_1148x1011.png" width="300" height="264.198606271777" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/17d41493-eefa-4e76-bf46-de9539ff9923_1148x1011.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1011,&quot;width&quot;:1148,&quot;resizeWidth&quot;:300,&quot;bytes&quot;:76723,&quot;alt&quot;:&quot;High-level overview of JDK, JRE, and JVM inside a container&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="High-level overview of JDK, JRE, and JVM inside a container" title="High-level overview of JDK, JRE, and JVM inside a container" srcset="https://substackcdn.com/image/fetch/$s_!7aRB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17d41493-eefa-4e76-bf46-de9539ff9923_1148x1011.png 424w, https://substackcdn.com/image/fetch/$s_!7aRB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17d41493-eefa-4e76-bf46-de9539ff9923_1148x1011.png 848w, https://substackcdn.com/image/fetch/$s_!7aRB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17d41493-eefa-4e76-bf46-de9539ff9923_1148x1011.png 1272w, https://substackcdn.com/image/fetch/$s_!7aRB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17d41493-eefa-4e76-bf46-de9539ff9923_1148x1011.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><em>High-level overview of JDK, JRE, and JVM inside a container</em></figcaption></figure></div><p>At a very high level, when you write Java code, the JDK is responsible for compiling your program. The JDK has tools to convert your source code into something the JVM can understand and run. The <strong>JVM</strong> itself is the magical layer that runs Java code on any platform, maintaining the "write once, run anywhere" promise. </p><p>Now, let&#8217;s break this down step by step, and decode how each part of this process works, from writing code to running it on your machine.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!JJuO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4cefcde-21f3-43e5-a9d8-f7bb619beab4_1962x370.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!JJuO!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4cefcde-21f3-43e5-a9d8-f7bb619beab4_1962x370.png 424w, https://substackcdn.com/image/fetch/$s_!JJuO!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4cefcde-21f3-43e5-a9d8-f7bb619beab4_1962x370.png 848w, https://substackcdn.com/image/fetch/$s_!JJuO!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4cefcde-21f3-43e5-a9d8-f7bb619beab4_1962x370.png 1272w, https://substackcdn.com/image/fetch/$s_!JJuO!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4cefcde-21f3-43e5-a9d8-f7bb619beab4_1962x370.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!JJuO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4cefcde-21f3-43e5-a9d8-f7bb619beab4_1962x370.png" width="1456" height="275" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f4cefcde-21f3-43e5-a9d8-f7bb619beab4_1962x370.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:275,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:105434,&quot;alt&quot;:&quot;High-level diagram how Java source code converts into machine code&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="High-level diagram how Java source code converts into machine code" title="High-level diagram how Java source code converts into machine code" srcset="https://substackcdn.com/image/fetch/$s_!JJuO!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4cefcde-21f3-43e5-a9d8-f7bb619beab4_1962x370.png 424w, https://substackcdn.com/image/fetch/$s_!JJuO!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4cefcde-21f3-43e5-a9d8-f7bb619beab4_1962x370.png 848w, https://substackcdn.com/image/fetch/$s_!JJuO!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4cefcde-21f3-43e5-a9d8-f7bb619beab4_1962x370.png 1272w, https://substackcdn.com/image/fetch/$s_!JJuO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4cefcde-21f3-43e5-a9d8-f7bb619beab4_1962x370.png 1456w" sizes="100vw"></picture><div></div></div></a><figcaption class="image-caption"><em>High-level diagram how Java source code converts into machine code</em></figcaption></figure></div><p>Let&#8217;s break it all down into bite-sized pieces and dive deeper into each part of this fascinating architecture. Trust me, it&#8217;s not as complicated as it sounds!</p><div><hr></div><h2>1. <strong>The Java Development Kit (JDK)</strong></h2><p>Think of the <strong>JDK</strong> as the toolbox you use to write Java programs. It's where you get all the tools you need to create, compile, and run your Java applications. The JDK includes:</p><ul><li><p><strong>Compilers (javac)</strong>: This is the tool that takes your human-readable (<strong>.java)</strong> files and compiles them into bytecode (<strong>.class</strong>) files. Bytecode is an intermediate, platform-independent form of code that can be executed by the JVM on any platform.</p></li><li><p><strong>Libraries</strong>: Pre-written code that you can use in your projects. This includes everything from math functions to GUI components.</p></li><li><p><strong>Debugging Tools</strong>: To help you find and fix issues in your code.</p></li><li><p><strong>The JRE (Java Runtime Environment)</strong>: As part of the JDK, this is what you need to run your programs once they&#8217;re compiled.</p></li></ul><p>The JDK doesn't just help you write code; it&#8217;s also responsible for turning that code into something that can run on different devices and platforms.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!IRYs!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3a932da-8d33-4c5a-ba47-8801ee545aa3_740x581.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!IRYs!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3a932da-8d33-4c5a-ba47-8801ee545aa3_740x581.png 424w, https://substackcdn.com/image/fetch/$s_!IRYs!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3a932da-8d33-4c5a-ba47-8801ee545aa3_740x581.png 848w, https://substackcdn.com/image/fetch/$s_!IRYs!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3a932da-8d33-4c5a-ba47-8801ee545aa3_740x581.png 1272w, https://substackcdn.com/image/fetch/$s_!IRYs!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3a932da-8d33-4c5a-ba47-8801ee545aa3_740x581.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!IRYs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3a932da-8d33-4c5a-ba47-8801ee545aa3_740x581.png" width="372" height="292.07027027027027" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a3a932da-8d33-4c5a-ba47-8801ee545aa3_740x581.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:581,&quot;width&quot;:740,&quot;resizeWidth&quot;:372,&quot;bytes&quot;:74534,&quot;alt&quot;:&quot;High-level diagram of Java Java Development Kit  (JDK)&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="High-level diagram of Java Java Development Kit  (JDK)" title="High-level diagram of Java Java Development Kit  (JDK)" srcset="https://substackcdn.com/image/fetch/$s_!IRYs!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3a932da-8d33-4c5a-ba47-8801ee545aa3_740x581.png 424w, https://substackcdn.com/image/fetch/$s_!IRYs!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3a932da-8d33-4c5a-ba47-8801ee545aa3_740x581.png 848w, https://substackcdn.com/image/fetch/$s_!IRYs!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3a932da-8d33-4c5a-ba47-8801ee545aa3_740x581.png 1272w, https://substackcdn.com/image/fetch/$s_!IRYs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3a932da-8d33-4c5a-ba47-8801ee545aa3_740x581.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><em>High-level diagram of Java Java Development Kit  (JDK)</em></figcaption></figure></div><p>In this diagram, you can see how the JDK sits at the top, with all its tools&#8212;compilers, libraries, and the JRE&#8212;working together to help you create Java programs.</p><div><hr></div><h2>2. <strong>The Java Runtime Environment (JRE)</strong></h2><p>Once you've written and compiled your code with the JDK, it's time for the <strong>JRE</strong> to step in. The JRE is a package of software that allows you to run Java programs on your system. It contains everything needed to run Java applications, including:</p><ul><li><p><strong>The Java Class Library</strong>: A collection of pre-written classes like (java.util.ArrayList or java.io.File) that provide a wide range of functionality.</p></li><li><p><strong>Runtime Libraries:</strong> In <strong>Java 8</strong> and earlier, all core Java libraries were bundled into a single file, <strong>rt.jar</strong>, which included everything from java.lang to java.util. This monolithic approach meant that even unused libraries were loaded, which could be inefficient. Starting with <strong>Java 9</strong>, Java introduced the <strong>modular system (JPMS)</strong>, breaking the JDK into independent modules like java.base, java.sql, and java.desktop. This modularization allows for more efficient runtimes, as only the required modules are included, improving performance and reducing memory footprint. Tools like jlink let you build custom runtime images tailored to your application&#8217;s needs.</p></li><li><p><strong>The JVM</strong>: The JVM is the <strong>heart of the JRE</strong>. It&#8217;s responsible for <strong>executing</strong> the compiled Java bytecode (<code>.class</code> files). It abstracts away the details of the underlying hardware, ensuring that the same Java bytecode can run on different platforms without modification (this is why Java is known for its "Write Once, Run Anywhere" philosophy). The JVM handles memory management, garbage collection, and the execution of bytecode.</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Q2RZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98bc3b50-7cdc-423a-8e80-a666793dad0d_1974x1549.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Q2RZ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98bc3b50-7cdc-423a-8e80-a666793dad0d_1974x1549.png 424w, https://substackcdn.com/image/fetch/$s_!Q2RZ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98bc3b50-7cdc-423a-8e80-a666793dad0d_1974x1549.png 848w, https://substackcdn.com/image/fetch/$s_!Q2RZ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98bc3b50-7cdc-423a-8e80-a666793dad0d_1974x1549.png 1272w, https://substackcdn.com/image/fetch/$s_!Q2RZ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98bc3b50-7cdc-423a-8e80-a666793dad0d_1974x1549.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Q2RZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98bc3b50-7cdc-423a-8e80-a666793dad0d_1974x1549.png" width="342" height="268.4793956043956" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/98bc3b50-7cdc-423a-8e80-a666793dad0d_1974x1549.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1143,&quot;width&quot;:1456,&quot;resizeWidth&quot;:342,&quot;bytes&quot;:218122,&quot;alt&quot;:&quot;High-level diagram of Java Runtime Environment (JRE)&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="High-level diagram of Java Runtime Environment (JRE)" title="High-level diagram of Java Runtime Environment (JRE)" srcset="https://substackcdn.com/image/fetch/$s_!Q2RZ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98bc3b50-7cdc-423a-8e80-a666793dad0d_1974x1549.png 424w, https://substackcdn.com/image/fetch/$s_!Q2RZ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98bc3b50-7cdc-423a-8e80-a666793dad0d_1974x1549.png 848w, https://substackcdn.com/image/fetch/$s_!Q2RZ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98bc3b50-7cdc-423a-8e80-a666793dad0d_1974x1549.png 1272w, https://substackcdn.com/image/fetch/$s_!Q2RZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98bc3b50-7cdc-423a-8e80-a666793dad0d_1974x1549.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><em>High-level diagram of Java Runtime Environment (JRE)</em></figcaption></figure></div><p>The JRE doesn&#8217;t provide the tools to develop Java programs (those are in the JDK), but it&#8217;s essential if you just want to run the programs that someone else has written. If you install Java on your system just to run a program (like a Java-based game or a web application), you&#8217;re typically installing the JRE.</p><div><hr></div><h2>3. <strong>The Java Virtual Machine (JVM)</strong> &#8211; The Heart of Java&#8217;s Portability</h2><p>Here&#8217;s where things get really interesting. The <strong>JVM</strong> is the engine that runs Java programs. It&#8217;s responsible for interpreting the bytecode compiled by the JDK and executing it on your machine. The JVM is crucial because it allows Java to uphold its &#8220;<strong>write once</strong>, <strong>run anywhere</strong>&#8221; promise. But how does it do that?</p><p>Let&#8217;s break it down:</p><h3>a) <strong>Java Bytecode &#8211; The Intermediate Code</strong></h3><p>When you write a Java program and compile it, the output is <strong>bytecode </strong>(a low-level, platform-independent code), not machine code (which is specific to your computer's processor). This bytecode is what makes Java portable&#8212;it can be executed on any device that has a JVM. You don&#8217;t need to rewrite or recompile your code for different platforms. Here&#8217;s why:</p><ul><li><p><strong>Bytecode</strong>: Think of bytecode as a universal language. It&#8217;s like a code that doesn't belong to any specific machine. You can run it anywhere, and the JVM on that system will translate it into something the machine understands.</p></li><li><p><strong>.class Files</strong>: When you compile your Java program, the output is a <code>.class</code> file, which contains the bytecode. The JVM reads this bytecode and converts it into machine code to execute on your computer.</p></li></ul><p>This is how Java can run on virtually any device, whether it&#8217;s a Windows PC, a Linux server, or even your smartphone.</p><h3>b) <strong>Class Loaders &#8211; Bringing Classes into Memory</strong></h3><p>The JVM works by loading classes (or parts of the bytecode) into memory as needed. When you run a Java program, the JVM uses <strong>class loaders</strong> to find and load the necessary <code>.class</code> files into memory area.</p><p><strong>The Class Loader mechanism consists of three main steps as follows:</strong></p><h4>Step 1: Class Loading</h4><p>When a class is first referenced in a program, the JVM's <strong>Class Loader</strong> kicks in to load the class file into memory. This process follows a strict hierarchy of class loaders:</p><ul><li><p><strong>Bootstrap Class Loader</strong>: This is responsible for loading the core Java libraries (like java.lang.*). Before Java 8, it loaded classes from the rt.jar file, but from Java 8 onwards, it loads the java.base module as part of the new module system. This loader has the highest priority and is built into the JVM, so it can&#8217;t be customized or replaced.</p></li><li><p><strong>Extension Class Loader</strong>: This loads Java extension libraries (for example, javax.*). Before Java 8, it loaded classes from the lib/ext directory, but starting with Java 8, it now loads platform-specific modules (like java.sql, java.desktop) for backward compatibility. This loader has the second-highest priority and provides additional functionality beyond core Java.</p></li></ul><ul><li><p><strong>Application Class Loader</strong>: This loads the classes for your own Java applications, including classes from your project and any external libraries specified in the classpath (like .jar files). It&#8217;s the class loader you interact with most often when running Java programs. This loader is the lowest priority in the hierarchy, so it loads classes only after the Bootstrap and Extension Class Loaders have been checked.</p></li></ul><p>Each class loader operates in a parent-child relationship, and if a class loader cannot find a class, it delegates the task to its parent class loader. An object of this class is created in heap</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!bEve!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F148468d4-4efc-43cf-877d-a22f33221dfc_6659x2441.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bEve!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F148468d4-4efc-43cf-877d-a22f33221dfc_6659x2441.png 424w, https://substackcdn.com/image/fetch/$s_!bEve!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F148468d4-4efc-43cf-877d-a22f33221dfc_6659x2441.png 848w, https://substackcdn.com/image/fetch/$s_!bEve!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F148468d4-4efc-43cf-877d-a22f33221dfc_6659x2441.png 1272w, https://substackcdn.com/image/fetch/$s_!bEve!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F148468d4-4efc-43cf-877d-a22f33221dfc_6659x2441.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bEve!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F148468d4-4efc-43cf-877d-a22f33221dfc_6659x2441.png" width="1456" height="534" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/148468d4-4efc-43cf-877d-a22f33221dfc_6659x2441.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:534,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:966788,&quot;alt&quot;:&quot;High-level diagram of Class Loader Subsystem&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="High-level diagram of Class Loader Subsystem" title="High-level diagram of Class Loader Subsystem" srcset="https://substackcdn.com/image/fetch/$s_!bEve!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F148468d4-4efc-43cf-877d-a22f33221dfc_6659x2441.png 424w, https://substackcdn.com/image/fetch/$s_!bEve!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F148468d4-4efc-43cf-877d-a22f33221dfc_6659x2441.png 848w, https://substackcdn.com/image/fetch/$s_!bEve!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F148468d4-4efc-43cf-877d-a22f33221dfc_6659x2441.png 1272w, https://substackcdn.com/image/fetch/$s_!bEve!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F148468d4-4efc-43cf-877d-a22f33221dfc_6659x2441.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><em>High-level diagram of Class Loader Subsystem</em></figcaption></figure></div><h4>Step 2: Linking</h4><p>Once a class is loaded, it's <strong>linked</strong> into the JVM. Linking is a multi-stage process that prepares the class for use:</p><ul><li><p><strong>Verification</strong>: Ensures that the bytecode is valid and adheres to the JVM's specification. This step checks that the bytecode does not violate any rules that might make it unsafe to execute (such as accessing memory in unauthorized ways). If the bytecode doesn't pass verification, the JVM throws a VerifyError.</p></li><li><p><strong>Preparation</strong>: This step allocates memory for static variables and initializes them to their default values (like null for objects, 0 for integers, etc.). It doesn't assign the values specified in the source code&#8212;just the defaults. If there are issues here, like trying to allocate memory for invalid static variables, the JVM might throw a NoClassDefFoundError or NullPointerException, depending on the nature of the problem.</p></li><li><p><strong>Resolution</strong>: This stage resolves symbolic references (like class or method names) into actual references to memory locations. For example, if a class calls a method in another class, the JVM resolves the method reference and links it to the actual method's memory address. This ensures that when the class is actually executed, all method calls and references are mapped correctly. If a symbolic reference cannot be resolved (for example, if a method or class is not found), the JVM may throw a NoSuchMethodError or ClassNotFoundException.</p></li></ul><p>If any issues are found during the Verification stage, the JVM will throw an exception to stop the class from being used. This ensures that your program won't run with faulty or malicious code. For example, if a class file is altered or corrupted&#8212;perhaps by malware or a malicious actor&#8212;the JVM&#8217;s <strong>bytecode verifier</strong> can detect these changes. If it finds something suspicious or unsafe, it will throw a VerifyError (also known as a '<strong>verify exception</strong>'). This exception helps prevent the execution of compromised or harmful code, safeguarding your application and system.</p><h4>Step 3: Initialization</h4><p>Initialization is the final step before a class is ready to be used in your program. Imagine you&#8217;ve bought a new piece of furniture&#8212;before you can sit on it, it needs to be assembled and positioned in your living room. Similarly, initialization is where the class gets "assembled" and its parts (variables, static blocks) are set up.</p><p>It&#8217;s the moment when Java makes sure everything inside the class is properly initialized and ready for action. But what exactly happens in this step?</p><ul><li><p><strong>Assigns Values to Static Variables</strong>: Static variables are shared by all instances of a class, so they need to be set up before anything else. During initialization, Java assigns them the actual values defined in the class.</p></li><li><p><strong>Executes Static Blocks</strong>: If your class contains a static block (a special piece of code inside static <code>{}</code>), it gets executed now. Static blocks run only once, the first time the class is accessed. This is where you can set up things that need to be done just once&#8212;like initializing complex static variables or connecting to a database.</p></li><li><p><strong>Assigns Values to Instance Variables</strong>: While instance variables are assigned default values during class loading (e.g., null, 0, etc.), this is the point where they get their real values, either from the constructor or from any static blocks that are part of the class. </p></li></ul><p>Java doesn&#8217;t just initialize a class randomly&#8212;it waits until you actually use it. Here are the six situations that trigger class initialization:</p><ol><li><p>Using the new Keyword</p></li><li><p>Calling a Static Method</p></li><li><p>Assigning a Value to Static Fields</p></li><li><p>Explicit Class Initialization</p></li><li><p>Using Reflection</p></li><li><p>Creating an Instance of a Subclass</p></li></ol><h3>c) <strong>Runtime Data Area &#8211; The Brain of the JVM</strong></h3><p>When you run a Java program, the <strong>Runtime Data Area</strong> is where all the important data lives during the execution of your program. It&#8217;s like the workspace of the JVM, where it holds the data and provides resources that your program needs.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!jI4t!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7212eda-3b5d-4c0e-b653-e4cf798505ce_3286x1401.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jI4t!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7212eda-3b5d-4c0e-b653-e4cf798505ce_3286x1401.png 424w, https://substackcdn.com/image/fetch/$s_!jI4t!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7212eda-3b5d-4c0e-b653-e4cf798505ce_3286x1401.png 848w, https://substackcdn.com/image/fetch/$s_!jI4t!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7212eda-3b5d-4c0e-b653-e4cf798505ce_3286x1401.png 1272w, https://substackcdn.com/image/fetch/$s_!jI4t!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7212eda-3b5d-4c0e-b653-e4cf798505ce_3286x1401.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jI4t!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7212eda-3b5d-4c0e-b653-e4cf798505ce_3286x1401.png" width="1456" height="621" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b7212eda-3b5d-4c0e-b653-e4cf798505ce_3286x1401.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:621,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:459588,&quot;alt&quot;:&quot;Runtime Data Area &#8211; The Brain of the JVM&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Runtime Data Area &#8211; The Brain of the JVM" title="Runtime Data Area &#8211; The Brain of the JVM" srcset="https://substackcdn.com/image/fetch/$s_!jI4t!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7212eda-3b5d-4c0e-b653-e4cf798505ce_3286x1401.png 424w, https://substackcdn.com/image/fetch/$s_!jI4t!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7212eda-3b5d-4c0e-b653-e4cf798505ce_3286x1401.png 848w, https://substackcdn.com/image/fetch/$s_!jI4t!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7212eda-3b5d-4c0e-b653-e4cf798505ce_3286x1401.png 1272w, https://substackcdn.com/image/fetch/$s_!jI4t!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7212eda-3b5d-4c0e-b653-e4cf798505ce_3286x1401.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><em>Runtime Data Area &#8211; The Brain of the JVM</em></figcaption></figure></div><p>This area is divided into five main parts, each serving a specific purpose.</p><h4><strong>1. Method Area: Where Class-Level Information Lives</strong></h4><p>The <strong>Method Area</strong> is a shared resource across all threads in the JVM. It holds important information about the class, including:</p><ul><li><p><strong>Class-level metadata</strong> (class name, superclass, etc.)</p></li><li><p><strong>Method and field data</strong> (method names, parameter types, return types, etc.)</p></li><li><p><strong>Runtime Constant Pool</strong> (constants, literals, references to other classes or methods)</p></li><li><p><strong>Constructors</strong> and <strong>method bytecodes</strong> (for both instance and static methods)</p></li></ul><p>Since the <strong>Method Area</strong> is shared among all threads, it&#8217;s critical to manage it carefully to avoid memory contention or leaks. If the JVM can't allocate memory here due to excessive class loading or other factors, it throws an OutOfMemoryError.</p><h4><strong>2. Heap Area: The Home for Objects</strong></h4><p>The <strong>Heap Area</strong> is shared across all threads and serves as the runtime data area from which memory for all class instances and arrays is allocated.</p><p>The JVM uses an automatic garbage collector to manage memory in the heap. The <strong>garbage collector</strong> reclaims memory used by objects that are no longer needed, ensuring that your application doesn&#8217;t run out of memory.</p><p>Key things to note:</p><ul><li><p>The <strong>Heap</strong> can be dynamically resized during runtime based on the application's needs. However, if the JVM can't allocate sufficient memory, it throws an OutOfMemoryError.</p></li><li><p>Heap memory can be managed with various garbage collection strategies, like <strong>Mark-and-Sweep</strong>, <strong>Generational GC</strong>, etc., to optimize performance.</p></li></ul><h4><strong>3. Stack Area: The Thread&#8217;s Personal Workspace</strong></h4><p>Each thread in the JVM gets its own <strong>Stack Area</strong>. The stack is crucial for managing method invocations and local variables, and it uses a <strong>Last-In-First-Out (LIFO)</strong> structure to store data.</p><p>Key parts of the <strong>Stack Area</strong>:</p><ul><li><p><strong>Stack Frames</strong>: Each method invocation creates a stack frame. This frame stores:</p><ul><li><p><strong>Local variables</strong></p></li><li><p><strong>Operand stack</strong> (used for intermediate computations)</p></li><li><p><strong>Frame data</strong> (method data, exception handling info, etc.)</p></li></ul></li></ul><p>The <strong>Stack</strong> is thread-safe because each thread has its own stack. However, if a thread&#8217;s stack grows too large (for example, due to deep recursion), the JVM will throw a StackOverflowError. If the system can&#8217;t allocate enough memory for a new stack, it will throw an OutOfMemoryError.</p><h4><strong>4. Program Counter (PC) Register: The Instruction Pointer</strong></h4><p>Each thread in the JVM has its own <strong>Program Counter (PC) Register</strong>, which holds the address of the currently executing instruction. The JVM uses this to fetch the next instruction to execute.</p><ul><li><p>For <strong>native methods</strong>, the PC Register&#8217;s value is undefined, as native methods are executed outside of the JVM&#8217;s bytecode.</p></li><li><p>The <strong>PC Register</strong> is critical for managing the execution flow in multithreaded programs and ensures that each thread maintains its own execution context.</p></li></ul><h4><strong>5. Native Method Stack: Supporting Native Code</strong></h4><p>The <strong>Native Method Stack</strong> is used for managing native method invocations, which are methods written in languages like C or C++. Each thread gets a separate stack for native method calls.</p><ul><li><p>Native methods are often used for <strong>performance optimizations</strong> or <strong>low-level system interactions</strong> (such as file I/O or network communication).</p></li><li><p>This stack stores all the information related to the native method call, and it interacts with the <strong>JVM stack</strong> for managing data between Java and native code.</p></li></ul><h3><strong>d) The Execution Engine &#8211; Running Bytecode</strong></h3><p>Once the bytecode is loaded into memory, the <strong>execution engine</strong> kicks in. It&#8217;s responsible for reading and executing the bytecode instructions one by one. The JVM uses three main methods to do this:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Jzgn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64cdb2a0-e987-4321-a58e-96db24a1e0f3_4333x532.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Jzgn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64cdb2a0-e987-4321-a58e-96db24a1e0f3_4333x532.png 424w, https://substackcdn.com/image/fetch/$s_!Jzgn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64cdb2a0-e987-4321-a58e-96db24a1e0f3_4333x532.png 848w, https://substackcdn.com/image/fetch/$s_!Jzgn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64cdb2a0-e987-4321-a58e-96db24a1e0f3_4333x532.png 1272w, https://substackcdn.com/image/fetch/$s_!Jzgn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64cdb2a0-e987-4321-a58e-96db24a1e0f3_4333x532.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Jzgn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64cdb2a0-e987-4321-a58e-96db24a1e0f3_4333x532.png" width="1456" height="179" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/64cdb2a0-e987-4321-a58e-96db24a1e0f3_4333x532.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:179,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:234314,&quot;alt&quot;:&quot;High-level diagram of The Execution Engine (JVM)&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="High-level diagram of The Execution Engine (JVM)" title="High-level diagram of The Execution Engine (JVM)" srcset="https://substackcdn.com/image/fetch/$s_!Jzgn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64cdb2a0-e987-4321-a58e-96db24a1e0f3_4333x532.png 424w, https://substackcdn.com/image/fetch/$s_!Jzgn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64cdb2a0-e987-4321-a58e-96db24a1e0f3_4333x532.png 848w, https://substackcdn.com/image/fetch/$s_!Jzgn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64cdb2a0-e987-4321-a58e-96db24a1e0f3_4333x532.png 1272w, https://substackcdn.com/image/fetch/$s_!Jzgn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64cdb2a0-e987-4321-a58e-96db24a1e0f3_4333x532.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"><em>High-level diagram of The Execution Engine (JVM)</em></figcaption></figure></div><ul><li><p><strong>Interpretation</strong>: The JVM reads and executes the bytecode line by line, which is efficient for small programs but can be slow for large, complex applications.</p></li><li><p><strong>Just-In-Time (JIT) Compilation</strong>: To boost performance, the JVM uses <strong>JIT compilers</strong>. The JVM tracks which methods are called frequently (hotspots). Once a method reaches a threshold of calls, the JIT compiler compiles it into machine code. This allows future calls to execute faster without needing interpretation. Some JIT compilers can re-optimize code if methods continue to be called frequently, ensuring further performance gains. Those methods that are repeated, JIT provides direct machine code, so re-interpretation is not required.</p></li><li><p><strong>Garbage Collection: </strong>One of the most significant features of the JVM is <strong>automatic memory management</strong>. In many languages, you need to manually allocate and free memory, which can lead to memory leaks and bugs. In Java, however, the JVM takes care of this for you using <strong>garbage collection</strong>. Garbage collection is the process where the JVM automatically identifies and removes objects from memory that are no longer in use, freeing up resources without you having to worry about it. It makes Java easier to work with, especially for beginners, because you don&#8217;t need to manually manage memory allocation.</p></li></ul><h3>e) Java Native Interface (JNI)</h3><ul><li><p><strong>Function</strong>: Allows Java to interact with <strong>native code</strong> (e.g., C/C++ libraries) for tasks that require direct hardware access or OS-specific operations.</p></li><li><p><strong>How it works</strong>: JNI acts as a bridge, letting Java call native libraries and vice versa.</p></li><li><p><strong>Why it matters</strong>: JNI is crucial for performance-critical operations, such as optimizing I/O or using existing system libraries, but it introduces complexity as Java loses its cross-platform advantage when using native code.</p></li></ul><h3>f) <strong>Native Method Libraries</strong></h3><ul><li><p><strong>Function</strong>: Collections of native code (C/C++) required by the JVM for interacting with lower-level system resources.</p></li><li><p><strong>How it works</strong>: These libraries are accessed via JNI, allowing the JVM to utilize OS-specific functionality, hardware operations, or external libraries.</p></li></ul><div><hr></div><h2><strong>Platform Independence &#8211; The Magic of the JVM</strong></h2><p>The JVM is what enables Java&#8217;s famous "write once, run anywhere" feature. Since the JVM exists for every major operating system (Windows, macOS, Linux, etc.), the same Java bytecode can be executed on any platform without modification. The JVM abstracts away the underlying hardware and operating system, meaning that Java code can run on any device or server as long as the appropriate JVM is available.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Empn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F114dbbf0-a5c0-49fb-9c81-b92250e253a6_5235x3714.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Empn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F114dbbf0-a5c0-49fb-9c81-b92250e253a6_5235x3714.png 424w, https://substackcdn.com/image/fetch/$s_!Empn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F114dbbf0-a5c0-49fb-9c81-b92250e253a6_5235x3714.png 848w, https://substackcdn.com/image/fetch/$s_!Empn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F114dbbf0-a5c0-49fb-9c81-b92250e253a6_5235x3714.png 1272w, https://substackcdn.com/image/fetch/$s_!Empn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F114dbbf0-a5c0-49fb-9c81-b92250e253a6_5235x3714.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Empn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F114dbbf0-a5c0-49fb-9c81-b92250e253a6_5235x3714.png" width="728" height="516.5" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/114dbbf0-a5c0-49fb-9c81-b92250e253a6_5235x3714.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:1033,&quot;width&quot;:1456,&quot;resizeWidth&quot;:728,&quot;bytes&quot;:1664246,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Empn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F114dbbf0-a5c0-49fb-9c81-b92250e253a6_5235x3714.png 424w, https://substackcdn.com/image/fetch/$s_!Empn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F114dbbf0-a5c0-49fb-9c81-b92250e253a6_5235x3714.png 848w, https://substackcdn.com/image/fetch/$s_!Empn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F114dbbf0-a5c0-49fb-9c81-b92250e253a6_5235x3714.png 1272w, https://substackcdn.com/image/fetch/$s_!Empn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F114dbbf0-a5c0-49fb-9c81-b92250e253a6_5235x3714.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3>Final Thoughts</h3><p>Java&#8217;s architecture may seem complex at first, but once you break it down, it&#8217;s a beautifully engineered system designed to run code efficiently across different platforms. The combination of the JDK, JRE, and JVM allows Java to be both powerful and portable. As you write and run Java code, remember that you&#8217;re taking advantage of a well-oiled machine&#8212;one that has been refined over decades to ensure consistency and reliability.</p><p>So next time you write some Java code, you&#8217;ll know exactly what&#8217;s happening under the hood: how the JDK compiles your program, how the JRE gets it ready to run, and how the JVM executes it seamlessly across platforms. Pretty cool, right?</p><p>Happy coding, and remember: Java&#8217;s <strong>"write once, run anywhere" mantra</strong> isn&#8217;t just a slogan&#8212;it&#8217;s the magic of the JVM in action.</p><p></p><div class="pullquote"><p><em>Do you know someone who loves engineering or has a curiosity for tech? &#129300;<br>Why not share the joy of simplifying complex ideas with them? Forward this newsletter and spread the knowledge&#8212;<strong>learning is always better when it&#8217;s shared!</strong> &#128640; </em></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://codiescoder.substack.com/?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share&quot;,&quot;text&quot;:&quot;Share Codies coder&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://codiescoder.substack.com/?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share"><span>Share Codies coder</span></a></p></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://codiescoder.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Codies coder! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Coming soon]]></title><description><![CDATA[This is Codies Coder Newsletter.]]></description><link>https://codiescoder.substack.com/p/coming-soon</link><guid isPermaLink="false">https://codiescoder.substack.com/p/coming-soon</guid><dc:creator><![CDATA[Ajay Negi]]></dc:creator><pubDate>Thu, 09 Jan 2025 18:12:33 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!vCfG!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff574545e-ca46-4752-8376-f6508575c6ec_96x96.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This is Codies Coder Newsletter.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://codiescoder.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://codiescoder.substack.com/subscribe?"><span>Subscribe now</span></a></p>]]></content:encoded></item></channel></rss>