/ W3SCHOOLS

W3schools - Data Type

이 페이지는 다음에 대한 공부 기록입니다
Lecture에서 배웠던 내용을 복습하며 작성했습니다

찾으시는 정보가 있으시다면
주제별reference를 이용하시거나
우측 상단에 있는 검색기능을 이용해주세요

Java Data Types

Data types are devided into two groups

  • primitive : byte, short, int, long

    • float, double

    • boolean, char

  • Non-primitive : String, Arrays, Classes

Primitive Data Type

The type specifies the size and type of variable value

It has no additional method

8 primitive data type in Java

  • interger(store whole) : byte(1byte) < short(2bytes) < int(4bytes) < long(8bytes)

  • floating point(store fractional) : float(4bytes) < double(8bytes)

    • sufficient for storing 6~7 / 15 decimal digit
  • boolean(1bit) : store true o false

  • char(2bytes) : store a single character/letter or ASCII

  • * Scientific number

    • “e” indicate the power of 10

    • “12E3” means “12000”

  • * Alternatively can use ASCII value

    • char var = 65; output “A”

Non-primitive Data Type

called reference type(they refer to object)

The main different between Non-primitive and primitive

  primitive Non-primitive
start lower upper
size depend on data type all the same
value always has can be null
mean predefined be created by the programmer
  can not can call method to perform certain operation

Java type Casting

assign a value of one primitive data type to another

  • Widening casting(automatically) : converting a smaller to large

    • byte < short < char < int < long < float < double
  • Narrowing casting(manually)

    • must be done manually by placing the type in parentheses in front of the value
double d = 9.78d;
int i = (int)d;