What is data Type ?
Java is a statically type language , means every variable must be declared with a specific data type before it can be used.
int age = 10;
String name = "ajay"
Data types are divided into,
1) Primitive data type,
2) Non-primitive data type.
1) Primitive data type:
Primitive data type specifies the type of the variable and store the value
Number:
- byte(8 bit)--> Stores the whole number from -128 to 127 (2**8 = 256)
- short(16 bit)---> Stores whole numbers from -32,768 to 32,767 (2**16 = 65,536)
- int(32-bit)---> stores whole number from -2,147,483,648 to 2,147,483,647 (2**32 = 4,294,967,296)
- long(64 bit)--->Stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (2**64 = 18,446,744,073,709,551,616)
Decimal number :
- float(32 bit) --->Single-precision decimal. Requires an f suffix.Sufficient for storing 6 to 7 decimal digits
double(64 bit) --->Double-precision decimal (default for decimals). Sufficient for storing 15 to 16 decimal digits
boolean(8 bit)---> the boolean data type has two possible value : True or False , bascially used for logical condition.
char(16 bit) --->Stores a single character/letter or ASCII values
Default value for primitive data type
2) Non-Primitive data type:
Non-primitive data type are created by programmer,Instead of storing actual value its stores memory references,
Non-primitive types can be used to call methods to perform certain operations
- String --> A sequence of characted wrapped in double quotes.
String name = "Ajay";
- Array ---> Array are used to stored multiple value in a single variable,To declare an array the variable type should defined by square brackets [].
String [] cars = { "audi", "BMW", "BenZ"}
int[] myNum = {10, 20, 30, 40};
- Class and object Enverthing in the java is associated with class and object Class Class like an object contructor , a template or blueprint for creating object.
Create a Class
create a class using class keyword,
Rule of creating Class name
- class name should first with upper case,
- should br meaning full name,
- No space allowed,
- should be in upperCase or camelCase,
- Special Charactors only "_" and "$" is allowed.
public class Main{
}
public class SuperMarket{
}
public class Super_Market{
}
public class Super$Market{
}
Creat a object
- Object is created only inside the class.
- Using new Keyword a object is created.
public class Main{
public Static void main(String[] args){
Main myObject = new Main();
}
}
Default value for Non-primitive data type
- Default value is always null for all type in non-primitve type

Top comments (0)