😎

Java Data Types

2021/08/21に公開

Primitive Type

Name Explanation Wrappter Class
boolean 論理型(true or false) Boolean
char 文字型(整数型 符号なし16bit) Character
byte 整数型(8bit) Byte
short 整数型(16bit) Short
int 整数型(32bit) Integer
long 整数型(64bit) Long
float 単精度浮動小数点型(実数型)(32bit) Float
double 倍精度浮動小数点型(実数型)(64bit) Double

Example

boolean

boolean flag = false;
or 
Boolean flag = true;

char

char letter = 'D'; 
or
Character letter = 'D';

※ If it is double quotation, that become error.

byte

byte b = 100;
or
Byte b = 100;

short

short num = 5;
or
Short num = 5;

int

int num = 5;
or
Integer num = 5;

long

long num = 5;
or
Long num = 5l;

※ WrapperClassを使用する際はLongであることを明示する必要がある(最後にl をつける)

float

float floatNum = 0.01f;
or
Float floatNum = 0.01F;

※ floatであることを明示する必要がある。(最後f or Fをつける)

double

double doubleNum = 0.01;
or
Double doubleNum = 0.01;

Reference Type

Name Explanation
String 文字列
Array 配列
Class クラス

Example

String

String text = "Hello, World";

Array

String[] langs = { "Ruby", "Python", "C", "Java" };

Class

※ 参考: Java言語プログラミングレッスン(上)

Discussion