First, the initial Java
1, a Java source file can have a maximum of only one public class "but, can have more than one class declaration", when there is a public class, the source file name must be consistent with this class name, otherwise, cannot compile; if there is not a public class in the source file, There is no consistency requirement for the file name and class name.
II. Basics of Java syntax
1. Basic Data type:
A) Byte---1 bytes, short--2,int--4,long---8 "constant after remember to add L or L",char--2 bytes , float--4,double--8,.
2. Arrays
A) array declaration method: two: "Do not allocate memory space"
Data type array name []
Data type [] array name
b) Java does not allow the number of array elements to be specified within the square brackets in the declaration array, as distinct from C + +.
c) create a one-dimensional array: "When you create an array , you really allocate memory space , so you need to specify the number of elements "
Array name = new data element type [ number of elements ]
D) Initialize the one-dimensional array: "array length int len =array. length; "" is not a method without parentheses () "
int array[]= new int [] {1,2,3,4}; or
int array[]= {1,2,3,4}
3. Break and Continue differences
A) Break action: Jump out of the current loop body or program body ;
b) Continue function: can only be used inside the loop statement, function: Skip The cycle, continue to perform the next cycle.
4,java processing Big Data
A) There are two classes BigInteger and BigDecimal in Java, representing large integer types and large floating-point number classes, which can handle a sequence of numbers of any length ;
b) Statement:
BigInteger bi1= newBigInteger ();
BigInteger bi2= new BigInteger ();
c) BigInteger and BigDecimal two classes are not overloaded with "+", "-", "*", "/" operators, and have their own methods.
Add: Bi1. Add(BI2)
Minus: Bi1. Subtract(BI2)
By: Bi1Multiply (bi2)
Except: Bi1. divide(BI2)
Take the reverse: bi1. negate()
Exponential operation: Bi1. POW ( number)
III. Classes and objects
1. Create object: The process of creating an object is called instantiation of the class. Use new to create an object
2. Constructor :
A) The method that is automatically executed during class instantiation is called a construction method. No need to call manually
b) The name of the construction method must be the same as the class name, and there is no return value
3. This keyword:
Used to represent the current object itself, or an instance of the current class, all methods and properties of this object can be called through the This keyword.
4. Packing type, automatic unpacking and packing
That is, int---the corresponding integer, and so on.
5. Encapsulation: privatization of attributes; Provides a common way to access private variables
Declare the properties of private, and define the GetXXX () and Setxxx () methods to access
6. Single Case mode:
A) singleton mode, which ensures that a class has only one instance, and instantiates itself and provides this instance to the entire system, this class becomes a singleton class. "Choose a singleton class primarily to avoid inconsistent states"
b) The characteristics of a singleton class:
A singleton class can have only one instance;
The Singleton class must create its own unique instance;
The Singleton class must provide this instance to other objects.
Iv. Inheritance and polymorphism
1, the Java class only supports single inheritance, multi-inheritance is indirectly implemented through the interface;
2. Use Super to call the parent class's constructor method
A) subclasses do not inherit the construction method of the parent class. When you create a subclass object, the constructor of the parent class is called first, the member that inherits the parent class is initialized, and the child class constructor is called to initialize the members of the subclass.
b) Subclasses if you want to use the constructor of the parent class, you must use it in the constructor of the subclass, and use the keyword super to represent it, and super must construct the first statement in the method for the subclass .
C
3. Abstract class
A) An abstract class cannot instantiate "instantiate to subclass to complete" and can be inherited
b) Abstract methods must be overridden by subclasses.
c) As long as a class that contains an abstract method must be defined as an abstract class
d) Abstract classes can contain specific methods, or they may not contain abstract methods
4, polymorphism:--- an interface, a variety of implementations , is the same thing, showing a variety of forms.
A) Two ways to implement polymorphism: inheritance and interface
b
5.
Java Basics Summary