0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Java 学習メモ(まとめ②) 型

0
Posted at

プリミティブ型

Javaのデータ型は、プリミティブ型と参照型の2種類

型     用途 例 備考
int 整数を扱う int age = 25; 約 -21億 ~ 21億まで扱える
double 小数を扱う double pi = 3.14159; 小数点を含む計算に使用
boolean 真偽値を扱う boolean isStudent = true; true または false のみ
char 1文字を扱う char grade = 'A'; シングルクォーテーション ' ' を使用
long 大きな整数を扱う long population = 8000000000L; int より大きな値を扱える
float 小数を扱う float rate = 0.1f; double より精度が低い
byte 小さな整数を扱う byte score = 100; -128 ~ 127
short やや小さな整数を扱う short year = 2025; int より小さい範囲

参照型(とりあえず今はStringだけ)

型    種類 用途 例 備考
String 参照型 文字列を扱う String name = "Taro"; ダブルクォーテーション " " を使用

型安全

プログラムの間違いをコンパイル時に発見できるため、実行時に予期しないエラーが起こるリスクを減らせる

変数の命名規則

変数は、キャメルケースで書く。(小文字始まり・単語の区切りを大文字⇒userName)

定数

・変数を変更したくない場合はfinalを使い定数を宣言する
・final を付けた変数に再代入しようとすると、コンパイルエラーになる
・定数の命名規則は、変数とは異なり 大文字のスネークケース(単語をアンダースコアで区切る)を使う

final double TAX_RATE = 0.10;
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?