What are Java's primitive types?

In Java, every variable has a type declared in the source code. There are two kinds of types: reference types and primitive types. Reference types are references to objects. Primitive types directly contain values. There are 8 primitive types:

  • byte
  • short
  • int
  • long
  • char
  • float
  • double
  • boolean

From the Java Language Specification, Chapter 4. Types, Values, and Variables:

The Java programming language is a statically typed language, which means that every variable and every expression has a type that is known at compile time.

The Java programming language is also a strongly typed language, because types limit the values that a variable [...] can hold or that an expression can produce, limit the operations supported on those values, and determine the meaning of the operations. Strong static typing helps detect errors at compile time.

The types of the Java programming language are divided into two categories: primitive types and reference types. The primitive types [...] are the boolean type and the numeric types. The numeric types are the integral types byte, short, int, long, and char, and the floating-point types float and double. The reference types [...] are class types, interface types, and array types. There is also a special null type. An object [...] is a dynamically created instance of a class type or a dynamically created array. The values of a reference type are references to objects. All objects, including arrays, support the methods of class Object [...].


What do people mean by "Types"?

In the real world you have different types of vehicles, for example. Each serve a distinct purpose. You have sports cars for driving fast, utes for carrying tools, trucks for transporting lots of goods, and limousines for travelling in luxury. In the same way, in Java, you can have different types of data which serve different purposes e.g. you have numbers (which are used to add/subtract etc), you can have "strings" which are used to communicate words and letters. You cannot use letters to add - that just does not make sense, nor could you use numbers to write a sentence. You gotta use the right data type to do whatever you want to do.

Primtives vs reference types - what does it mean? What's the difference?

Now there are some "types" of data which are basic. These are already created by the boffins at Redmond/Sun. These are called "primitive" java types, and they store the values within themselves. What does that mean? It's best explained by example:

Example of a primitive type

If I gave you a $50 note, then the note in and of itself is worth $50. The value is stored in the note itself.

Primitives Juxtaposed with Reference Types

Now imagine that instead of giving you $50 I give you an piece of paper which has on it an address to a safe deposit box in my bank in Switzerland. The piece of paper i gave you is not worth $50 in and of itself, but it points to an address where you can get your $50. This piece of paper is basically a "reference" type, because it doesn't store any values within and in and of itself, it merely points to certain addresses. But I can give you an address to anything: planes, castles, rainforrests: anything!

Summary

You can't just hand someone a plane or a Shinkansen train from your back pocket: you just hand them an address to it. But if you have $50, or any type of currency: the actual substance is in your back pocket. You're not gonna give them a treasure map to your $50 note.

That in an nutshell is the difference between primitive and reference types.

I hope it helps.