Core JAVA
Java Runtime Environment (JRE)
Java Virtual Machine (JVM)
Java overview
Java basics
Java Objects and classes
Java Constructors
Java basic datatypes
Java variable types
Java modifiers/Access Modifiers In Java
Java Basic Operators
Java Loops and Controls
Java conditions
Java numbers and characters
Java strings
Java arrays
Java date time
Java methods
Java file and IO operations
Java exceptions
Inner class
Java OOPs Concepts
Java Inheritance
Java Polymorphism
Java Abstraction
Java Encapsulation
Java Interface
Cohesion and Coupling
Association, Aggregation and Composition
Java Collections
Java ArrayList
Java LinkedList
Set and HashSet
LinkedHashSet and TreeSet
Queue and PriorityQueue
Deque and PriorityQueue
Java Map Interface
Java HashMap
Internal Working Of Java HashMap
Java Mutithread
Methods of Thread In Java
Join , run & Start Method in Threads
Difference b/w start & run Methods in Threads
Java Concurrency Package & its Features
CountDownLatch, CyclicBarrier, Semaphore and Mutex in Thread
Java Data Types
What are java data types? Java Data types in java is the same as real world data types which are used to represent a certain set of data and their basic nature, for example in mathematics there are integers, floats etc. similarly in the programming world to represent those we have some data types.
If you have already worked on C, C++ or any similar programming language then you must have used int, float, double, char etc data types.
Remember these data types need space in memory to store for example int will take some bytes(8 bit will be equal to 1 byte) in memory and float will take more bytes to store in memory as the complexity and requirement increases data type memory requirement changes as well.
There are two data types categories are in java:
- Primitive Data Types.
- Non-primitive/ Reference/Object Data Type
Primitive Data Types
As the name suggests, primitive data types are old and primitive which we have been using or known to them in mathematics or any programming language.
You are already aware about a few of them but just don’t know till now that they are primitive in java for example int (integer in mathematics) or float.
As a programmer you should know these data types and how much memory they take so you will be able to choose appropriate one for your program and also will save memory which will make your program high performant.
Let’s jump into java’s primitive data types:
- boolean: Boolean is used for flag or any condition, it can hold only two values true or false, it is widely used in conditions in code.
- byte: byte can a small data type which can hold -128 to 127 any integer(in mathematics)
- char: char is used to represent single characters, example a-z any letter or A-Z any letter etc..
short: it is kind of integer used to represent smaller range of integer numbers. - int: int represents integer from mathematics.
- long: it is kind of integer but have ability to hold huge numbers.
- foat: it is used to hold float numbers with decimal points.
- double: it is used to hold float values with decimal points but has ability to hold large float numbers.
![Java’s primitive data types](https://tutorialshut.com/wp-content/uploads/2021/03/tabular-data.png)
Non-primitive/ Reference/Object Data Type
As the name suggests non primitive data types are newer data types which are also known as reference or object data types.
Examples of reference data types in java are Long, Integer, Boolean and Class, at first some of these may look primitive but they are completely different.
Each reference or object data type may even have methods within them for operations.
Few Examples of non primitive:
- Integer
- Boolean
- List
- Array
- String
- Class (any class)
Below diagram of data types gives quick overview of both types:
![diagram of data types](https://tutorialshut.com/wp-content/uploads/2021/03/diagram-of-data-types.png)
How to Declare Data Types In Code
Syntax:
<Name of primitive or non-primitive data type> <desired name to hold> = <value>;
Examples of primitive data type:
int age = 20;
float amount = 20.0f;
char firstChar = 'c';
Examples of non primitive data types:
Integer weight = 20; Float price = 20.0F; String name = "developer";
References
Java primitive data types
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
Next Articles