Introduction of java Programming language.
■》Variables & Data Types & constant ->
● Variables->
○ A variable is a container (storage area) used to hold data.
○ Each variable should be given a unique name (identifier).
■ Program->
public class Main
{
public static void main(String[] args)
{
// Variables
String name = "ved";
int age = 19;
float price=399.50;
String neighbour = "duggu";
String friend = "shourya";
}
}
● Data Types->
Data types are declarations for variables. This determines the type and size of data associated with variables which is essential to know since different data types occupy different sizes of memory.
There are 2 types of Data Types :
1● Primitive Data types : to store simple values.
2● Non-Primitive Data types : to store complex values.
□ Primitive Data Types->
These are the data types of fixed size.
Data Type Names->
1-short
2-int
3-long
4-float
5-double
6-char
7-boolean
8-byte
□ Non-Primitive Data Types->
These are of variable size & are usually declared with a ‘new’ keyword.
Eg : String, Array, object, interface, class.
String name = new String("ved");
int[] marks = new int[3];
marks[0] = 97;
marks[1] = 98;
marks[2] = 95;
■》 Constants->
A constant is a variable in Java which has a fixed value i.e. it cannot be assigned a different value once assigned.
● Example->
public class Main
{
public static void main(String[] args)
{
// Constants
float PI = 3.14f;
}
}
Comments
Post a Comment