Variables
Variables
• Keyword
• Variable
• Identifier
• Data type
• Declaration and Initialization
Keyword
• Reserved words in Java with special meanings.
• Example: int, class, if, return, static, void , public.
They are predefined by the language and have special purposes. You
cannot use them for naming variables, methods, or classes.
class Demo {
public static void main(String[] args) {
int age = 25;
}}
• Declaration: • Initialization:
System.out.println(Name);
System.out.println(age);
general rules for naming variables
Which is correct:
1.Int Number=10;
2.String value=hello everyone;
3.boolean x=true;
4.String str value=“Vanakkam”;
Identifier
• The name used for variables, methods, classes, etc.
Byte Short
• Size:8bits(1 byte) • Size:16 bits(2 bytes)
• Range : -128 to 127 • Range : -32,768 to 32,767
• Default value :0 • Default value :0
int long
• Size:32 bits(4 bytes) • Size:64 bits(8 bytes)
• Range : -2,147,483,648 to • Range :-2^63 to 2^63-1
2,147,483,647 • Wider range is needed
• Default value :0
• Most Commonly Used. long l=1000000000L;
int b=100000;
Primitive Datatype
float double
• Size:32 bits(4 bytes) • Size:64 bits(8 bytes)
• Default value :0.0f • Default value :0.0d
• 7 decimal digits • 15 to 16 decimal digits
char boolean
• Size:16 bits(2 bytes) • Size:1bit
• Single charactor • Values: true or false
• Default value :0
Char c=‘A’; • Wider range is needed
boolean flag=true;
Summary
• Concept Definition Example
• Keyword Reserved word with special meaning. int, class, if
• Variable A container to store data. int age = 25;
• Identifier Name for variables, methods, or classes. Demo, age, main
• Data Type Defines the type of data a variable can hold . int, String, boolean
• Declaration Declaration is defining a variable; int age;
• Initialization initialization is giving it a value. age = 25;
Questions
1.What is JDK & Uses?
2.What is JVM & Uses?
3.What is JRE ?
4.What is Java Platform?
5.Java is Independent Platform or not and Why?
6.What is Keywords ?
7.What is Variables?
8.What is DataType and Tell some Basic types?
9.Explain Combined Declaration and Initialization with examples?