0% found this document useful (0 votes)
13 views5 pages

Summer Home Work Class IX 2024 (1)

Uploaded by

itsnewmehaha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views5 pages

Summer Home Work Class IX 2024 (1)

Uploaded by

itsnewmehaha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

CHAPTER 3.

VALUES AND DATA TYPES

❖ DATA TYPES IN JAVA: Data type in Java is used to identify data and dictate

the JVM what type of data will be stored in a variable during program execution and

therefore allocates enough space for the variable. Java data types are of two kinds:

(i) Primitive or Fundamental or Intrinsic data type

(ii) Reference or Composite or Extrinsic data type.

⎯ Primitive or Fundamental or Intrinsic data type: The data types which are

independent of any other type, are known as Primitive data types. They are pre-

defined or built-in data types because the system developers of Java have defined

them. Java provides 8 different primitive data types. byte, short, int, long, float,

double, char and Boolean.

Integer Primitive Data Type: It is used to store integer data that is numbers

without a decimal point. Java uses 4 integer data types. byte, short, int and long.
Data Type Size Range

byte 8 bits ( 1 byte) -27 to 27 – 1

short 16 bits ( 2 bytes ) -215 to 215 – 1

int 32 bits ( 4 bytes ) -231 to 231 – 1

long 64 bits (8 bytes ) -263 to 263 – 1

Floating Primitive Data Type: It is used to represent numbers with decimal

point i.e., fractional numbers. float and double are the two Floating Primitive

Data Types used in Java.

Data Type Size Range

float 32 bits ( 4 bytes) 3.4 E – 38 to 3.4 E + 38

double 64 bits ( 8 bytes ) 1.7 E – 308 to 1.7 E + 308


Character Primitive Data Type: It is used to store or represent a character in Java.

Java follows the UNICODE system to represent characters. Thus, the size of a

character in Java is of 2 bytes.

Data Type Size Range

char 16 bits ( 2 bytes) Characters having Unicodes from 0 to 65,536

Boolean Primitive Data Type: It is used to represent the two states that a condition

that can evolve in Java. Any condition in Java can either be valid, i.e. true or invalid,

i.e. false.

Data Type Size Range

boolean 8 bits (1 byte) true or false

⎯ Reference or Composite or Extrinsic data type: Reference data types are

secondary type of data. It is composed or constructed using Primitive data types.

Ex.: class, array and interface.

❖ Arithmetical Expression and Statement:


A set of variables, constants and arithmetical operators used together to yield a

meaningful result is known as known as an Arithmetical Expression. When an

arithmetical expression is assigned to a variable then it is called an Arithmetical

Statement.

For example,

d = b * b – 4 * a * c;

In this example, b * b – 4 * a * c is an Arithmetical Expression and d = b * b – 4 * a *

c is an Arithmetical Statement.
Types of Arithmetical Expressions:
Based on the data types, the arithmetical expression is of two types:

(1) Pure Expression

(2) Impure Expression

(1) Pure Expression: An Arithmetical expression that uses all its components of

same data types is known as Pure Expression.

For example, int a, b;

int c = a + b - c;

In the expression above, all its components like a, b and c are integer data type.

So, it is a Pure Expression.

(2) Impure Expression: An Arithmetical expression in which one or more

components are of different data types is known as Impure Expression or Mixed

Expression.

For example, int a;

float f, d;

double s = a + f - d;
Here, a, f, d and s are of different data types. So, it is an Impure Expression.

❖ TYPE CONVERSION: In a mixed expression the result can be obtained in any

one form of its data types. Hence, it is needed to convert the various data types into a

single type. Such conversion is termed as Type Conversion. In Java, Type Conversion

can be done in two different ways which are as follows:

(i) Implicit Type Conversion

(ii) Explicit Type Conversion


⎯ Implicit Type Conversion: In a mixed expression, the data type of the result gets

automatically converted into the higher most data type available in the expression

without any intervention of the user. This process of type conversion is known as

Implicit Type Conversion or Coercion.

Hierarchy of Data Types:

byte

char

short

int

long

float

double

(Hierarchy of the data types)

This hierarchy indicates the increasing order of data types.

For example, int x = 10; // occupies 4 bytes


double y = x; // occupies 8 bytes
System.out.println(y); // prints 10.0
In this code, 4 bytes integer value is assigned to 8 bytes double value.

⎯ Explicit Type Conversion: When the data type gets converted to another data

type after user’s intervention, the type of conversion is known as explicit type

conversion. Typecasting is generally used for explicit type conversion. The

general syntax is:

(data type) expression;

For example, double x = 10.5; // 8 bytes


int y = x; // 4 bytes; raises compilation error
System.out.println(y);
In this code, 8 bytes double value is narrowed to 4 bytes int value. It raises error.

Here we need to explicitly typecast it.

double x = 10.5;

int y = (int) x; // Explicit Typecasting

System.out.println(y); // prints 10

The double x is explicitly converted to int y and thus y gets the value 10.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy