package Basics;
public class DataTypes_Variable {
public static void main(String[] args) {
/* → Integer DataType ➔ byte, short, int, long
→ Decimal DataType ➔ float, double
→ Character DataType ➔ char, boolean, String(Non-Primitive DataType) */
/* → Variables are Container which stores value
→ How to declare Variable :
Syntax ➔ <datatype> <variableName> = <value>; */
/* → Rules for constructing names of variable in Java ->
➔ Should start with letters, $ or _ (underscore)
➔ Can contain letters, digits, underscore, dollar-sign
➔ Should not contain white_spaces
➔ We cannot use reserved keyword as a variable */
// → sysout or sout + ctrl_space is a shortcut for Print Statement
/* Byte stores values between -128 and 127 as, 1byte = 8bit & 1bit has 2 possible outcome, so 1byte has +-2^7=256 possible outcome & 1bit is used for sign i.e. 0 for +ve sign and 1 for -ve sign */
byte n = 127;
System.out.println(n);
/* Short DataType stores values between -32768 and 32767 as Short data-type is a 16-bit(2byte) mean 2^15 possible outcome. */
short m = 182;
System.out.println(m);
// int data-type is a 4byte(32-bit) it stores values between -2147483648 and 2147483647
int roll_no = 15, age = 18;
System.out.println(roll_no);
long s = 123443; // long data-type is a 64-bit( 8byte)
System.out.println(s);
/* float data-type in Java stores a decimal value with 6-7 total digits of precision and it is a 32-bit. To assign a float value we have to always put f in the end of value */
float y = 13.2f;
System.out.println(y);
double z = 12.13243; //double can store up to 16 digits after the decimal & it is a 64-bit
System.out.println(z);
String name = "Akash"; // String is always placed in Double Quotes
System.out.println(name); // And its a Non-Primitive DataType
boolean itsbool = true;
System.out.println(itsbool);
char mychar = '@'; //char datatype store only one character it placed in Single Quotes
System.out.println(mychar);
}
}