[Java object-oriented BASICS (I)] data types and operators, java object-oriented
[Meow "Android path] [BASICS (1)] [Java object-oriented Basics] data types and operators 1. Data Types in Java, there are two types of data: basic data type and reference type. There are 8 basic data types, as shown in the following table:
| Basic Data Type |
Bytes |
Binary digits |
Minimum value |
Maximum Value |
Default Value |
| Byte |
1 |
8-bit |
-2 ^ 7 |
+ 2 ^ 7-1 |
0 |
| Short |
2 |
16-bit |
-2 ^ 15 |
+ 2 ^ 15-1 |
0 |
| Int |
4 |
32-bit |
-2 ^ 31 |
+ 2 ^ 31-1 |
0 |
| Long |
8 |
64-bit |
-2 ^ 63 |
+ 2 ^ 63-1 |
0 |
| Float |
4 |
32-bit |
IEEE754 |
IEEE754 |
0.0f |
| Double |
8 |
64-bit |
IEEE754 |
IEEE754 |
0.0d |
| Char |
2 |
16-bit |
\ U0000 |
\ UFFFF |
\ U0000 |
| Boolean |
---- |
---- |
---- |
---- |
False |
| Void |
|
|
|
|
|
It should be noted that: 2. The differences between the two data types are compared from the following three aspects: Meaning, processing, and value assignment. 2.1 represents the basic data type. Its variables represent a specific value, which can be a character, a number, or a Boolean value. The referenced data type. Its variable represents a memory address, which points to a memory space and stores one or more values corresponding to the variable in the memory space. In Java, the value of the basic data type and the address information of the referenced data type are stored in the Stack, and the value of the referenced data type is placed in the Heep. Example:
1 class Student {2 String ID; 3 String Name; 4 int Age; 5 public Student (String id, String name, int age) {6 ID = id; 7 Name = name; 8 Age = age; 9} 10} 11 12 int a = 10; 13 Student B = new Student ("070271006", "meow Xiaomi", 18 );
The stack corresponding to the above variables is as follows:
2.2 When processing basic data types, space has been granted at the same time, so you can directly perform operations. For example:
1 int a = 10;2 int b = a + 20;
Generally, a variable is created when the reference type is declared, and the space is not allocated. You need to use the keyword "new" to open up space for data storage.
For example:
1 Student student = null; // a Student variable is declared at this time. 2 // student. toString (); // when this variable is used for access, an error occurs: This row will report a null pointer exception 3 student = new Student ("070271006", "meow Xiaomi", 18 ); // inform the JVM to open up the storage space
The space allocation of the above two lines of code JVM is handled as follows:
After the above process, student can access the member variables in the heap. Another special case is the use of the String type. For detailed analysis, see the next article. 2.3 The assignment operation of the basic data type is indeed a "assignment" in the actual sense, for example:
1 int a = 10; 2 int B = a; // at this time, the value of B is 103 // If you modify the value of a, the value of B will not change. 4 a = 100; // at this time, the value of a is 100, and the value of B is 10.
Generally, the value assignment of the reference type passes the heap memory address, for example:
1 Student stuMiao = new Student ("070271006", "meow Xiaomi", 18); 2 Student stuNodin = stuMiao;
The above assignment operation does not create a new object, but declares a variable named stuNodin in the stack, whose value is the same as that of stuMiao, all point to the heap memory address of the Student object. The image metaphor is like the two names of the same person.
If you modify the reference data of stuMiao, the referenced data of stuNodin changes at the same time.
1 stuMiao. Age = 16; // at this time, stuMiao. Age is equal to 16; stuNodin. Age is equal to 16;
Similarly, as a special type, String still does not apply to the above rules. For more information, see the next article.
3. Here, we only provide an overview of operators in Java, and will not repeat them here. See the following table for details:
| Arithmetic Operators |
+,-, ×,/, % Get the remainder, ++, --,-reverse |
| Relational operators |
>,<, >=, <= ,! =, = |
| Logical operators |
! Non, &, | or, ^, Or, & short circuit and, | short circuit or |
| Bitwise operators |
~ Bitwise inversion, & bitwise AND, | bitwise OR, ^ bitwise OR |
| Shift Operator |
<Move left,> move right with a symbol, >>> move right without a symbol |
| Three-object conditional Operator |
D = expression 1? Expression 2: expression 3 |
| Value assignment operator |
=, + =,-= |
4. There are basically two types of loops in loop Java: for Loop and do-while loop. Beginning with J2SE 1.5, Java introduced a for variant loop: foreach loop. It doesn't mean that foreach is a keyword similar to for, but a name that is easy to understand. Its function is to traverse "Each (one by one. The basic structure is based on the for loop. The details are as follows:
1 for (element type t element variable x: traversing Object list) {2 references the java Statement of x; 3}
Foreach is a simplified version of for. It is mainly used for simple traversal of arrays and collections. However, it also has limitations. It only provides the traversal function and does not support operations such as deletion and replacement. For loops that require recording and using indexes, foreach itself cannot be implemented (it can be recorded by itself ). Therefore, the for loop cannot be replaced, but all can be converted to the corresponding for loop.
1 // instance 1, traversing the array: 2 int [] arrays = new int [] {1, 2, 3}; 3 for (int I: arrays) {4 System. out. println (I); 5} 6 7 // instance 2, traversing set: 8 List <String> list = new ArrayList <String> (); 9 for (String item: list) {10 System. out. println (item); 11}
[Nodin's Tips] This article mainly introduces the data types, operators, and loops in Java, which are very basic knowledge of Java. However, the more basic the knowledge is, the less visible it is. As the saying goes, "the treasure of a thousand miles is destroyed by the ant nest. At the same time, the difference between the two data types is analyzed in detail to further understand the data types, it also lays the foundation for our next article to analyze strings in more detail.
This article is original from Nodin. For more information, see the source! Http://www.cnblogs.com/monodin/p/3841185.html
Which data type is the operator number in java?
+-These belong to the char type. Even if one of the eight main types is used, you can test how to identify them. If the "+" outside "of the String in the definition is the connection String, even if "" is the same as the number, if it is of the string type, if it is of another type such as int double +, it is an operator. In println, if the first character is of the string type, all the plus signs are connected to the connector. If the first character is of the char type, followed by a number such as println ("?" + 1 + 2 + "fuk") The answer is 66fuk. In this way, the first and second operators are operators, and the third is connectors ,? It calculates the sequence table code.
Didn't I talk about the word table code output by 1 + a + 1?
Java object-oriented class type definition
You should understand the basic data type.
1. What are the characteristics of object-oriented?
2. So you need to know what is a class and what is an object?
Answer: 1. The three main characteristics of object-oriented, inheritance, encapsulation and polymorphism, do not understand what it means, but you need to know this concept!
2. What is a class: A class is a collection of abstract things, and an object is a class specific. Humans-class, you, me or him are objects. Are all human objects.
What you are confused about is just a syntax problem. This is called the reference of holding objects, which is a syntax problem.
Syntactically, the format of the method used to call an object is: object. Method (parameter ...)