Ready to become a real developer java study -day02
Variable and identifier variable In memory, the variable address is stored and the value of the variable can be assigned. ![[Pasted image 20250417123627.png]] variable has be to assigned with a value before we use this variable. identifier public class java02 { public static void main(String[] args) { //1. Identifier as alphabet characters String username = "lisi"; //2. Identifier as special characters: _ $ String _name = "wangwu"; String $name = "xiaohong"; String user_name$="lisi"; //3. numbers: 0 - 9, but cannot be put at the start String name2 = "lisi"; //4. the identifiers cannot be repeated within one {}-> variables name cannot be repeat with one {} //5. identifiers are case-sensitive in java //6. some identifiers are keywords in java and cannot be used as variable name //String public = "lisi"; //7. camel naming rule String userName = "lisi"; //8. identifiers' length is not limited. } } Data type ![[Pasted image 20250422143909.png]] public class java03 { public static void main(String[] args) { /** * data storage unit: * - bit: the smallest unit for data execution/processing. on(1), off(2) * - byte: the smallest unit for data storage. is a group of 8 bits. * 1 byte = 8 bit * KB, MB, GB, TB... * 1024 Byte = 1KB * 1024KB = 1MB * 1024MB = 1GB * 1024GB = 1TB * * byte : 8 bits * short: 16 bits * int : 32 bits * long: 64 bits * */ //integer data type byte b = 10; short s = 10; int i = 10; long l = 10; //floating point data type /** * float: single precision 6-7 decimal digits * double: double precision 15-16 decimal digits */ float f = 1.05226585231f; //a f/F need to be added at the tail of value double d = 2.055698412698877452; System.out.println(f); //1.0522659 System.out.println(d); //2.0556984126988773 //character type char c = 'c'; //only one character //boolean type boolean bl = true; /** * Type Conversion in Java * 1. widening conversion/implicit casting(small to large type) * byte -> short -> int -> long -> float -> double convert automatically! * * 2. Narrowing conversion/explicit casting (large to small type) * -- may cause data loss and cannot be converted automatically. * -- may cause precision loss or overflow * -- Requires explicit casting using parentheses. * byte

- Variable and identifier variable In memory, the variable address is stored and the value of the variable can be assigned. ![[Pasted image 20250417123627.png]] variable has be to assigned with a value before we use this variable.
identifier
public class java02 {
public static void main(String[] args) {
//1. Identifier as alphabet characters
String username = "lisi";
//2. Identifier as special characters: _ $
String _name = "wangwu";
String $name = "xiaohong";
String user_name$="lisi";
//3. numbers: 0 - 9, but cannot be put at the start
String name2 = "lisi";
//4. the identifiers cannot be repeated within one {}-> variables name cannot be repeat with one {}
//5. identifiers are case-sensitive in java
//6. some identifiers are keywords in java and cannot be used as variable name //String public = "lisi";
//7. camel naming rule String userName = "lisi";
//8. identifiers' length is not limited.
}
}
- Data type ![[Pasted image 20250422143909.png]]
public class java03 {
public static void main(String[] args) {
/**
* data storage unit: * - bit: the smallest unit for data execution/processing. on(1), off(2) * - byte: the smallest unit for data storage. is a group of 8 bits. * 1 byte = 8 bit * KB, MB, GB, TB... * 1024 Byte = 1KB * 1024KB = 1MB * 1024MB = 1GB * 1024GB = 1TB * * byte : 8 bits * short: 16 bits * int : 32 bits * long: 64 bits * */
//integer data type
byte b = 10;
short s = 10;
int i = 10;
long l = 10;
//floating point data type
/**
* float: single precision 6-7 decimal digits * double: double precision 15-16 decimal digits */ float f = 1.05226585231f; //a f/F need to be added at the tail of value
double d = 2.055698412698877452;
System.out.println(f); //1.0522659
System.out.println(d); //2.0556984126988773
//character type char c = 'c'; //only one character
//boolean type boolean bl = true;
/**
* Type Conversion in Java * 1. widening conversion/implicit casting(small to large type) * byte -> short -> int -> long -> float -> double convert automatically! * * 2. Narrowing conversion/explicit casting (large to small type) * -- may cause data loss and cannot be converted automatically. * -- may cause precision loss or overflow * -- Requires explicit casting using parentheses. * byte <- short <- int <- long <- float <- double */
//1. widening conversion
byte b2 = 10;
int i2 = 100;
i2 = b2;
//2. narrowing conversion
b2 =(byte) i2;
}
}