Javaaaaa@a
Javaaaaa@a
Presented by
Team-4
Data Types in
Java:
Definition:
Data types in Java define the type of data that
can be stored in variables. They specify the size and
type of values that can be held in variables, helping
to allocate the correct amount of memory.
Purpose:
To specify the kind of data a variable can hold
(e.g., integer, decimal, text, etc.).
To optimize memory usage and ensure type
safety (e.g., preventing operations between
incompatible data types).
Simple term’s:
Types of Data types:
public class A
{
static int m=100;//static variable
void method()
{
int n=90;//local variable
}
public static void main(String args[])
{
int data=50;//instance variable
}
}//end of class
Java Variable Example: Add
Two Numbers
public class Simple{
public static void main(String[] args){
int a=10;
int b=10;
int c=a+b;
System.out.println(c);
}
}
OUTPUT:
20
Java Constant
• Constant is a value that cannot be changed after
assigning it.
• Java does not directly support the constants.
• There is an alternative way to define the constants
in Java by using the non-access modifiers static and
final.
• In Java, to declare any variable as constant, we
use static and final modifiers.
• It is also known as non-access modifiers. According
to the Java naming convention the identifier name
must be in capital letters.
Static and Final Modifiers
Explanation
A class with the main() method to determine the
total cost based on a fixed price per unit is defined
by the Java program ConstantExample. To guarantee
its immutability, it declares a constant PRICE with
the value 234.90 by employing the last keyword.
CONCLUSION: