201621123030 Java Programming 3rd week of study summary

Source: Internet
Author: User

1. Study summary of the Week 1. Beginner-oriented, will learn a lot of fragmented concepts and knowledge. Try to use mind mapping to organize these fragmented concepts and knowledge points. Use the tool to draw a link between the knowledge points and the knowledge points you learned this week. The steps are as follows:

1.1 Write the key points of knowledge that you think are important in this week's study, such as classes, objects, encapsulation, etc.
1.2 Use mind maps or OneNote or other tools to organize these keywords.

2. Written assignments 1. Transforming data structures in an object-oriented manner ' rational number ' (emphasis) Note: Attributes must be decorated as private

1.1 Your main code (need to show your school number and name in the program) and paste the program's git address.

1.2 Compare your code with the code of the course, what is the difference between object-oriented programming and process-oriented programming?

Splitting an event into multiple fragments and building a lot of letters to solve is process-oriented programming; an event is an object, and then it's wrapped up in an object in a variety of ways. This is object-oriented programming.

2. Constructors and initialization blocks

2.1 What is the use of the constructor with PTA 5 (constructor and ToString)? What are the features of its function format?

The constructor is in the following form:

Public person ()
{
System.out.println ("This is constructor");
System.out.println (name+ "," +age+ "," +gender+ "," +id ");

}
Public person (String name,int Age,boolean gender)
{
This.name=name;
This.age=age;
This.gender =gender;
}

By defining a constructor, we can assign an initial value to the class we define when we define the variable, and if it is not constructed, it is assigned the initial value directly with the default constructor.

The ToString function is in the following form:

Public String toString ()
{
return String.Format ("person [name=%s, age=%d, gender=%s, id=%s]", name,age,gender,id);
}

After the definition, this function helps us to output the variable, and if it is not defined, it uses the ToString function in the parent class or object class.

2.2 If a class does not write a constructor, does it have a constructor function? If a class has only a constructor with parameters, does it have a default constructor with no arguments?

There will be a constructor that will automatically generate a constructor with no parameters assigned to it, and if there is a constructor with parameters in a class, it will not have a default constructor with no parameters

2.3 Look at the source code of the string class, find out 3 constructors of the string class that can be understood, and use your own words to describe the differences between the 3 constructors.

public String() 

This string constructor allows you to create a new empty string for the value character array

public String(char value[])

This string constructor copies the string into a char array

String (byte[] bytes)

This string constructor constructs the string object by using byte

2.4 Combining the PTA (constructors and initialization blocks) illustrates the similarities and differences between the initialization block and the constructor. and explain, initialize block with constructor who executes first? What is the difference between an initialization block and a static initialization block, and who executes it first?

Initialization objects are implemented through initialization blocks and constructors, constructors initialize only internal objects, initialization blocks are initialized for all objects, and as soon as a new object is created, the initialization block begins to work, so the order of execution is the initialization block > constructor

Static initialization block is also a new object is executed once and only once, static initialization block first execution

3. Code Analysis: Math class

3.1 When using the method of the Java.lang.Math class, why do I not need to new a math object and then call the corresponding method on that object?

The functions of the math class are static, so users can call methods in math directly using the class name plus the method name, without creating an object with new

3.2 What error will be generated if new Math ()? Try reading the math class source code to analyze the reason.

Error generating ' The constructor math () is not visible ', meaning that the constructor math () is invisible

3.3 Further: What do you think the object needs to be new to use, and what method to invoke without having to create the corresponding object to use? (Key Check)

The object is instantiated with new, and the function can be called after it is instantiated. Calling static static methods can not create objects that can be used

4. Heavy-duty overload

4.1 What is an overload? What is a constructor overload? How can I distinguish two overloaded methods?

    • Overloading means that multiple methods have the same method name but different parameters, which can be different parameter types, different number of parameters, and different order of parameters. Only the return type is not overloaded, for example of the math class Max function overload, which is distinguished by the argument condition.

4.2 Examples of 1 method overloads in the Java.lang.Math class cited?
Static double abs (double A) is an example of overloading

5. Code reading: Finalfinal modified variables cannot be changed, why does the following code work? Final int[] numbs= {1,2,3,4,5}; NUMBS[2] = 1;

Numbs this array object is final, its references cannot be modified, and not the series of values that the reference points to cannot be modified. and if numbs = null; it will be an error.

6. Time-Date class in Java8: Write function public static Boolean Ismondaytofriday () function: Determine if today is Monday to Friday, return True, return false. The function is called in the main function, and if true, the "Weekday + Name Study number" is output, otherwise the output "Rest + Name Study number".

7. Encapsulation

7.1 In combination with PTA (SHAPE), please summarize in your own words what is the meaning of encapsulation in object-oriented? What are the benefits?

    • The object's data method is placed in the same class, and when the operation is performed, it is done by invoking the object's method, which greatly improves the readability

7.2 What are the keywords related to encapsulation?

    • Private privately owned
    • Default defaults for
    • Protected defended the
    • public.
8. Pair programming Practice (unfinished, 0 points) find a level similar to the students to complete 1-2 questions. Before you start programming, you can discuss the content first. Write the experience report, including the following: 1. Name of the other party. 2. The completed topic. 3. Impressions. 4. Photos (last time many students did not post photos, please affix)

Party Name: Ma Yulan
Title: PTA 7-1 jmu-java-03 Object-oriented foundation -01-constructors and ToString
Feelings: In the experiment class, the teacher gave the idea of thinking, and then each have different ideas, pairing programming let oneself know others ' ideas and their own have a very big difference, there are many places worth learning from

3. Code cloud and PTA3.1. Codes Cloud Code submission record
在码云的项目中,依次选择“统计-Commits历史-设置时间段”, 然后搜索并

3.2 PTA Problem Set completion diagram needs to have two pictures (1. Ranking chart. 2.PTA Submission list diagram)

3.3 Count the amount of code completed this week

The weekly code statistics need to be fused into a single table, using the-history parameters of the latest version of the Code statistics tool, which can be found in the project Wiki address for detailed usage. The table looks like this:

Week Time Total code Amount New Code Volume total number of files number of new files
2 330 330 5 5
3 652 322 11 6

201621123030 Java Programming 3rd week of study summary

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.