Skip to content

Variables

Alex E edited this page Jan 1, 2019 · 1 revision

Variables

Wiki Home

Licensing

What is a variable?

A variable is considered to be a place in memory and is a to store information in. Computers allow users to store thousands of these containers in a single program. We can assign multiple forms information to these containers, such as giving it a name. For example, a wanted to calculate a user's current age based on the date they'd need to use variables. The computer would need someplace to store all this different information, this is where variables come into play. Without the ability to store information the computers process anything.

How do you create a variable?

To create a variable we need to define their data type, assign a name to it, and define a value to it. One of the most basic data types is an int which is short for integer. Let's break it down, even more, an int is a data type which tells java to that we need to assign a container or an area of memory to store this information (In this case our integer or item) After that we define our variable name myFirstNumber, which gives our program something to call this. This is then followed by a equal sign (=) and a number next to the end. This tells our int that we'd like to assign the value of 5 to it. (But keep in mind variables are flexible and we can assign numbers to this)

Integers are not limited to one singular number. You are able to create longer or more difficult equations. Ex. 10 + 2 * (5 - 2)

Input

int myFirstNumber = 5;
System.out.println(myFirstNumber); // We're telling Java to print the variable we created

Outcome

5

Clone this wiki locally