3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Java入門】変数(Variable)について

Last updated at Posted at 2020-04-15

変数(Variable)とは?

様々な言語には変数というのが存在する。
変数は一言で言うとお皿❓箱❓みたいな⁉️つまり、何らかのデータを入れておく領域。
変数を宣言するとメモリ上の決まった領域を確保し、そこにデータが格納される。

変数(Variable)の型

前回の記事を参考してください〜💕(030)
型を見に行こう
※ByteからStringまで

変数(Variable)のアクセス修飾子

前回の記事を参考してください〜💕(030)
修飾子を見に行こう
※ public・protected・privateが対象
❣️アクセス修飾子がなし😮:現在のクラスと同じパッケージのクラスからアクセスできる。

変数(Variable)の書き方

  • 宣言
型 変数名;
--------
int a;
  • 代入
変数名 = 値;
※変数に値を代入するには「=」を使うよ❣️
----------
a = 10;
※変数に値を代入する時は型に気を付けてね❣️
  • 様々な宣言方法

① 宣言と同時に値を代入する。(初期化)

int a = 10;

② 同じ型に複数を宣言する。

int a, b, c;

③ ①+②

int a = 1, b = 2, c = 3;

変数(Variable)名のルール?

変数名を決めるのに👇のルールを守ろう‼️

  • 「英字」か「_」か「$」で始まる。
  • 注‼️「$」は使うべきでない、また「_」で始めるべきでない
例)
・_value
・get$Money
  • 大文字、小文字が区別される。
例)
dong
Dong
dOng
doNg
donG
DOng
dONg
doNG
DonG
DONG

  • 予約語は使えない‼️

||||||
|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
| abstract | boolean | break | byte | case |
| const | continue | default | do | double |
| goto | if | implements | import | instanceof |
| package| private | protected | public | return |
| this | throw | throws | transient | try
| catch | char | class | extends | final
| int | interface | long | native | new |
| short | static | super| switch | synchronized |
| void | volatile | white |finally | float |
| for |

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?