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

Java_Day2_DataTypes_Variables

The document covers the fundamental building blocks of Java, focusing on data types, variables, and constants. It explains the two main categories of data types: primitive (such as int, double, char, and boolean) and reference types (like Strings and Arrays). Additionally, it discusses variable declaration and initialization, the concept of constants using the `final` keyword, and type casting methods in Java.

Uploaded by

bdsingh9040
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Java_Day2_DataTypes_Variables

The document covers the fundamental building blocks of Java, focusing on data types, variables, and constants. It explains the two main categories of data types: primitive (such as int, double, char, and boolean) and reference types (like Strings and Arrays). Additionally, it discusses variable declaration and initialization, the concept of constants using the `final` keyword, and type casting methods in Java.

Uploaded by

bdsingh9040
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Java - Day 2: Data Types,

Variables & Constants


Understanding fundamental building
blocks of Java programs
What are Data Types?
• - Data types define the kind of values a
variable can hold.
• - Java is **strongly typed**, meaning each
variable has a specific type.
• - Two main categories: **Primitive Data
Types** and **Reference Data Types**.
Primitive Data Types
• 1. **Integer Types**: byte, short, int, long
• 2. **Floating-Point Types**: float, double
• 3. **Character Type**: char
• 4. **Boolean Type**: boolean

• Example:
• ```java
• int age = 25;
• double price = 99.99;
• boolean isJavaFun = true;
• char grade = 'A';
• ```
Reference Data Types
• - These store references (memory addresses)
instead of actual values.
• - Includes: **Strings, Arrays, Classes,
Interfaces**.
• - Example:
• ```java
• String name = "John";
• int[] numbers = {1, 2, 3, 4, 5};
• ```
Variables in Java
• - A variable is a container for storing values.
• - **Declaration & Initialization**:
• ```java
• int number; // Declaration
• number = 10; // Initialization
• ```
• - Variable Types: **Local, Instance, Static**.
Constants in Java
• - A constant is a fixed value that cannot be
changed.
• - Declared using the `final` keyword.
• - Example:
• ```java
• final double PI = 3.14159;
• ```
Type Casting in Java
• - **Implicit Casting (Widening Conversion)**: Automatic
conversion from smaller to larger type.
• - **Explicit Casting (Narrowing Conversion)**: Requires
manual conversion.
• - Example:
• ```java
• int num = 10;
• double d = num; // Implicit casting
• double x = 9.7;
• int y = (int) x; // Explicit casting
• ```
Recap & Next Steps
• - Java has **primitive and reference data
types**.
• - Variables store values, while **constants**
hold fixed values.
• - **Type casting** allows conversion between
data types.
• - Next: **Operators & Expressions in Java**.

You might also like