Java is a general-purpose language. A lot of its syntax is derived from C and C++ which makes it easier for C/C++ developers to migrate to that language.
Java is also an object-oriented language - it provides support for implementing software designed based on the object-oriented paradigm.
Java is a typed language.
In C++, the size (in bytes) of numeric data depends on the compiler and the computer you are using.
In Java, on the other hand, the size is standardized (the same for all operating systems).
A variable in Java must be a specified data type:
int myNum = 5; // Integer (whole number)
float myFloatNum = 5.99f; // Floating point number
char myLetter = 'D'; // Character
boolean myBool = true; // Boolean
String myText = "Hello"; // String
Data types are divided into two groups:
Primitive data types - includes byte,short,int,long,float,double,boolean and char
Non-primitive data types - such as String, Arrays and Classes.
A primitive data type specifies the size and type of variable values, and it has no additional methods.
Java has 8 primitive (basic) data types:
byte, short, int, long, float,double, char, boolean
Non-primitive data types are called reference types because they refer to objects.
Reference variables are created using defined constructors of the classes. They are used to access objects. These variables are declared to be of a specific type that cannot be changed. For example, Employee, Puppy, etc.
Class objects and various type of array variables come under reference datatype.
Default value of any reference variable is null.
A reference variable can be used to refer any object of the declared type or any compatible type.
Example: Animal animal = new Animal("giraffe");
The main difference between primitive and non-primitive data types are:
Primitive types are predefined (already defined) in Java. Non-primitive types are created by the programmer and is not defined by Java (except for String).
Non-primitive types can be used to call methods to perform certain operations, while primitive types cannot.
A primitive type has always a value, while non-primitive types can be null.
A primitive type starts with a lowercase letter, while non-primitive types starts with an uppercase letter.
The size of a primitive type depends on the data type, while non-primitive types have all the same size.