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

Constants and Final?

Hello-

As explained in the video, constants are values that can never change. Later in the video, we were introduced to the 'final' keyword that prevents your code from being changed.

Why cant we just use the 'final' keyword instead of using constants when writing something that can't and shouldn't be changed? Do constants and 'final' do the same thing?

Help is appreciated!

1 Answer

Rick Buffington
Rick Buffington
8,146 Points

To my knowledge, a constant is the concept of what the "final" keyword performs. There is a "const" keyword in Java, but it is not used. So essentially, when you label a variable with final, you are creating a constant.

Okay! Thanks!