Primitive Types in Java

Photo by Maximilian Weisbecker on Unsplash


So what are primitives?

  • boolean: true or false values
  • char: 16 bit-sized characters (it uses Unicode system and ASCII)
  • byte: 8 bit-sized integers
  • short: 16 bit-sized integers
  • int: 32 bit-sized integers
  • long: 64 bit-sized integers
  • float: 32 bit-sized floating point numbers (numbers with a decimal point. eg: 3.14)
  • double: 64 bit-sized floating point numbers

So boxes you said?

  • a name, which could be anything you could think of (except for ones that start with numbers, or keywords)
  • a type, which describes the type of value the box can contain, a primitive or an object-type
  • a size, which you do not need to worry yourself too much with, except for providing a value bigger than the box’s capacity.


// Creating two boxes, x and y of types int and short respectively
int x = 30;
short y = x;
// This provokes an error (incompatible types)
short y = 30;
int x = y;
// Works like a charm

How to differentiate between object-types and primitives?


Thank you for reading!




Just a front-end guy and a bookworm who loves to share what he is learning.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Prerequisites for being a developer

A conversation about Planner

Back2Basics : Existential types in Scala


Vision behind the HUMAN ambassador program

What is automated testing?

PHP 8.1 made me delete these 30 lines of code

Draggable rectangle in OpenCV (Python)

Why Zoom’s Success Is Not a Coincidence — On Distributed Video Conferencing Architecture

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mohamed El Amine Yamani

Mohamed El Amine Yamani

Just a front-end guy and a bookworm who loves to share what he is learning.

More from Medium

Java Strings

what is an Array in java?

Java Programming Language: For-Each Loop Example

[Solved]: Eclipse JUnit Error: Class not found java. java.lang.ClassNotFoundException…