Java Foundation One (read head first Java record)

Source: Internet
Author: User

write it in front.in the actual application of Java, because there is no system to read the book or study, so the foundation is weak, just this book is a relatively entry-level books, record some of the following basic concepts, to facilitate their own to learn. Of course, if it is helpful to everyone is also very good. because the book has about 700 pages, it is too much to put all the knowledge points in an essay. At random I decided to split into a few essays to write. This article mainly describes some of the running Java programs. Some basic content of Java classes, variables, methods.   How Java Works1. Writing source code. java Files2. Compile the Java code with the Javac compiler to check for errors3. Compile the Java file with no error after output. Class5. Use the Java Virtual Machine (JVM) to read and execute the. class file, and turn the bytecode into a form that the platform can understand to run  program Structure of Java1. Classes in the source file2. Methods are stored in the class3. The statement is stored in the method4. Each program has at least one class and one main (), a program will only have a main (), main () is the beginning of the programclass dog{private int size;pulibc int GetSize () {return size;     }public int Add (int total) {int a=10;int b=12;total=a+b;return Total     } }Dog G=new Dog ()Description: Here dog is the class name, and G is the reference variable for the object. The size is an instance variable. A and B are local variables in the method, and add () and GetSize () are methods.   Classes and Objects1. Classes are not objects, classes are the models that create them (classes are blueprints for objects)2. Class consists of known instance variables and methods of executiontwo uses for 3.main (): Testing real classes and starting Java applications4.java All files can be archived in accordance with PKZIP format Java archive-.jar file, jar file can reference a simple text format text file manifest definition jar in a file containing the main () method5. Compiling the. java file compiles all of the classes in the. java file into a separate. class file (binary file)  variables1.java focus Type, variable must have type and nameThe 2.float type must be followed by F, otherwise all values with a decimal point will be treated as double (example float f=32.5f)  Reference variable:(for example, there is a dog class, dog d;d is a reference variable that refers to the dog object)1. The value of the reference variable represents the access method to the object on the heap, using the dot. To operate, which can be equivalent to referencing a pointer to2. The value of a reference variable that is not referenced to any object is null3. The object that the reference variable points to is present on the heap and is garbage collected by GC when the object on the heap is not referenced. Array1. The array is also an object, regardless of whether the original primary data type is placed inside2. The array itself must not be the original primary data type3. He can contain the original primary type data (int), or it can contain reference variables, but the reference variable is simply a reference, or the object needs to be created4. Once the array is declared, only the elements of the declared type (exception byte can be placed in int) are loaded.  Method1.java is passed by value, that is, through a copy. So the variable in the method actually copies the value to the formal parameter.2. The value of the parameter can be changed in the method, but cannot change the value of the argument passed in by the calling method  instance Variable1. Instance variables will always have default values, integers (0), float (0.0), Booleans (false), references (false)2. Data encapsulation, you can mark the variable as private through private (so that the external cannot directly access the data through the dot), and then through the public getter or setter method to set the variable value and read the value of the variable, and can be written to limit the value3. Instance variables are declared within a class and not in a method4. When local variables are declared in the method, there is no default value. Local variables must be initialized before they are used. If not initialized, the compilation does not pass5. The parameter of the method is the same as the local variable, but it does not need to be initialized or can be compiled, the parameter value is required when calling the method  Compare1. Use = = to compare primitive type data. Just compare whether the corresponding byte combinations are equal2. Use = = to compare reference variables, only two references to the same object return True (the object is not one, the value is False)  the process of developing a class1. Find out what the class should do2. Listing instance variables and methods3. Write the pseudo-code of the methodpseudo code consists of three parts: declaration of instance variable, method declaration and method Logic4. Write the test application of the method (write the test program concept from Extreme Programming XP, which makes it easier to write code faster)5. Implementation class6. Test method7. Debugging or re-engineering   watch out.the 1.if and while statements determine the condition of a Boolean value2.int x= (int) 24.6; (int) The number of floating-point numbers can be taken as integral parts3. The Java program needs to be compiled with Javac Xxx.java first. Then use Java XXX to execute the program (note that the Javac compile-time files need to add. java suffix, and then compiled through the use of Java XXX to execute the program, but there is no need to add. class suffix, directly with the program name can be)

Java Foundation One (read head first Java record)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.