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.
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