20155335 2006-2007-2 "Java Programming" third week study summary
# # Textbook Learning Content Summary
First of all, the key is the area of the basic type and class type, the resulting object must define the class, the class is a concept, does not exist, the object is present, conforms to the tired definition, the Java program consists of a class consisting of variables and functions,
The code that the main function forms in the class is as follows
public class mytest{
public static void Main (String args[]) {
}
}
Class definition uses the Class keyword.
Relationship of objects and references
In Java, an object is referenced, like a pointer, a reference, and an object are associated together, otherwise the reference is not allowed to be controlled by me, if a reference to a string is created
String S
It is not associated with any object at this time, and if you do something, the call will have some problems, (except for some basic types, which will be given the initial value when defined), the associated method is
String S=new string ();
or string s= "";
When associating, you might want to use new to create an object, to associate, and also to initialize.
In general, storing references and basic type variables, the stack allocates and frees memory primarily by moving the pointer up and down.
New means allocating a piece of memory, allocating memory to load the object, and when the program executes new, the heap allocates a memory space to the object, and the heap consumes more time than the stack when it allocates and frees the memory.
String [] class and array
The string class is the type of the literal, constructor
String {
Byte[]
Bytes
;(constructs a string object from a byte array. )
Array objects are to be manipulated, arrays are not purely data collections, and after an array is created with new, each index element has a default value, and it is important not to specify the array length.
Where is the class definition that represents the creation of an array object? Generated dynamically by the JVM.
Understanding the concept of encapsulation
Encapsulation is to allow other code to not freely obtain its own properties, the process and data surrounded, access to data only through the defined interface, the object as a whole.
Understanding constructs
When defining a class, you can use a constructor to define the initial process that the object establishes, with the constructor having the same name as the class without declaring the return type.
Overload
As long as the method name is the same, the parameter table is different, it can form the method overload, and the method overload is called compile-time polymorphism, which is determined by the compile time to call that method, which conforms to the nearest matching principle.
The conditions to be met by overloading are
Must be of the same class.
Method name.
The parameter types are different or the number of parameters is different.
Methods in Static
The function of static is, in short, convenient to make calls (methods/variables) without creating an object.
The static modified member variables and member methods are independent of any object of the class, and as long as the classes are loaded, the static object can be accessed before any of his objects are created, without referencing any objects.
The methods declared as static have the following limitations
1. They can only invoke other static methods.
2. Only static data can be accessed
3. This or super cannot be referenced in any way.
Call a static method for the class name. Method Name.
A variable declared as static is actually a global variable, and when an object is declared, all instance variables of that class are common to a static variable.
An inner class can be declared as a static class, and an inner class declared as statically can be used directly as a normal class, and static member variables and member methods decorated with public are essentially global variables and global methods, or they can be decorated by private to indicate that the variable can be in the block code of a class. or used in other static member methods of a class, but cannot be referenced directly in other classes by the class name.
# # Problems and solutions in textbook learning
-1 Questions
Operation Array Object P102 page run result first three null
-Xx1 Solutions
The initial value of the known class type is null.
Integer [] scores=new integer[3]; The number of objects created is 0.
-XX2 problem
How do I make the p135 page overloaded correctly?
-XX2 Solutions
Change the public double somemethod (int i) in line sixth to
Public double SomeMethod (float i)
- ...
# # Problems in code debugging and resolution process
-XX1 problem
-Xx1 Solutions
-XX2 problem
-XX2 Solutions
- ...
# # [Code Hosting] (link)
-Code Submission Process:
-Run git log--pretty=format: "%h-%an,%CD:%s" and
-Code Volume:
-Run Find Src-name "*.java" | Xargs Cat | Grep-v ^$ | Wc-l and
# # last week quiz summary of the wrong title
-The wrong question 1 and the reason, the decimal value of the 6.~0b1011 is-12, the binary 1011 is the inverse code of 1100, the value is 12, take the reverse, get-12.
-The wrong question 2 and the reason, 9.system.out.printf ("%b,11"), the output is 1011, is wrong, but its complement of 0100.
- ...
20155335 Eucun "Java Programming" third week summary