Variables
Javada iki cur varialbe var: primitive type and reference(complex type, reference type)
Primitive
1. boolean - 1 bit. true or false. By default false.
2. byte - 8 bit integral value. 0
3. short - 16 bit integral value. 0
4. int - 32 bit integral value. 0
5. long - 64 bit integral value. 0
6. float - 32 bit floating-point value. 0.0f
7. double - 64 bit floating-point value. 0.0f
8. char - 16 bit Unicode value. '\u0000'
variable(identifier) - lar istenilen herf, $, _ bawlaya biler. variable adinda . istifade oluna bimez.
Mes: float f = 4; float n = 4,3F; long k = 3L; double s = 3; double d = 3.6;
Ikilik say sistemi: 0b veya 0B ile bawlayir.
Sekkizlik say sistemi: 0 ile bawlayir.
Onaltiliq say sistemi: 0x ile bawlayir.
Declaration: boolean b;
Initialization: b = true;
Definition: int i = 6; Definition = declaration + initialization
Unicode elementleri '\uxxxx' weklinde ifade edilir. 'x' 16-liq say sistemindeki (hexadecimal) reqemlerdir. Yeni bir Unicode kodu 4 eded 4 bitlik reqemlerden emele gelir: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F] yeni ['\u0000' - '\uffff']
"_" - iki reqem arasinda iwlenilir. Bawlangicda ve sonda, noqtenin yaninda, "f", "F", "d", "D", "l", "L" yaninda iwlene bilmez.
public class Main {
public static void main(String[] args) {
String a = "10_0";
Integer b = Integer.valueOf(a);
System.out.println(a);
System.out.println(b);
}
}
Bu wekilde cevirme apara bilmerik.
Primitiv deyiwenlerle referans deyiwenlerin ferqi:
public class Main {
public static void main(String[] args) {
int i = 5;
int j = i;
i = 7;
System.out.println(i);
System.out.println(j);
String s1 = new String("a");
String s2 = new String("b");
String temp = s1;
s1 = s2;
s2 = temp;
}
}Roles of variables.1. Instance or object variables. 2. Class variables. 3. Local variables.1. Instance of object variables - identify, represent object.2. Local variables - method parameters, inside blocks of methods, inside blocks. Local variab-les are not part of the object. Sometimes they are called temporary variables or stack variab-les.local variable - lari initialize etmek lazimdir.
Комментарии
Отправить комментарий