OneBite.Dev - Coding blog in a bite size

create a variable in java

Code snippet on how to create a variable in java

  int age; // declaration
  age = 20; // initialization

The above code snippet is an example of how to declare and initialize a variable named ‘age’ in Java. First, the line “int age;” declares a variable ‘age’ of type integer. The type of a variable defines the types of values that the variable can contain. In this case, ‘age’ can only contain values of the type integer. Next, the line “age = 20;” initializes the newly declared variable ‘age’ to a value of 20. Initializing a variable simply means assigning an initial value to the variable. After the two lines above are executed, the variable age is now ready to be used in your code.

java