0% found this document useful (0 votes)
36 views

Unit-I Chapter in Book - 3 Data Types, Variables and Arrays: - K. Indhu

This document covers data types, variables, and arrays in Java. It discusses why Java is strongly typed and defines its primitive data types. Sample programs demonstrate using the long, double, char, and boolean data types as well as dynamic variable initialization, variable scope/lifetime, type conversions, and single and multi-dimensional arrays. The goals are to explain why Java is strongly typed, its data types, primitive data types, and features such as type promotion rules and how arrays work in one, two, and three dimensions.

Uploaded by

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

Unit-I Chapter in Book - 3 Data Types, Variables and Arrays: - K. Indhu

This document covers data types, variables, and arrays in Java. It discusses why Java is strongly typed and defines its primitive data types. Sample programs demonstrate using the long, double, char, and boolean data types as well as dynamic variable initialization, variable scope/lifetime, type conversions, and single and multi-dimensional arrays. The goals are to explain why Java is strongly typed, its data types, primitive data types, and features such as type promotion rules and how arrays work in one, two, and three dimensions.

Uploaded by

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

UNIT- I

CHAPTER IN BOOK- 3
DATA TYPES, VARIABLES
AND ARRAYS

-K. Indhu

SYLLABUS COVERED HERE


Data Types, Variables and Arrays

K. INDHU

GOALS
1. Why Java is strongly typed ?
2. Data Types in Java
3. Primitive Data Types in Java
4. Sample Program using Long
5. Sample Program using Double
6. Sample Program using Char
7. Sample Program using Boolean
8. Dynamic Initialization of Variables
9. Scope / Lifetime of Variables
10.Javas Type Conversions
11.Sample Program Type Conversion
12.Javas Type Promotion Rules
13.Single Dimensional Arrays
14.Multi Dimensional Arrays
K. INDHU

WHY JAVA IS STRONGLY


TYPED ?
In Java->

(1) Every variable has a type, Every expression


has a type and Every type is strictly defined.
(2) Also, all assignments are checked for type
compatibility.
(3) Any type mismatches during assignments
are errors that must be corrected before the
compiler will finish compiling the class.
Thus Java is called Strongly Typed language.
K. INDHU

DATA TYPES IN JAVA

K. INDHU

PRIMITIVE DATA TYPES IN JAVA

K. INDHU

SAMPLE PROGRAM USING


LONG

K. INDHU

SAMPLE PROGRAM USING


DOUBLE

K. INDHU

SAMPLE PROGRAM USING


CHAR

K. INDHU

SAMPLE PROGRAM USING


BOOLEAN

K. INDHU

10

DYNAMIC INITIALIZATION OF
VARIABS

K. INDHU

11

SCOPE / LIFETIME OF
VARIABLES

K. INDHU

12

JAVAS TYPE CONVERSIONS


When one type of data is assigned to another type of
variable, an automatic type conversion will take place if below
two conditions are met->

The two types are compatible.

Destination type is larger than Source type.


When the above two conditions are met, WIDENING
CONVERSION takes place.

K. INDHU

13

JAVAS TYPE CONVERSIONS


CHART

K. INDHU

14

SAMPLE PROGRAM TYPE


CONVERSION

K. INDHU

15

JAVAS TYPE PROMOTION


RULES
Java's widening conversions
are->
From
From
From
From
From
From

a byte to a short, an int, a long, a float, or a double,


a short to an int, a long, a float, or a double,
a char to an int, a long, a float, or a double,
an int to a long, a float, or a double,
a long to a float or a double,
a float to a double.

The Type Promotion Rules are:1. All byte and short values are promoted to int.
2. If one operand is a long, the whole expression is
promoted to long.
3. If one operand is a float, the entire expression is
promoted to float.
4. If any of the operands is double, the result is double.
K. INDHU

16

SINGLE DIMENSIONAL ARRAYS

K. INDHU

17

SAMPLE PROGRAM

K. INDHU

18

MULTI-DIMENSIONAL ARRAYS

K. INDHU

19

SAMPLE PROGRAM

K. INDHU

20

SAMPLE PROGRAM

DECLARATION- 3
DIMENSIONAL ARRAY

K. INDHU

21

ALTERNATE ARRAY
DECLARATION WAY

K. INDHU

22

SO FAR WE STUDIED
Data Types, Variables and Arrays

K. INDHU

23

HAPPY
LEARNING!!!

You might also like