20172325 2016-2017-2 "Java Program design" Fourth week study summary textbook study summary
1. A further understanding of the definition and properties of classes, objects, declaration variables
2. Learn how to write a class and apply it to the required program
3. Learn the concepts and differences of formal parameters and arguments
4. The role and use of modifiers, such as public and private
5. Learn static classes, such as static and static variables
6. The role and application of encapsulation
7. Necessary steps to be made in object-oriented programming, including requirements, design, implementation, and testing
8. Further understanding of the enumeration classes
9. Learned the method overloads in the calling method
10.UML class diagrams contain content and functions that help to understand the class
1.In 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.
2.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".
3.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.
4.What happens if 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.
5.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.
6.Unlike the String class where you must pass a message to an object (instance) of the class, as in X.length (), in order To use 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.
-
7.Which of the following would yield a pseudorandom number in the range [ -5, +5] Given the following:
Random ge n = new Random ();
A. Gen.nextfloat () * 5
B. gen.nextfloat () * 10-5
C. gen.nextfloat () * 5-10
D. gen.nextint () * 10 -5
E. Gen.nextint 5
Gen.nextint (10)-5 The result is -5,-4,-3,-2,-1,0,1,2,3,4, not the problem, it is only a few numbers rather than a range of values. Nextfloat, however, generates pseudo-random numbers in the range [0,1], multiplied by a 10 yield between 0 and 10, minus 5, to get the result.
8.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 objects
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
Both of these statements are legitimate java. S1 is a string reference that is initialized to the string "testing123". S2 is a string reference that is initialized to the string "Test 123". Note the spaces between "test" and "123". So the two strings are not equal.
9.An "Alias" (alias) is when
A. Different reference variables refer to the same physical object
B. Different numeric variables refer to the same physical object
C. Different numeric variables contain identical values
D. Both variables have the same names
E. None of the above
When there are two or more references to the same physical object, an "alias" appears, so that the object can be read/written/modified by following any reference
10.The String class ' CompareTo method
A. Compares the string in a case-independent manner (independent way)
E I Yields (rate of return) 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 the two string is exactly the same, then it has a value of 0.
11.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.
12.If you need to import not only the top-level of a package, but all its secondary levels as well, you should write:impo RT 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.
13.You may use the String replace () method to remove characters from a string.
A true
B false
The replace () method replaces only a single character with another single character. The replace () method does not add or remove characters from the string; The string length remains the same
14.All the methods in the Math class is declared to be static.
A true
B false
Mathematical methods are often designed to be useful in arithmetic expressions, so no instances are required to use them. This is achieved by ensuring that all mathematical methods are static.
15.The Advantage (s) of the Random class ' pseudo-random number generators, compared to the Math.random method, was that
A. You may create several random number generators
B. The generators in Random is more efficient than the one in Math.random
C. You can generate random ints, floats, and ints within a range
D. You can initialize and reinitialize Random generators
E. All but answer B
The efficiency of all random number generators is the same. Random generators are better than mathematical advantages. All other attributes are included randomly.
16.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
By one or more mathematical methods, the "%" symbol in the programmer's hand is truncated at the end of the display, not the beginning.