Age-considered input needs to be judged by the introduction of:
Packaging:
Definition: Hide the properties of things and the details of implementation, only provide public methods to operate.
Private keyword:
Access modifiers, which can modify member variables and functions, are a form of representation of encapsulation, as well as classes, functions, and so on.
Description of the Set/get method:
A public method is required to access the private decorated member variable.
The Set method mainly modifies the value of the member variable;
The Get method is primarily to get the value of a member variable.
Note: Set/get does not necessarily appear together, depending on the actual need to use the corresponding function.
This keyword:
is a reference to the currently owned member function class object.
Each in-class method has a default this.
function: Solve the problem of local variable hidden member variable "nearest principle"
Construction Method:
The method name is the same as the class name, there is no deterministic return value type, and no return value.
Function: Member variable initialization
The default constructor is no longer available when the construct method is not shown, and no parameter is provided by default, as long as there is a display to write out the constructor method.
"Write your own parameterless constructor VS default parameterless constructor"
Recommendation: Add an parameterless constructor to each of your classes.
Constructor method Overload: "Parameter list is different"
To construct a code block:
Code block: code within {};
Function: Sets the common code within the construction method together and takes precedence over the construction method execution.
About initializing the execution order of related operations:
Default initialization-"show initialization-" construct code block-"constructor
Static keyword: "Resource sharing"
Static modifier member Variable features:
A: Loaded with the class, B: Precedence over the class object and exists;
C: The modified member variable is shared by all objects;
D: can be called directly using the class name.
Precautions:
A:static modified method, there is no this keyword;
B: Static methods can only access static variables, non-static methods are callable;
C: Can be called by using the class name.
Documentation notes:
Format:/** */
Format key: @author author @version version @param parameter @return return value
Sample document Generation command: "Destination directory" "Source file name"
javadoc-d d:\\-author-version Arrarytest.java
API application:
Math class
[ABS ()//Absolute ceil ()//Ceiling value floor ()//Flooring value round ()//rounding "+0.5"
Random ()//Generate stochastic value [0.0,1.0) max ()//Max min ()//min.]
Guess number Game
1: Package
(1) Hide the implementation details and provide a public access method.
Classes, methods and so on are actually the embodiment of the package.
(2) Private keyword
A: Used to modify member variables and member methods.
B: The modified content cannot be accessed in other classes.
(3) Common applications:
All member variables in the class are private, giving the corresponding Get/set method.
The code reflects:
Class Student
{
private String name;
private int age;
Public Student () {}
Public Student (String name,int Age)
{
THIS.name = name;
This.age = age;
}
public void SetName (String name)
{
THIS.name = name;
}
Public String GetName ()
{
return name;
}
public void Setage (int.)
{
This.age = age;
}
public int Getage ()
{
return age;
}
}
2: Construction method
(1) format and features
Format:
Access permission modifier class name (parameter ...) {}
Access permission modifiers:
Public,private
Characteristics:
A: The method name is the same as the class name
B: no return value type
C: No specific return value
(2) Precautions:
A: If you do not give the constructor method, the JVM will automatically give you a parameterless constructor method.
B: If you give a construction method, then the JVM will no longer provide a parameterless construction method.
This time, if you want to use the parameterless construction method: You can only provide
Recommendation: Always manually give the method of non-parametric construction.
3:this Keywords (master)
(1) is a keyword. Represents a reference to the current class object.
Simple note: In a method, which object calls the method, this represents who.
In addition to the static method, there is an implied in all methods that there is a this reference
(2) Application scenario:
Resolves a local variable hidden member variable problem.
4:static keywords
(1) is a keyword. member variables and member methods can be decorated.
(2) Static characteristics:
A: Loaded with the load of the class
B: Precedence over object existence
C: Shared by all objects of the class
D: Can be called by the class name
(3) Static precautions:
A: There is no this keyword in the static method.
B: Static methods can only access static members.
(4) Invocation of static content:
A: Called by the object
B: Called by the class name
Recommended to be called by the class name.
(5) When should I use static?
If a content is shared by all objects, it is statically decorated.
Example:
Cups and water dispensers.
Toilets and people.
Teachers and students.
Random number of 5:math classes (master)
The class name calls a static method.
Package: Java.lang
Class: Math
Method: public static Double Random ():
The class under the Java.lang package can be used directly without a guide package.
Generates a random number between 1-100:
int number = (int) (Math.random () *100) +1;
Java Basics-day eighth