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 Objects (Retired) Harnessing the Power of Objects Methods and Constants

Why is the Main class a void return-type?

For example:

System.out.println("Hello");

This would return Hello world (In the right context) so it actually does return something if I got this right. Or isn't printing actually returning?

2 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Yassin;

Welcome to Treehouse!

If one thinks about what main is doing it might make more sense. A main function is what gets called when we run a program, right? For example, if we were to do java example.java we would be running the main function inside of our example.java file. We can certainly do interactive things like take input from a user or print information out, but the concept of "returning" something to the operating system is a bit nebulous. The only real "return value" that exists is something like a System.exit(int) method that could return an exit status code.

You can take a look at the language specification for more details.

Happy coding,
Ken

Thank you very much for your answer Ken! Clears things up for me.

All the best, Yassin

I am currently testing Treehouse but I absolutely love it and will get a membership. Thanks for your great service, even for a test version user.