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 Classes, Objects, Constructor...

Why do we have to create java classes, constructor in a different java file?

1 Answer

Java is object oriented. The idea is to create modular code that you can reuse so we create classes for certain tasks/objects. We do this is separate files to organize our code, because once you get into large assignments and have 8,000+ lines of code in each class it will become difficult to find things. Constructors are a way of creating objects from those classes.

Take more courses, even the Java track, and you will begin to understand the differences. Take another language (non object oriented) like c and you will appreciate classes. Note I said "c" and not c++, or c#.