It's all about Java: Atomicity with Java Programming Language

Sunday, 28 September 2025

Atomicity with Java Programming Language

 Atomicity with Java

What is Atomicity


Atomicity, in computer science, is considered to be a property [ALL-OR-NOTHING], that the state of a resource in an operation is not controlled by a different flow of execution at the same time [Even in time slicing operations]

We know, Java is not pure object oriented programming language, due to primitive data types' design behavior.

Most of the Java experts, while designing and developing applications thrives hard, to create, most secured applications considering "Atomicity in multi threaded application".

Does Java language helps in developing Secured application..?

The answer is no, Java programming language does not give secured applications at all, especially in multi threaded environment.

As we know, Java supports 2 types of variables/data types. 
  1. Primitive data types
  2. User defined data types

Primitive data types:      

Java supports 8 different primitive data types. They are: 

  1.  boolean    1 byte
  2.  short        2 bytes
  3.  int            4 bytes
  4.  char         2 bytes
  5.  float         4 bytes
  6.  long         8 bytes
  7.  double     8 bytes
  8.  byte         1 byte

User Defined data types:


In Java, user defined data types are created using "new" operator. For example, to create Employee object, the following instruction is coded

Employee employee = new Employee();

Now, the employee in the above statement, is a reference to an Employee class and called as user defined data type.

Now, coming to the point [Why Java is not secured..?], the primitive data types, long and double are not atomic variables. That means they are not executed in a single operation. 

long variable's size is 64 bits. And it is divided into 32 bits + 32 bits while copying from one memory location to another memory location. and all user defined data types are based on primitive data types.

And these two primitive variables [long and double] breaks the atomicity law. 

And developers can not bypass long and double variables in their program to create application. It is almost impossible to create the application without these variables.

Especially, in multi threaded based application, these non atomic variables may give unpredictable results. 

No comments:

Post a Comment

Popular posts

Atomicity with Java Programming Language

 Atomicity with Java What is Atomicity Atomicity, in computer science, is considered to be a property [ALL-OR-NOTHING], that the state of a ...