惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Heimdal Security Blog
P
Privacy International News Feed
S
Schneier on Security
P
Proofpoint News Feed
L
Lohrmann on Cybersecurity
Spread Privacy
Spread Privacy
P
Privacy & Cybersecurity Law Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Scott Helme
Scott Helme
K
Kaspersky official blog
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
aimingoo的专栏
aimingoo的专栏
Simon Willison's Weblog
Simon Willison's Weblog
S
Securelist
Help Net Security
Help Net Security
B
Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Security Archives - TechRepublic
Security Archives - TechRepublic
云风的 BLOG
云风的 BLOG
The GitHub Blog
The GitHub Blog
N
News and Events Feed by Topic
Hacker News: Ask HN
Hacker News: Ask HN
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
M
MIT News - Artificial intelligence
雷峰网
雷峰网
博客园 - 司徒正美
V
V2EX
AWS News Blog
AWS News Blog
Know Your Adversary
Know Your Adversary
N
News | PayPal Newsroom
T
Tor Project blog
Cisco Talos Blog
Cisco Talos Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
PCI Perspectives
PCI Perspectives
Google DeepMind News
Google DeepMind News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
U
Unit 42
C
Cybersecurity and Infrastructure Security Agency CISA
P
Palo Alto Networks Blog
G
Google Developers Blog
T
Threat Research - Cisco Blogs
博客园 - Franky
I
InfoQ
D
DataBreaches.Net
爱范儿
爱范儿
Y
Y Combinator Blog
博客园 - 叶小钗
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Static vs Non-Static in Java: Understanding Class and Object Through a Shop Story
Kathirvel S · 2026-05-31 · via DEV Community

Imagine You're Standing Outside a Shop...

Have you ever noticed something interesting when you walk past a shop?

Even before entering, you can see the shop's name board.

"Fresh Mart"

You don't need to enter the shop to know its name. It's visible to everyone from outside.

But what about the products?

Can you see all the products from outside?

No.

To access products, you must enter the shop.

Now let's connect this simple real-world example to Java.


Meet Our Java Shop

Imagine this Java class:

public class Shop {

    static int age = 20;
    static String name = "Fresh Mart";

    String prod_name;
}

Think of it this way:

Shop Story Java Concept
Shop building Class
Shop name board Static variable
Product inside shop Non-static variable
Entering the shop Creating an object

What Is a Class?

According to the Java documentation:

A class is a blueprint or template from which objects are created.

In simple words:

A class describes what something should look like.

For example:

public class Shop {
    static String name;
    String prod_name;
}

This does not create an actual shop.

It only describes:

  • A shop has a name.
  • A shop can contain products.

Think of it like an architect's building plan.

A plan is not the actual building.

Similarly:

A class is not an object.

It is only the blueprint.

Think of a class as:

Recipe
Template
Blueprint
Design
Instruction Sheet


Why Do We Need Classes?

Imagine a city with 10,000 shops.

Would you write separate code for every shop?

shop1
shop2
shop3
shop4
...

That would be a nightmare.

Instead, we create one blueprint:

class Shop

And then create many shop objects from it.

Benefits:

✅ Reusability

✅ Better organization

✅ Less code duplication

✅ Easier maintenance


What Is an Object?

If a class is the blueprint...

An object is the real thing created from that blueprint.

Example:

Blueprint:

House Design

Actual house:

House #1
House #2
House #3

Similarly:

Class:

Shop

Objects:

Shop s1 = new Shop();

Shop s2 = new Shop();

Now we have two real shop objects.

Each object gets its own storage.


Why Do We Need Objects?

Imagine there are 10,000 shops.

Would we create 10,000 classes?

Shop1
Shop2
Shop3
Shop4
...

❌ Impossible to maintain.

Instead:

class Shop

One class.

Many objects.

Shop s1 = new Shop();

Shop s2 = new Shop();

Shop s3 = new Shop();

Advantages:

✅ Reusable

✅ Organized

✅ Saves code

✅ Models real-world entities


The Most Important Line in Java

Look carefully:

Shop s1 = new Shop();

Most beginners see one line.

Java sees several steps.

Let's break it apart.


Step 1: Shop

Shop

This is the class type.

It tells Java:

"The variable I'm about to create will store a Shop object."

Similar to:

int age;
String name;

Here:

Shop s1;

means:

s1 can store a Shop reference.


Step 2: s1

Shop s1;

s1 is a reference variable.

Think of it as:

Address Holder
Pointer
Reference
Remote Control

Initially:

s1
 |
 v
null

No object exists yet.


Step 3: new

new

This is where the magic happens.

new tells Java:

"Allocate memory and create a brand new object."

Without new:

Shop s1;

No shop is created.

With new:

new Shop();

Java creates a fresh object in memory.


Step 4: Shop()

Shop()

This calls the constructor.

Think of it as:

Opening a new shop
Initializing the shop
Preparing the shop

Java creates memory and prepares all variables.


What Happens Internally?

When Java sees:

Shop s1 = new Shop();

Java roughly performs:

Create memory

Memory

+----------------+
| prod_name=null |
+----------------+

Then:

Store address in s1

s1
 |
 |-------> Object
           +----------------+
           | prod_name=null |
           +----------------+


Creating Another Object

Shop s2 = new Shop();

Now Java allocates another memory block.

s1
 |
 v
+----------------+
| prod_name=null |
+----------------+

s2
 |
 v
+----------------+
| prod_name=null |
+----------------+

Notice:

These are two separate objects.

Separate memory.

Separate data.


What Happens After Assignments?

s1.prod_name = "Rice";

s2.prod_name = "Milk";

Memory becomes:

s1
 |
 v
+----------------+
| prod_name=Rice |
+----------------+

s2
 |
 v
+----------------+
| prod_name=Milk |
+----------------+

Each object stores its own value.


Where Does Static Memory Live?

Consider:

public class Shop {

    static String name = "Fresh Mart";

    String prod_name;
}

Many beginners think:

Every object stores name.

Wrong.

Static variables are stored once per class.


Visual Memory Layout

CLASS AREA (Method Area)

Shop Class
+-----------------------+
| name = Fresh Mart     |
+-----------------------+



HEAP MEMORY

Object s1
+-----------------------+
| prod_name = Rice      |
+-----------------------+

Object s2
+-----------------------+
| prod_name = Milk      |
+-----------------------+

Only one copy of:

static String name

exists.

No matter how many objects you create.


Why Static Saves Memory

Imagine:

Shop s1
Shop s2
Shop s3
...
Shop s1000

If name were non-static:

Fresh Mart
Fresh Mart
Fresh Mart
Fresh Mart
...
1000 times

Huge waste.

Instead:

static String name

One copy.

All objects share it.

             Fresh Mart
                 ^
                 |
      -------------------------
      |           |           |
     s1          s2          s3


Static vs Non-Static Memory Diagram

CLASS AREA

+--------------------------------+
| Shop.name = Fresh Mart         |
| Shop.age  = 20                 |
+--------------------------------+



HEAP

s1
 |
 v
+--------------------------------+
| prod_name = Rice               |
+--------------------------------+


s2
 |
 v
+--------------------------------+
| prod_name = Milk               |
+--------------------------------+


What Is Static?

Remember the shop name board?

Everyone can see it without entering the shop.

That's exactly how static members work.

Example:

static String name = "Fresh Mart";

You can access it directly through the class:

System.out.println(Shop.name);

No object required.

Because static belongs to the class itself.


Why Static Exists

Imagine there are 1,000 shop objects.

Should every object store the same shop name?

That wastes memory.

Instead:

static String name = "Fresh Mart";

Only one copy exists.

All objects share it.

Benefits:

✅ Memory efficient

✅ Faster access

✅ Shared information


What Is Non-Static?

Products inside the shop are different.

One shelf contains:

Rice

Another shelf contains:

Milk

Each shop object stores its own products.

Example:

String prod_name;

This is non-static.

Every object gets its own copy.

Access:

product.prod_name

Not:

Shop.prod_name

Because the product belongs to a specific shop object.


Static vs Non-Static

Static Non-Static
Belongs to class Belongs to object
One copy exists Separate copy per object
Access using class name Access using object
Memory efficient Stores object-specific data
Created when class loads Created when object is created

Code to the Story

public class Shop {

    // Visible from outside
    static int age = 20;
    static String name = "Fresh Mart";

    // Inside the shop
    String prod_name;

    public static void main(String[] args) {

        Shop product = new Shop();
        product.prod_name = "First Product";

        Shop product2 = new Shop();
        product2.prod_name = "Second Product";

        System.out.println("=== Looking from outside ===");

        System.out.println("Shop Age: " + Shop.age);
        System.out.println("Shop Name: " + Shop.name);



        System.out.println("=== Entering Shop ===");

        System.out.println(product.prod_name);
        System.out.println(product2.prod_name);
    }
}

Output:

=== Looking from outside ===
Shop Age: 20
Shop Name: Fresh Mart

=== Entering Shop ===
First Product
Second Product

See the difference?

Outside:

Shop.age
Shop.name

Inside:

product.prod_name
product2.prod_name


How to Print Static Variables

Static variables belong to the class.

System.out.println(Shop.age);
System.out.println(Shop.name);

Output:

20
Fresh Mart


How to Print Non-Static Variables

Create an object first.

Shop product = new Shop();

product.prod_name = "Laptop";

System.out.println(product.prod_name);

Output:

Laptop


When Should You Use Static?

Use static when data is shared by all objects.

Examples:

Company Name
Tax Rate
Application Version
Counter
Constants
Utility Methods

Example:

static String company = "ABC Ltd";

Every employee object uses the same company name.


When Should You Use Non-Static?

Use non-static when every object needs its own value.

Examples:

Student Name
Employee Salary
Car Number
Product Name
Account Balance

Example:

String studentName;

Every student has a different name.


Where Are These Memories Stored in JVM?

Think of the JVM as having three important areas.

Stack Memory

Stores:

s1
s2
product
product2

Reference variables live here.

STACK

s1 ------+
s2 ------+


Heap Memory

Stores actual objects.

HEAP

Object 1
Object 2
Object 3

Whenever you write:

new Shop();

Memory is allocated in the Heap.


Method Area (Class Area)

Stores:

Class metadata
Static variables
Static methods

Example:

static String name;
static int age;

These are stored once in the Method Area.

METHOD AREA

Shop.name
Shop.age


Complete JVM Memory Picture

METHOD AREA
+-------------------------+
| Shop.name = Fresh Mart  |
| Shop.age  = 20          |
+-------------------------+


STACK
+-------------------------+
| s1 -> Object1           |
| s2 -> Object2           |
+-------------------------+


HEAP
+-------------------------+
| Object1                 |
| prod_name = Rice        |
+-------------------------+

+-------------------------+
| Object2                 |
| prod_name = Milk        |
+-------------------------+

Now you can actually visualize what happens when Java executes:

Shop s1 = new Shop();


Quick Challenge For You

Before reading the answer, guess the output:

public class Shop {

    static String name = "Fresh Mart";

    String product;

    public static void main(String[] args) {

        Shop s1 = new Shop();
        Shop s2 = new Shop();

        s1.product = "Rice";
        s2.product = "Milk";

        System.out.println(name);

        System.out.println(s1.product);

        System.out.println(s2.product);
    }
}

Think...

Think...

Ready?

Output:

Fresh Mart
Rice
Milk

Why?

Because:

  • name is shared by the class.
  • product belongs to each object separately.

Final Takeaway

Whenever you're confused between static and non-static, remember the shop story.

Shop Name Board = Static

Everyone can access it without entering.

Products Inside the Shop = Non-Static

You must enter a specific shop object to access them.

And remember:

  • Class = Blueprint
  • Object = Real thing created from the blueprint
  • Static = Shared by everyone
  • Non-Static = Unique to each object

Whenever you see:

Shop s1 = new Shop();

Read it like this:

Shop      -> Type of object

s1        -> Reference variable

new       -> Allocate new memory

Shop()    -> Create and initialize object

Visualize:

s1
 |
 v
+------------------+
| Shop Object      |
+------------------+

Once you understand this memory picture, static vs non-static stops being something to memorize and becomes something you can actually see happening inside the JVM.

References

Official Java Documentation: