BASIC BUILDING BLOCKS, DATA TYPE IN JAVA | BCA SEM 04 JAVA BKNMU JUNAGADH

 

Basic building blocks:

Data Types in Java

Data types specify the different sizes and values that can be stored in the variable. There are two types of data types in Java:

§  Primitive data types: The primitive data types include Boolean, char, byte, short, int, long, float and double.

§  Non-primitive data types: The non-primitive data types include Classes, Interfaces, and Arrays.

Java Primitive Data Types

In Java language, primitive data types are the building blocks of data manipulation. These are the most basic data types available in Java language.


Boolean Data Type

In Java, the boolean data type represents a single bit of information with two possible states: true or false. It is used to store the result of logical expressions or conditions. Unlike other primitive data types like int or double, boolean does not have a specific size or range. It is typically implemented as a single bit, although the exact implementation may vary across platforms.

Example:

Boolean a = false; 

Boolean b = true;   

 

Int Data Type

The int data type in Java is a primitive data type that represents a 32-bit signed two's complement integer. It has a range of values from -2,147,483,648 to 2,147,483,647. The int data type is one of the most commonly used data types in Java and is typically used to store whole numbers without decimal points. Its default value is 0.

int a = 100000, int b = -200000 

Float Data Type

The float data type in Java is a primitive data type that represents single-precision 32-bit IEEE 754 floating-point numbers. It can represent a wide range of decimal values, but it is not suitable for precise values such as currency. The float data type is useful for applications where a higher range of values is needed, and precision is not critical.

float f1 = 234.5

Char Data Type

The char data type in Java is a primitive data type that represents a single 16-bit Unicode character. It can store any character from the Unicode character set, that allows Java to support internationalization and representation of characters from various languages and writing systems.

char letterA = 'A'   

The char data type is commonly used to represent characters, such as letters, digits, and symbols, in Java programs. It can also be used to perform arithmetic operations, as the Unicode values of characters can be treated as integers. For example, you can perform addition or subtraction operations on char variables to manipulate their Unicode values.

Post a Comment

Thanks for comment.

Previous Post Next Post