Note: The first chapter is called "quick browsing", which briefly covers these basic concepts and technologies in Java. Although I have learned java before and developed Android for a while, I will take a note of some basic content that I did not know before and what I did not know.
1. Several Concepts of the Method
1 public static void main(String[] args)2 {3 //...4 }
Modifier: public and static;
Return type: void;
Method Signature: Method Name and parameter list, that is, main and string [] ARGs;
Method header: modifier, return type, and method signature, that is, public static void main (string [] ARGs );
Code between Methods;
Method Declaration: 1-4 rows.
2 Enumeration type
Each enumerated constant is a static field pointing to the object corresponding to its value, rather than an integer value. This is somewhat different from the enumeration type in C and C ++, but it is hard to remember what the enumeration type in C # is.
3. For Loop
The declared cyclic variables are specific to for during initialization, and other control flow statements cannot declare variables within the statement (this has not been noticed or tried ). The circular variable scope is the circular body.
4. Create objects and static methods
Instantiate and allocate it to the memory area of the stack. All objects are accessed by reference. Static methods cannot directly access non-static members because there is no specific object, that is, this reference.
5 string and printf
String is not a character array. You cannot assign a character array to a string reference. You can use a character array as a parameter to create a String object for the string constructor. The string object is read-only or immutable!
System.out.printf("The value of pi is % .3f %n",Math.PI);
Here, % N is not the same as \ n, and will vary with the operating system! (This is unknown .)
6 override
The method is to implement methods with the same method signature and return type as the super class. A simple experiment is conducted here. The Code is as follows:
1 class A 2 { 3 public void println() 4 { 5 System.out.println("A"); 6 } 7 } 8 9 class B extends A10 {11 public void printlnB()12 {13 System.out.println("B");14 }15 }16 17 class C18 {19 public static void main(String[] args)20 {21 new B().println();22 }23 }
(1) such code can be directly compiled and executed. The displayed result is of course;
(2) Change the printlnb of Class B to println for compilation and execution. The result is B, which is understandable;
(3) then, change the public name of println of Class B to private. A compilation error occurs during compilation and execution. The error is returned as follows:
(4) connect and comment out new B (). println ();. Compile the First Half of the error;
(5) connect (3) and set new B (). change println () to new B (). super. println () and new B (). super (). println () cannot be compiled. (Of course, this may be meaningless, but it should be an experiment ).
There are still some things that can be studied here. After reading a special chapter, I will go to the experiment.
7 annotations
I just used @ override or something. This annotation is provided in the book. Of course I didn't make it clear. Mark it for the moment:
@Reviewed(reviewer = "Joe Smitch", date = 20050331)// ... @interface Reviewed{ String reviewer(); int date();}
Although @ override is often seen in Android code, I have never paid much attention to it. There is also such an advanced usage, how to use it, and I will look at it later.