Data Types in Java

Data Types in Java

Data Types in Java

Data Types in Java:

In Java, there are two types of data types: primitive data types and reference data types.

  1. Primitive Data Types:
    • byte: 8-bit signed two’s complement integer (-128 to 127)
    • short: 16-bit signed two’s complement integer (-32,768 to 32,767)
    • int: 32-bit signed two’s complement integer (-2,147,483,648 to 2,147,483,647)
    • long: 64-bit signed two’s complement integer (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)
    • float: 32-bit single-precision floating point (approximately ±3.40282347E+38F)
    • double: 64-bit double-precision floating point (approximately ±1.79769313486231570E+308)
    • boolean: true or false
    • char: 16-bit Unicode character (‘\u0000’ to ‘\uffff’)
  2. Reference Data Types:
    • Class
    • Array
    • Interface
    • Enum
    • String

Primitive data types are used to represent simple values like numbers and characters, while reference data types are used to represent objects that are instances of a class or an interface.

  1. byte: used to represent whole numbers from -128 to 127
				
					byte num = 10;
				
			
  1. short: used to represent whole numbers from -32,768 to 32,767
				
					short num = 1000;
				
			

3. int: used to represent whole numbers from -2,147,483,648 to 2,147,483,647

				
					int num = 1000000;
				
			
  1. long: used to represent whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
				
					long num = 1234567890L;
				
			
  1. float: used to represent decimal numbers with single precision
				
					float num = 3.14f;
				
			
  1. double: used to represent decimal numbers with double precision
				
					double num = 3.14159265359;
				
			
  1. boolean: used to represent true/false values
				
					booleanisTrue = true;
				
			
  1. char: used to represent single characters
				
					char letter = 'A';
				
			
Join To Get Our Newsletter
Spread the love