当前位置:网站首页>2022-7-18 guyujia's study notes of group 8
2022-7-18 guyujia's study notes of group 8
2022-07-20 10:05:00 【Sister haha】
One 、 object-oriented
java Is an object-oriented programming language , stay java in , Everything is an object .
Process oriented : Process oriented is to analyze the steps needed to realize the requirements , Through some methods, step by step to achieve the requirements .
object-oriented ( Behaviorisation ): According to the characteristics of the whole demand , Functional division , Encapsulate these common parts into classes ( After class instantiation, the object ), Let the object solve the problem .
stay java in , There are three characteristics of object-oriented :
1. encapsulation
2. Inherit
3. polymorphic
4. abstract
Member variables — attribute
· The process of creating objects , Class instantiation process , An object is also called an instance of a class
We created one Car Class object car1, This car1 Is the name of the object . Actually this car1 It's just an identifier .
· Naming rules for object names : Little hump
· Syntax for creating objects : Class name Object name = new Class name ( ); Class name Object name = new Constructors ( Class name ())
Define a member methodpublic: Access modifier , Later on
void: no return value
run(): Method name , identifier
{}: Method body . What does this method do
(): The parameter When declaring a method , Parameters in parentheses , Formal parameters , Shape parameter , It can be used as a local variable When a method is called , The parameters of the real incoming method , The actual parameter , Actual parameters . Parameters can have multiple , The middle is separated by commas Java Chuanshen in Chinese , You need to clarify the data type
There are ways to return values
public
boolean: return type , After a series of operations, my method , To get a specific value , Return value , The type of return value is boolean
Return value with return xxx; Type to match
A method with a return value will get a specific value after execution , This value can be saved
When exactly should there be a return value , When there is no return value ?
In development , Most methods have return values
return keyword
- return Keyword termination method continues
- Returns the return value of the method
problem : stay void The methods of , Can there be return?
can
Call other methods in one method
public class Ch05 { String str; public void show(){ // Omit part of the code to be executed ... // Call other methods in one method // Ch05 c = new Ch05(); // c.info(); System.out.println(str); info(); } public void info(){ // Omit part of the code to be executed ... } }
Naming rules for identifiers : Letter , Numbers , Underline , Dollar symbol , The number can't start 1、 Class name : Hump 2、 Property name 、 Method name : Little hump
Focus on : 1、 We've learned before 8 Basic data types 2、 Starting today , We have more data types . All the classes we can meet , Including what we just created Car It's a data type , A beauty is also a data type . , All classes are data types , All reference data types . From now on , We really understand class This keyword , Create a class , Used to create a data type . image car1,car2,car3....car100 It's called quoting , It points to an area in memory . Where these objects are stored Space , We call it heap . We need to understand two memory spaces : 1、 Stack : We store variables and basic data types ( characteristic : First in, then out ) The address is a hexadecimal string 2、 Pile up The initial value of the reference data type is null
public class Ch03 { public static void main(String[] args) { // Car car; Declared a Car Properties of type car, // assignment , except String Outside , Other reference data types need new Car car = new Car(); // Just see new, It's not null, It has an address System.out.println(car); } }
recursive
Member method Method names cannot be repeated If one method has static, To call a non static Methods , You can only create objects , Use object . MethodCh01 c = new Ch01( ) ;
c.run( );
Adjust yourself - recursive The problem of recursion :StackOverflowError Stack overflow out of memory
Method overloading
Method overloading (Overload) 1. Same method name 2. Different parameters ( Type of parameter , Number of parameters , The order of the parameters ) 3. Occurs in the same class Independent of return value type , Independent of access modifier , Independent of the method body The benefits of method overloading : In order to use the same method with similar functionsIndefinite length parameter 1. In the parameter list , At most one variable length parameter 2. The variable length parameter must be in the last position· The essence of indefinite length parameter is array
·java.lang All classes under the package do not need to be explicitly imported , The rest needs to be guided
public int sum(int [] arr){ result = 0;
practice :
demand :
* Write two overloaded methods
* 1. One method is to find the maximum value of two numbers
* 2. Another method is to find the maximum of three numberspublic class Ch03 { public int max(int num1,int num2) { return num1 > num2 ? num1:num2; } public int max(int num1,int num2,int num3){ int a = (num1 > num2 ? num1 : num2); return a > num3 ? a : num3; } public static void main(String[] args) { Ch03 c = new Ch03(); c.max(1,2,3); } }
Access modifier
- public Common , Public Maximum authority , As long as it is public Declared method , As long as in the same project , Can be used .
· It can be placed in the class 、 attribute 、 Method 、 On the constructor
- protected The protected : Package can span , If the cross package must be its subclass
· Can be placed in the attribute 、 Method 、 On the constructor
- default ( Write nothing )default: Only the current package can be accessed ( You can't lead the bag in )
· It can be placed in the class 、 attribute 、 Method 、 On the constructor
- private Private Minimum authority , Only the current class can be used
· Can be placed in the attribute 、 Method 、 On the constructor
Constructors
grammar : Access modifier Class name ( parameter list ){ }
characteristic ( characteristic ):
- Java stay new When the object , First, check whether the class corresponding to the object has a constructor , If so, what kind of constructor ; If there is no constructor , Objects cannot be built ( Create objects )
- Each class will have a default parameterless constructor
- The constructor is called when the object is instantiated
- We actually create objects through constructors
- If a constructor is declared as shown in a class , The original default built-in parameterless constructor is invalid ( Be overwritten ). If there are multiple constructors , Must overload .
public class Ch06 { public static void main(String[] args) { // The process of creating objects , The process of instantiation , Create a Dog Class // Class name Object name = new Constructors ; Dog dog = new Dog(""); } }
Learning experience :
Today's content is not very understood , You also need to watch videos to review and understand , Today's content is slightly understood , But you can't write the code yourself , This process needs more exercise , Think more ,
边栏推荐
- FPGA majority voter (including code)
- Secure Code Warrlor学习记录(四)
- 第三届“传智杯”全国大学生IT技能大赛(初赛B组题解)
- 乐山师范程序设计大赛2020-G: 最大公约数【思维】
- Detailed explanation of multiresolution decomposition and reconstruction of wavelet analysis
- 网安学习(二十四)传输层协议
- 离散数据(数组)的过零位置搜索
- Program verification of one-dimensional wavelet transform based on cyclic convolution (C language)
- Leetcode:905. 按奇偶排序数组【双指针+三种语言实现】
- CA运行fft版本
猜你喜欢
FPGA decoder + decoder (including code)
FPGA -- detailed explanation of the principle of displaying images with VGA timing (2)
Detailed explanation of multiresolution decomposition and reconstruction of wavelet analysis
FPGA majority voter (including code)
The third "intelligence Cup" National College Students' IT skills competition (solution to group B of the preliminary competition)
Leetcode: Game 302 (summary)
Infrared decoding program based on timer capture function (NEC protocol)
Secure Code Warrlor学习记录(三)
TCP three handshakes and four swings
Detailed explanation of the principle of triode series linear voltage stabilizing circuit and Multisim Simulation
随机推荐
FPGA skimming p1:1-out-of-4 multiplexer, asynchronous reset Series T trigger, parity check, shift splicing multiplication
方向信号的表达——复指数信号
(data and electricity) summary of various triggers - FPGA octet (1)
Connaissance de la technologie des tunnels d'infiltration Intranet
Leshan normal programming competition 2020-e: divide stones [01 backpacks]
Many new features of ktor2.0 were thought of a year ago and have been implemented in the project
提升开发效率的 Chrome 开发者工具快捷键参考
Matlab之数据筛选
Detailed explanation of the principle of triode series linear voltage stabilizing circuit and Multisim Simulation
Leetcode:905. 按奇偶排序数组【双指针+三种语言实现】
Reasons and solutions for the whitening of computer shortcuts -- the lesson of blood woo woo
正则表达式的设计
乐山师范程序设计大赛2020-I: 数组重排【贪心】
内网渗透隧道技术的相关知识
numpy中选择特定两行
Allegro cannot display drill legend information when adding drill legend
CA运行fft版本
【PTA】7-24 约分最简分式 (15 分)
虚幻引擎学习(一)
我的2020年线上的夏令营总结