Questions about JAVA:
- static (shared by all objects, owned by class), combined with final (unchanged)
- 序列化, serializable：通用的语言 for communication and persistence
- string builder
- 正则表达式:regex, //s, //s+
- Integer/int, Character/char?
- static block
- this() in constructor
- gnu trove
- script language
32-BITs SYSTEM and 64-BITs SYSTEM
- 232 − 1 = 4294967295 = 4 GiB − 1
- 32 bits will give you an addressable space of 2^32 items, each item being a full byte.
PRIMITIVE DATATYPES(stores in stack)
- byte: 8 bit signed integer, -128(2^7)~127
- short: 16 bit signed integer, -2^15~2^15
- int: 32 bit signed integer, -2^31~2^31
- long: 64 bit signed integer, -2^63, 2^63
- float: 32 bit single-precision floating point, 0.0f
- double: 64 bit double-precision floating point, 0.0d
double i = 5.0; i/2 = 2.0; （精度损失）i/2.0 = 2.5;
- boolean: 1 bit
- char: 16 bit Unicode character
java.lang PACKAGES CLASSES
String Class (object)
- Strinig is a class, any quoted string is an object, so we cannot use “==” to compare to strings, because we are comparing addresses of the objects in this way. We need to use str1.equals(str2) to compare two strings
- String objects are immutable, what about string builders?
- Use “+” to append strings
- s.valueOf(); return the string value of the argument
- s.contains(charSequence); if the argument is a character, use String.valueOf(arg) (423)
Integer Class (object)
- We cannot implement swap in java??
OBJECT ORIENTED PROGRAMMING
- Access level: private, public, …
- Variable model: we can copy value for primitive types, which can be expressed in 0 and 1, with fixed size. The variable and the value are together.
- Object model: do not have fixed size, the variable is a reference (8 bytes for 64-bits system, 4 bytes for 32-bits system), reference points to an object, which is stored in heap, the reference stores the address of the object in heap, the reference is stored in stack? Without initialization, the default value for a reference is null. Thus, in order to avoid NullPointerException, we need to initialize a reference with an object.
- For example, Student student1 = new Student(); it creates an Student type object stored in heap, this object has no name. The reference student1 points to the object. To wrap up, it can be summarized as “Reference = Object“. To count how many objects are created by the program, the only thing we need to count is how many “new”s there are.
- Reference array needs to be initialized independently. Student students = new Student; When we get access to students, it points to a null object, we have to intialize it like this: students = new Student();
- No modifiers, no variables, only constant
- A class implements an interface, and observe the rules. The reference of an interface can only use the methods defined in the interface, ignore other methods in the class selectively.
- A class can implement more than one interface.
- Similar to interfaces.
- In java, a class can only inherit one class, which is different from interface.