Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Basics Getting Started with Java Introduction to Your Tools

Adam Brown
Adam Brown
1,893 Points

Public Class Name

I notice that the public class <name> has to be the same name as the java file. Why is this?

1 Answer

Jon Kussmann
PLUS
Jon Kussmann
Courses Plus Student 7,254 Points

Hi Adam,

It's rule that the creators of Java decided on. I imagine it helps with finding classes more easily... if file names and class names were different and you wanted to make a new object from say the "House" class, you'd have to search every single one of your file names to find the "House" class instead of just going to the "House" file directly.