20172330 2017-2018-1 "Java Programming" Fourth Week study summary

Source: Internet
Author: User
Tags aliases first string

20172330 2017-2018-1 "Java Program design" Fourth week study summary textbook study summary

This week's content is more and more complex, including chapters fourth and seventh.

    • The fourth chapter introduces the definition and concept of class structure, and gives us a lot of examples to show the method and application of the custom class, and discusses the structure and use of the method definition: Including return statement, parameter, local data and so on.
    • The main content of the seventh chapter is object-oriented design. Through the introduction of books, we discuss the main problems of object-oriented software design, understand the technology of determining the classes and objects required by the program, discuss the relationship between classes, and learn the effect of static modifier on methods and data and the enumerator class. Finally, the method of establishing the formal object interface is studied.

      Problems in teaching materials learning and the solving process
    • Question 1: What does the writing class consist of, and what does each part do?
    • Problem 1 Solution: I don't quite understand, presumably, that there are two things in the writing class that roughly play a key role: constructors and methods. They can make this class effective and can be used in programs.

    • Issue 2: The difference between a static variable and an instance variable
    • Problem 2 Solution: After reviewing the data, we found
      Instance variables must be created before they can be used by the object, and static variables can be referenced directly using the class name. Just like static methods can be called directly through the class name.
      Static variables are common to all objects, one object changes its value, and the other object gets its value, resulting in a changed value;
      Instance variables are private to each object, one object changes its value, does not affect the results of other objects ' values, and other objects will still get the value that the instance variable was given at the beginning.

Problems in code debugging and the resolution process
    • Question 1: In the writing class homework and pp47, I wrote the book Class no problem, the operation is also successful, but in the Java compilation is displayed when the null, I changed several ways, regardless of whether it is ToString or set.

    • Problem 1 Solution: Then under the guidance of seniors to find that I write the class and the method of the definition of the name is the same cause the error final output null, This is changed to this. By the way, I see the textbook. 7.4.4 for this reference, this reference can allow an object to refer to itself, which solves my problem, and the This reference can also be cited for the currently running object.

    • Question 2: When you javac your well-made class to your bin file, you can test your text file to show that the class is not found, and there will be problems with javac-d.
    • Problem 2 Solution: Then you have to put him in a folder and your class will be effective.

Code Hosting


Last week's summary of the wrong quiz
  • 1In Java A variable may contain
    A a value or a reference
    B a Package
    C a method
    D a class
    E any of the above
    In Java, a variable can contain only one value or a reference. So you should choose a.

  • If variables contain aliases of the same object then
    A the object may be modified using either Alias
    B The object cannot be modified unless there's but a single reference to it
    C A third alias is created if/when the object is modified
    D the object would become an "orphan" if both variables is set to NULL
    E answers A and D are correct
    objects can be modified using aliases, and if all two variables are set to NULL, then the object becomes an "orphan".

  • Which properties is true of String objects?
    A their lengths never change
    B the shortest string has zero length
    C individual characters within a String may be changed using the Replace method
    D the index of the first character in a string is one
    E only A and B is true
    Their length will never change, the shortest string length is zero. The string is immutable. This means that once a string object is created, it cannot be changed. Therefore, the length of the string does not change after it is created. The shortest length string is "", and there are no characters between the quotation marks, so the length is zero.

  • What happens if do attempt to use a variable before it have been initialized?
    A syntax error generated by the compiler
    B A Runtime error may occur during execution
    C A "garbage" or "uninitialized" value would be used in the computation
    D a value of zero is used if A variable have not been initialized
    E Answers A and B are correct
    The compiler has been able to detect an uninitialized variable several times, in which case a syntax error is generated. If the compiler uses escape detection, a run-time error occurs when it is used.

  • What is the function of the dot operator?
    A It serves to separate the integer portion from the fractional portion of a floating point number
    B It allows one to access the data within an object when given a reference to the object
    C It allows one to invoke a method within a object when given a reference to the object
    D It is used-terminate commands (much as a period terminates a sentence in 中文版)
    E Both B and C are correct
    The function of the dot operator is that it allows the data in the object to be accessed when a reference is given to the object, which allows the method to be called in the object when a reference is given to the object. So this question should be e-chosen.

  • Unlike the String class where you must pass a message to an object (instance) of the class, as in X.length (), in order to With the Math class, you pass messages directly to the class name, as in Math.Abs () or math.sqrt ().
    A. True
    B. False
    The math class uses a method called a static method (or class method) that is called by passing the message directly to the class name itself rather than to the object of the class.

  • Which of the following would yield a pseudorandom number in the range [ -5, +5) given the following:
    Random Gen = new Random ();
    A gen.nextfloat () * 5
    B gen.nextfloat () * 10-5
    C gen.nextfloat () * 5-10
    D gen.nextint () * 10-5
    E Gen.nextint (10)-5
    The question is float, which I didn't notice.

  • Consider the following-lines of code. What can I say about S1 and S2?
    String S1 = "testing" + "123";
    String s2 = new String ("Testing 123");
    A S1 and S2 is both references to the same String object
    B the line declaring S2 is legal Java; The line declaring S1 would produce a syntax error
    C S1 and S2 is both references to different String objects
    D S1 and S2 would compare "equal"
    E none of the above
    S1 and S2 are references to different objects, regardless of whether S1 and S2 correspond to equal variables. So this problem should be selected C.

  • The String class ' CompareTo method
    A compares the string in a case-independent manner
    B yields true or false
    C yields 0 if the strings is identical
    D returns 1 if the first string comes lexically before the second string
    E none of the above
    If two strings are the same in the CompareTo method of the string class, 0 is obtained. Rather than right and wrong.

  • The advantages of the DecimalFormat class compared with the NumberFormat class include
    A precise control over the number of digits to be displayed
    B control over the presence of a leading zero
    C the ability to truncate values rather than to round them
    D the ability to display a percent automatically at the beginning of the display
    E only A and B
    The advantage of pseudo-random number generators with respect to math.random is that you can create several random number generators that generate random int,floats and ints within a range. So A and B should be included.

  • If you need to import not only the top-level of a package, but all its secondary levels as well, you should write:import Package. .;
    A true
    B false
    If you need to import not only the top level of the package, but also all the secondary levels, you should write: Import the package. ; (false); Import package.

    Other (sentiment, thinking, etc., optional)

This week's task volume is very large, and a lot of things need to write their own class and debugging, feel that there are still a lot of deficiencies in the existence of the idea or to take the book on the example of serious knocks to know, and then to do after class exercises.

Learning progress Bar
Code lines (new/cumulative) Blog volume (new/cumulative) Learning Time (new/cumulative) important growth
Goal 5000 rows 30 Articles 400 hours
First week 180/180 2/2 20/25
Second week 312/414 2/4 20/45
Third week 557/971 2/6 25/70
Week Four 1217/2242 2/8 44/114
    • Planned study time: 44 hours

    • Actual learning time: 25 hours

Resources
    • (http://www.cnblogs.com/rocedu/p/5182332.html)

20172330 2017-2018-1 "Java Programming" Fourth Week 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.