• Skip to main content
  • Skip to primary sidebar

Founder at work

Master the skills to create and launch your next SaaS company

  • About Me
  • Reviews
  • Resources
  • Community
  • Contact
  • Lessons
  • Series
  • Search
  • Login

what is a constant?

September 20, 2012 by Rick Hernandez Leave a Comment

Constants are very much like a variable in java. It’s a placeholder in memory that holds a value that is assigned to it  but the twist here is that the value will never be changed.  Example of a constant in java.

class example
{
    public static void main (String[]args)
  {
   int number1 = 2;
   final int FOOO = 100;
   System.out.println("The complete answer is" + (number1 + FOOO));
  }
}

by convention in java constants tend to be all in capital letters. For example FOO is the the constant that I used as i would if it was a variable by adding it to the int number1.

So when will you ever see a constant?
A rule of thumb for this is if you find your self declaring a set of variables that are never changing more than likely they should be constants.

Rick Hernandez

I always had a passion for the field of STEM (Science, Technology, Engineering, and Math) and I knew I wanted to do something to make a difference in the world. I just didn’t know where to start. I was an immigrant in a new country, grew up in a tough environment, and wasn’t sure how… Read More

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)

Related

Filed Under: Java, Programming

Primary Sidebar

Learn How To Take Your Idea And Convert It Into An App From Scratch Even If You Have Never Written A Single Line Of Code.

  • How to Find Your Next Great App Idea
  • The Secret To Getting PAID To Build Your Own App
  • How To Create Your App (SaaS, Mobile, VR, AR, Game)
  • How To Monetize Your Apps
Learn More
4.82 Ratings

Copyright © 2025 · JSecademy Blog Theme on Genesis Framework · WordPress · Log in