---
title: "Discussion on \"Why the filename must match the public class name\" | Hashnode"
description: "Discussion on \"Why the filename must match the public class name\". The Java compiler and JVM need a clear way to find and load the correct class.When a class is declared as public, it means it can be used by any other class or program.So Java expects that:\n\nThe public class name and the file name are the same.\n\nThis..."
url: "https://hashnode.com/posts/why-the-filename-must-match-the-public-class-name/68ee67a0cf15a7a78d6f8eb3"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Why the filename must match the public class name](https://javawithshritej.hashnode.dev/why-the-filename-must-match-the-public-class-name?utm_source=hashnode&utm_medium=feed)

The Java compiler and JVM need a clear way to find and load the correct class.When a class is declared as public, it means it can be used by any other class or program.So Java expects that: The public class name and the file name are the same. This...

Oct 14, 2025 · 2 min read · javawithshritej.hashnode.dev  
Read the article

-   [#java](https://hashnode.com/tag/java)
-   [#core-java](https://hashnode.com/tag/core-java)
-   [#public-class](https://hashnode.com/tag/public-class)
-   [#java-class](https://hashnode.com/tag/java-class)

## Written by

[Shritej Chavan](https://hashnode.com/@shritej-chavan-05)

@shritej-chavan-05

  
[View profile](https://hashnode.com/@shritej-chavan-05)

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
