1. Summary of this week's study
Learning to object-oriented, will learn a lot of fragmented concepts and knowledge. Try to use mind mapping to organize these fragmented concepts and knowledge. Use a pen or paper or the tools below to draw the points of knowledge you learned this week. or photo upload.
2. Written work
Code Reading
PublicClassTest1 {Privateint i =1;This line cannot be modifiedPrivatestatic int j = 2; public static void main (string[] args) {Geti (); TEST1GETJ (); } public static void geti ( Out.println (i); } public static void GETJ ( Out.println (j); }}
Can the above code be compiled and passed? Where does it go wrong? Trying to correct?
If you create 3 Test1 objects, there are several I in memory, a few J? Please analyze the reason?
- The above code can not be compiled through, access to I, the system is prompted to change the static variable I to static to be accessed, TEXT1GETJ () will also have an error, I tried to use get and set or error, the system is still prompted to change I to static variable is not OK, give up.
- If you create 3 Text1 objects, there will be 3 i,1 j in memory. Because I am non-static each creation of a new object will occupy a memory, and J is static only consumes one memory.
What is the use of constructors? What is the writing format? 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?
- The constructor is used to initialize an object when it is created, and is written in the public class name () {}.
- If a class does not write a constructor, it has a default constructor.
- If a class has only a constructor with parameters, it does not have a default constructor with no arguments.
java.lang.Math
when using a function of a class, why don't you need new? What happens if new Math () generates errors? Analyze the cause?
- Because the methods and properties in the Java.lang.Math class are static, the math class itself is not static and does not require new.
What is overloading? What is a constructor overload? In the Java.lang.Math class cited out 1 examples of function overloading? How can I distinguish between two overloaded functions?
- Overloading is the way multiple methods use a method name, but the number or type of arguments is different, but their role is generally the same.
- Constructor overloading to create multiple constructors for a class. Each constructor must have its own unique argument list.
- Two overloaded functions are distinguished by different parameters, refer to: http://blog.csdn.net/pony_maggie/article/details/43925705
The final modified variable cannot be changed, why does the following code work?
final int[] NUMBS= {1,2,3,4,5};NUMBS[2] = 1;
Because the final decorated reference type variable is assigned a value, you cannot point to another object. The value of the property that it points to can be changed.
6. Read the code Employeetest.java and answer:
Why are their properties private? What are the benefits of this design?
This is not an insider's access, and the benefit is that important information is not compromised.
Employee
add an parameterless constructor for the class, call its parameter constructor, set name to 雇员1
salary, 3000
and hireday for the month and day 2017年3月5日
. (Paste code)
Public Employee() {
This ("Employee 1",3,5);
}
Employee
Add an additional parameter constructor to the class, with only name and Salary,hideday as the current date . (Paste code)
Public Employee(String name, double salary)
{
< Span class= "hljs-function" > hireday= (Date) calendar.gettime ();
< Span class= "hljs-function" > calendar.getinstance (). get (Calendar,year);
< Span class= "hljs-function" > calendar.getinstance (). Get (Calendar,month) +1;
< Span class= "hljs-function" > calendar.getinstance (). get (Calendar,day_of_month);
}
7. Writing functionspublic static boolean isMondayToFriday()
Function: Judging today if it is Monday to Friday, direct output such as "work Time" and return true, otherwise output "break time".
Tip: Use LocalDateTime, DayOfWeek
References:
JAVA 8: Robust, easy-to-use time-date api-importnew.pdf
Java8datetimetest.java
8. Runnable Jar (optional)
The programs we've written before must either open Eclipse or copy the appropriate. class file to run under the command line, and if the. class file is large and has a package name in the file, you need to copy the complete directory structure and file to run. Now you want to hit the Java file in the Eclipse project into a runnable jar package that runs directly on the command line. Retrofit topic 7 to receive parameters from the command line, parameters for 年-月- 日
, make items into jar packages, and then run through the command line java -jar
, and. The reference file is as follows:
Eclipse generates runnable jar
3. Code Cloud Codes Submission record
- In the Code cloud Project, select statistics-commits history-set time period, and then search for and
4. PTA Experiment
- Topic set: jmu-java-03-Object-oriented 1-basic-encapsulation inheritance in programming (5-1, 5-2, 5-3)
- 5-1 is completed in class, because there is a place to forget to enter, resulting in the output has been only two lines, ask the teacher after the answer.
Reference files:
3rd Week Work Reference document
201521123032 Java Programming 3rd week of study summary