Learn Java Programming: Variables and Data Types

in learn •  3 years ago 

Variables are places where temporary values ​​are stored.

Just that.

Are you serious?

Yes seriously, if you want a longer one...

…let's see what it means from Wikipedia:

Variables: (Lat) 1. variable, not fixed; 2. declaration of something that has a variety of values ​​3. different in programming languages ​​are also called symbols that represent certain values, variables known in sub programs are called local variables. being known in general / intact in one program is called a global variable.

Well, don't you know?

Otherwise, just understand: Variable as a place to store temporary values.

Then, what is a data type?

A data type is a type of data stored in a variable.

Various Data Types
The following are the various data types in Java:

▶️ char: Character data type, example Z
▶️ int: number or integer, example 29
▶️ float: decimal number, example 2.1
▶️ double: decimal number too, but larger capacity, example 2.1
▶️ String: a collection of characters that make up text, eg Hello World!
▶️ boolean: a data type that only evaluates to true and false.

Creating Variables

The thing to know in creating variables in java is how to write them.

The format is like this:

image.png

Example:

Create an empty variable of type integer:

image.png

Create a variable of type integer and directly fill in the value:

image.png

Create a set of variables of the same data type:

image.png

So, where is it written?

Inside the main() function: the variables written in the main() function and other functions are called local variables.
Inside the class: These variables are called class or global variables.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!