Lets Talk About Variables. What Are They, How To Use Them.In JAVA

define variables in java

Lets Talk About Variables. What Are They, How To Use Them.In JAVA

Table of contents

No heading

No headings in the article.

So What Are the variables

  • Variables are way to store information in computer
  • Variables that we defined in java program can be accessed
  • by name what we give them
  • And Computers does some processes of figuring out where they get stored
  • in memory which is called as RAM (Random access memory)

A Variable is name suggests it can be changed, or what we can do we can tell the computer what type of information we want to store in variables and we can give them some name.

There are lots of type of variable we can defined for our variables, this are know as data types data types are Keyword in java.

Data Types

Lets Talked about data types

int data type :- int is a keyword in java and int is a short-form of Integer data types its mean a complete number which doesn't have any decimal points.

Define a Variable To define variables we need to specify its data type first, then give a variables a name and by using = we can initialize some value

Define a variable Example code snippte

I'm going type my first variable name

class Main {
 public static void main(String args[]) {
       int myFirstVariable = 5;
      }
}
  • So here we've defined our first variable.
  • We've specified a data type of int.
  • Again that was an integer, a whole number and
  • we used the equals operator and the literal value
  • five to set the variable to have the value of Five.
  • And finally we added that semicolon to end the line

    be more specific it's a declaration statement.

So a declaration statement is used to define a variable by indicating the data type, and the name, then optionally to set the variable to a certain value. So here the type, and type is a shortcut for the word data type is an int, the name is my first varibles and the value were assigning or initialising our variable with is five. So we're declaring a variable of type int with the name my first varibles and assigning the value of five to it. The initialization is optional, in other words we could have omitted the equals five with Java in general variables have to be initialised

Did you find this article valuable?

Support Roshan Shambharkar by becoming a sponsor. Any amount is appreciated!