Because the university has learned C + +, a rough look at Java years ago, at this moment for some not very clear questions to write down their own understanding and notes.
1. Data type
Direct storage is not too repetitive and must be understood for reference storage types:
A reference storage type includes a class type, an interface type, an array type, and so on, where the storage model is "indirect storage", when a reference data type is created, the reference (handle) is first allocated to a piece of memory on the stack, and the object's specific information is stored on the heap memory, and then the reference above the stack points to the object
The stack contains a variety of logic, as well as such as shaping, floating-point data, according to the principle of first-in-the-way stack, the code will be executed, the execution code is contained in the stack can be stored data. However, when the amount of data is too large, the performance will be significantly affected in the stack. So, we put a lot of data into the heap, and then the heap address in the stack. In this way, the data can be found by the address at the time of the data call.
2. Operators
Attention to the accuracy of the problem: when the type of two operands is inconsistent, the system needs to convert different data types to the highest precision data type, so as to ensure the accuracy of the calculation results.
For division operations, the result of dividing two integers in a program must be an integer
3. Dynamic array
The Java dynamic array is an object that can arbitrarily scale the length of an array, and in Java it is common to arraylist,arraylist is the java.util.ArrayList that comes with Javaapi. The following describes the use of ArrayList as a dynamic array of java.
The Java dynamic array is an object that can arbitrarily scale the length of an array, and in Java it is common to arraylist,arraylist is the java.util.ArrayList that comes with Javaapi. The following describes the use of ArrayList as a dynamic array of java.
1. Syntax: Add () is the addition of a new element,
Remove () deletes an element,
Size () Gets the length of the ArrayList.
The subscript for ArrayList is starting from 0.
2. Sample Code
Import java.util.ArrayList;
public class Javaarraylist {
public static void Main (String[]args) {
Initialization of a Java dynamic array
ArrayList al=new ArrayList ();
Adding data to a Java dynamic array
Al.add ("a");
Al.add ("B");
Al.add ("C");
Output Java dynamic array
for (int i=0;i<al.size (); i++) {
String Aleach= (String) al.get (i);
System.out.println (Aleach);
}
Delete an element in an array, delete the second element
Al.remove (1);
Modify the Java dynamic array and put the new element in the second position
Al.add (1, "2");
Output Java dynamic array
for (int i=0;i<al.size (); i++) {
String Aleach= (String) al.get (i);
System.out.println (Aleach);
}
}
}
The output is as follows:
A
B
C
A
2
C
Ps:java one-dimensional dynamic arrays are generally used in collections: Arraylist,hashmap, etc.
Generic type:
Arraylist<t> a = new arraylist<t> ();
2nd-android Programming Basics Notes