Learn Java , Selenium

Data Type – Below is the example of usage of data types in Java

				
					import java.util.ArrayList;

public class Program2 {

	public static void main(String[] args) {

		int number = 10;               // Integer (whole number)
		float floatNum = 6.99f;    // Floating point number
		char letter = 'F';         // Character
		boolean flag = false;       // Boolean
		String str = "Hello";     // String
	}

}

				
			

Explanation – 

This program demonstrates basic data types in Java:

  • int – Stores whole numbers (e.g., 10)

  • float – Stores decimal numbers (e.g., 6.99f). f is required to denote float.

  • char – Stores a single character (e.g., 'F')

  • boolean – Stores true or false values (e.g., false)

  • String – Stores a sequence of characters (e.g., "Hello")

Below is the various data type size in java – 

Data TypeSize
int4 bytes
long8 bytes
float4 bytes
double8 bytes
boolean1 bit
char2 bytes

 

Scroll to Top