20165312 2017-2018-2 "Java Programming" 7th Week study Summary

Source: Internet
Author: User
Tags shallow copy time and date


20165312 2017-2018-2 "Java program Design" 7th Week study Summary of the last week to test the leakage of the vacancy


Overall, I think last week two tests are very difficult, do the test also took a long time, I think because the knowledge of the book a lot, I have not understood well, so still want to read more well, a lot of books on the knowledge points omitted or read once forgotten.


Week five test (ch08 ch10)
    • The following statement about the inner class is correct ()


A. No other class can declare an object with an inner class of a class.



B. The name format of the internal class bytecode file is "outer nested class name $ internal
The class name.



C. The class body of an inner class can declare class variables and class methods.



D. The inner class is in the member position, so it can be decorated by private.



Answer: ABD (C-item error is not allowed in the class body of the inner class to declare class variables and class methods.) )


    • If the JVM is beyond its operational capacity, such as "byte[" Arr=new byte[1024 600]; " Throws a Java.lang.OutOfMemoryError exception.


A. True



B. False



Answer: B (for serious errors, described by the error class, and for non-serious problems, it is described by the exception class.) )


    • The following statement about exception handling is correct ()


A. Once the try section throws an exception object, the try section immediately ends execution and turns to the corresponding catch section.



B. A catch code block defines code that is bound to execute, which is typically used to close a resource.



C. The Try-catch statement can consist of several catch, dealing with the exception that occurs.



D. Exceptions listed in the catch brackets must not have an inheritance relationship, or a compilation error will occur.



Answer: ACD (item B: The finally code block defines code that is bound to execute, which is typically used to close a resource.) For the exception of the part, if not done finally, then the program is flawed, each call to the resources and then release the resources is necessary, otherwise the operating pressure will be particularly large. )


    • The object of the file class is primarily used to obtain information about the files themselves, such as reading and writing to the file, obtaining the directory where the file resides, the length of the file, or the file read and write permissions.


A. True



B. False



Answer: B (the file class does not involve read and write operations on files.) )


    • The following is the file class constructor method ()


A. File (file parent, String child)



B. File (String pathname)



C. File (string parent, String child)



D. File (URI Uri)



Answer: ABCD


    • The following is a description of the common methods of the file class, which is wrong ()


A.public long length(): Get file length



B.public int hashCode(): Calculates the hash code for this file



C.public String toString(): Returns the path name string for this abstract pathname



D.public Boolean isFile(): Determines whether a file is a normal file, not a directory



Answer: B (public int hashCode(): Computes the hash code for this abstract pathname.) )


    • The InputStream class inherits from FileInputStream and can read the file in bytes.


A. True



B. False



Answer: B (InputStream is the parent class)


    • The following statement is correct ()


A. You can use the FileOutputStream class to write to a file.



B. The FileOutputStream class is constructed by FileOutputStream (file file), FileOutputStream (String name), FileOutputStream (file file, Boolean append) and so on.



C. For the FileOutputStream (String name) method, the file specified by the parameter name is called the source of the output stream.



D. If the output stream points to a file that already exists, the output stream refreshes the file so that the length of the file is 0.



Answer: ABD (the file specified in the parameter name in C is called the destination of the output stream. )


    • The following statements about BufferedReader and BufferedWriter, the wrong is ()


A. You can read a line of text by calling the ReadLine () method of the BufferedReader object.



B. BufferedReader has a method for writing a return line character to a file: NewLine ().



C. When the BufferedWriter stream calls flush () to flush the cache or when the close () method is called off, the cached content is written to the destination even if the cache does not overflow.



D. You can connect the BufferedWriter stream with the FileWriter stream, and then use the BufferedWriter stream to write the data to the destination.



Answer: B


    • The following statement about the scanner class, right is ()


A. Using scanner and regular expressions to parse a file is characterized by a space exchange for time.



B. When parsing a word that is not a numeric word, calling the Nextint () or nextdouble () method will occur inputmismatchexception exception.



C. Create a scanner object that points to the file you want to parse, and you can use the Usedelimiter method to specify a regular expression as a split mark.



D. Regular expression \b (?! ABC) \w) +\b can be used to match words that do not contain ABC.



Answer: BCD (a uses scanner and regular expressions to parse a file is characterized by time for space)


    • Which of the following statements is true? ( )


A. An exception may have occurred creating the file object.



B. The Bufferedread stream can point to the FileInputStream stream.



C. The Bufferedwrite stream can point to the FileWrite stream.



D. Once the Randomaccessfile stream points to the file, it refreshes the file.



Answer: C


Six weeks of testing (ch08 ch15)
    • What is the feature of the list interface? ()


A. Duplicate elements are not allowed, elements have no order



B. Duplicate elements are not allowed, elements are in order



C. Allow repeating elements, elements in order



D. Allow repeating elements, elements without order



Answer: C


    • The following about LinkedList


A. Public E GetLast () returns the last element of this list. If this list is empty, Nosuchelementexception is thrown.



B. public void AddFirst (e e) Inserts the specified element at the beginning of this list. E is the element to be added.



C. The public boolean add (e E) is equivalent to AddLast (e).



D. public boolean remove (Object O) Overrides class Abstractcollection



Answer: ABCD (through the query API)


    • The following about HashMap


A. public boolean IsEmpty () returns True if this mapping does not contain a key-value mapping relationship.



B. Public V get (Object key) returns the value mapped by the specified key, or throws an exception if the mapping does not contain a mapping relationship for the key.



C. Public V put (K key, V value) associates the specified value with the specified key in this mapping. If the map previously contained a mapping of the key, the values defined first prevail.



D. Public Object Clone () returns a shallow copy of this HASHMAP instance: The key and the value itself are not copied.



Answer: AD (via the query API: B: If this map does not contain a mapping relationship for the key, NULL is returned.) C: If the map previously contained a mapping of the key, the old value is replaced)


    • The following about TreeSet


E I The public boolean add (e E) Adds the specified element to this set. If this set already contains such an element, the call does not change this set and returns FALSE.



C. public boolean addall (collection<? extends e> c) adds all the elements in the specified Collection to this set. Returns True if this set is changed because of a call.



D. Public e Lower (e e) returns the largest element in this set that is strictly less than the given element, or null if no such element exists.



Answer: BCD (Item A: ClassCastException exception is thrown if the specified object cannot be compared to the current element in the set. )


    • The expression with the following value is not true is ()


A. "John" = "John"



E I "John". Equals ("John")



C. "John" = "John"



D. "John". Equals (New String ("John"))



Answer: C


    • Constructs a new string using the constructor method String (byte[] bytes, int offset, int length, Charset Charset), by decoding the specified byte subarray with the specified Charset. Where the offset parameter is the index of the first character of the Subarray, and the count parameter specifies the length of the sub-array.


A. True



B. False



Answer: A


    • The length () method in the string class is used to get the lengths of a string object's character sequence, in bytes.


A. True



B. False



Answer: B


    • public boolean startsWith (string prefix) method that throws an exception if the argument is an empty string.


A. True



B. False



Answer: B


    • The following statement about the public int compareTo (String anotherstring) is correct ()


A. Compares two strings in a dictionary order. The comparison is based on the Unicode values of the individual characters in the string.



B. If this string object is in the dictionary order before the parameter string, the comparison result is a positive integer.



C. If they have different characters at one or more index positions, assuming that k is the minimum value for such an index, COMPARETO returns the difference between the two strings at position K at two char values, which is the value: This.charat (k)-anotherstring.charat (k)



D. If there are no different index positions for the characters, the dictionary order of shorter strings precedes the longer strings. In this case, COMPARETO returns the difference between the two string lengths



E. CompareTo returns 0 only if the method equals (Object) returns True.



Answer: ACDE (b returns a negative integer)


    • The following statement about the substring method is correct ()


A. public string substring (int beginindex) returns a substring starting at the character at the specified index until the end of this string.



B. The public string substring (int beginindex, int endIndex) substring starts at the specified beginindex until the character at the index EndIndex.



C. "Emptiness". Substring (9) The return value is "".



D. "Smiles". Substring (1, 5) The return value is "mile".



E. If Beginindex is greater than endIndex, then substring (int beginindex, int endIndex) returns-1.



Answer: ACD (item B: The character at index EndIndex-1. E entry: Throws a Indexoutofboundsexception exception. )


    • The following statement is wrong ()


A. The data class in the Java.util package overrides the ToString () method.



B. Both arrays and point inherit the ToString method.



C. The place where the x.tostring () method is called can be replaced with "" +x.



D. Definition int[] Numbers = {1, 2, 3}; String S1 = "" +numbers;, then System.out.println (S1); The ToString method is called to output the array.



Answer: D (item D: If you want to print an array, the array must call the static method arrays.tostring, that is, string S1 = "" +numbers in the above program; change to string S1 = arrays.tostring (Numbers);. If you want to print a multidimensional array, you need to call the Arrays.deeptostring method. )


    • The following statements about strings and character arrays, byte arrays, are correct ()


A. The return value of getChars (int srcbegin, int srcend, char[] DST, int dstbegin) method is empty.



E I Srcend is the index of the last character in the string to copy.



C. A Indexoutofboundsexception exception is thrown when Srcbegin is greater than srcend.



D. The characters to be copied to the DST sub-array start at index Dstbegin and end at index Dstbegin + (srcend-srcbegin)-1



Answer: ACD (item B: Srcend is the index after the last character in the string to be copied. )


    • The following statement about regular expressions is correct ()


A. \ba\w*\b matches a word that begins with the letter A



E I \d+ matches 1 or more consecutive digits.



C. \b\w{6}\b matches 6 or more characters.



D. [0-9] The meaning of the representation is exactly the same as the \d: a number



E. \s+ matches a string that does not contain whitespace characters.



F. (\d{1,3}.) {3}\d{1,3} is used to match an IP address.



Answer: Abde (c: \b\w{6}\b matches exactly 6 characters in a word. F: Each number in an IP address cannot be greater than 255, and the expression ignores this constraint. The Right thing is ((2[0-4]\d|25[0-5]|[ 01]?\d\d?).) {3} (2[0-4]\d|25[0-5]| [01]?\d\d?]. )


    • The following statements about the date class and the Calendar class are wrong ()


A. You can use the static method of the system class public long
Currenttimemillis () Gets the current time of the system.



B. The public boolean equals (Object obj) method of the date class overrides equals in the class Object.



C. You can use the After () method if you compare the time and date of the two calendar. The After () return value is a Boolean type, which is equivalent to CompareTo (when) <0.



D. Use the static method of the Calendar class getinstance () to initialize a calendar object.
Test Center: C: It is equivalent to CompareTo (when) >0.



Answer: C


    • The following statement is correct ()


A. Before Java 8, the date was calculated using the DateFormat class.



B. It takes time for humans to understand, and it is recommended to use ToString () of the date class.



C. Now the international standard Time is GMT.



D. The new Date (System.currenttimemillis ()) is equivalent to the new date ()



Answer: D


    • The following statement about the math class is correct ()


A. public static double CBRT (double A) returns the cube root of a double value. If the argument is Nan, the result is Nan.



B. public static double cos (double A) returns the trigonometric cosine of the angle. If the argument is Nan or infinity, the result is Nan.



C. public static double floor (double a) returns the largest (closest to positive infinity) Double value, which is less than or equal to the parameter and equals an integer. If the argument is Nan or infinity, the result is Nan.



D. public static double log10 (double A) returns the logarithm of the base 10 of the double value. If the parameter is positive 0 or minus 0, then the result is negative infinity.



Answer: ABD (c: If the argument is NaN, infinity, positive 0, or minus 0, the result is the same as the parameter.) )


    • Which of the following expressions is correct (no compile errors)? ( )


A. int m =float.parsefloat ("567");



B. int m =short.parseshort ("567")



C. byte M =integer.parseint ("2");



D. float m =float.parsedouble ("2.9")



Answer: C


    • Which of the following statements is true for the following code? ( )

      public class E {
        public static void main (String args[]) {
      String s1 = args[1];
      String s2 = args[2];
      String s3 = args[3];
      System.out.println(s3); 
        }
      }


A. A compilation error occurred on the program.



B. No compile error, execute program at command line: "Java E I love this game", program output this.



C. No compile error, execute program at command line: "Java E let us go", program no run exception.



D. No compile error, execute program at command line: "java E 0 1 2 3 4 5 6 7 8 9" program output 3.



Answer: D


Second, this week to learn to summarize the problems encountered and solutions
    • The link in the blog failed, I downloaded the xampp online, and according to the teacher's blog to learn the database.







    • When configuring driver Mysql-connector-java-5.1.41-bin.jar in Idea, find Mysql-connector-java-5.1.41-bin.jar by adding Junit.jar in similar unit tests, but I didn't find it.
    • Workaround:
      • Download Mysql-connector-java-5.1.46.zip
      • Unpack the Tarball
      • File->projeat Structure
      • Click Dependencies, click on the top right +-JARs to find the location of the decompression package-> Mysql-connector-java-5.1.41-bin.jar
    • According to the resources on the blue ink cloud download WHITESTARUML, based on the use of STARUML drawing class to learn how to draw UML
    • There was a problem running the test class Messagedaodemo.java





Then according to the error hint, found that the time code problem, the class name of the case is wrong.


Summary of Knowledge points
    • Connecting to a database
    • Criteria and sort query:
      • where child statementselect 字段 from 表名 where 条件
    • Update, add, and delete operations
      • Update
        update 表 set 字段 = 新值 where <条件子句>
      • Add to
        insert into 表(字段列表) values (对应的具体的记录)Orinsert into 表 values (对应的具体的记录)
      • Deletedelete from 表名 where <条件子句>
    • Using Preprocessing statements
    • Transaction
      • setAutoCommit(booean b): method to turn off autocommit mode
      • commit(): Method Handles Transaction
      • rollback(): Method failed to process transaction
Code Link code line number:





20165312 2017-2018-2 "Java Programming" 7th Week study Summary


Related Article

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.