Java is statically typed and also a strongly typed language because, in Java, each type of data (such as integer, character, hexadecimal, packed decimal, and so forth) is predefined as part of the programming language and all constants or variables defined for a given program must be described with one of the Java data types. Data types in Java are of different sizes and values that can be stored in the variable that is made as per convenience and circumstances to cover up all test cases.
Java has two categories in which data types are segregated:
1. Primitive Data Types in Java
Primitive data are only single values and have no special capabilities. There are 8 primitive data types.
2. Non-Primitive (Reference) Data Types
The Non-Primitive (Reference) Data Types will contain a memory address of variable values because the reference types won’t store the variable value directly in memory. They are strings, objects, arrays, etc.
i) Strings[TBD]
Strings are defined as an array of characters. The difference between a character array and a string in Java is, that the string is designed to hold a sequence of characters in a single variable whereas, a character array is a collection of separate char-type entities. Unlike C/C++, Java strings are not terminated with a null character.
ii) Class
A Class is a user-defined blueprint or prototype from which objects are created. It represents the set of properties or methods that are common to all objects of one type.
iii) Object
An Object is a basic unit of Object-Oriented Programming and represents real-life entities. A typical Java program creates many objects, which as you know, interact by invoking methods.
iv) Interface[TBD]
Like a class, an interface can have methods and variables, but the methods declared in an interface are by default abstract (only method signature, no body).
v) Array[TBD]
An Array is a group of like-typed variables that are referred to by a common name. Arrays in Java work differently than they do in C/C++.
Reference: https://www.geeksforgeeks.org/data-types-in-java/
Top comments (0)