CCAT exam sorting JAVA test questions

The compiled CCAT study test JAVA test questions are as follows:

1. Fill in the blanks (2 points for each blank, 20 points in total).

1. The CSS style for converting an inline label into a block label is display:block.

2. The value of the expression 19/3*3+19%3 is 19.

3. staticcalled static variables modified variables, he can pass 对象and 类名access in two ways.

4. If a method is modified as a 重写 / finalmethod, this method cannot be overridden.

5. The output of the following code is:ABC

public class Test {
    
    
    
    public static void main(String[] args) {
    
    
        LinkedList list = new LinkedList();
        list.add("A");
        list.add("B");
        list.add("C");
        list.add("D");
        list.add("E");
        list.add("F");
        for (int i = 0; i < list.size(); i++) {
    
    
            //poll 获取并移除列表的头
            System.out.println(list.poll());  
        }
    }
}
  1. The values ​​of I and J after output are 100, respectively 0.
public class Test {
    
    

    public static void main(String[] args) {
    
    
        int j = 0;
        int i = 0;
        for(;i<100; i++){
    
    
            j = j++;
        }
        System.out.println(i);
        System.out.println(j);
    }
}
  1. The output result of analyzing the following java code is 7
public class Point {
    
    
    int x,y;
    Point(int x,int y){
    
    
        this.x=x;
        this.y=y;
    }
    public static void main(String[] args){
    
    
        Point pt1,pt2;
        pt1=new Point (3,3);
        pt2=new Point(4,4);
        System.out.print(pt1.x+pt2.x);
    }
}

2. Multiple-choice questions (20 sub-questions for this big question, 2 points for each sub-question. 40 points total).

  1. The Tomcat port number can be configured by modifying Athe ( A) node of the ( ) file .
    A:server.xml
    B:web.xml
    C:server.xml
    D:web.xml

  2. In Java, about classes and objects, which of the following statements is correct is ( A).
    A: A class defines a conceptual model, and an object is a real entity
    B: An object defines a conceptual model, and a class is a real entity
    C: A class is a subset of an object
    D: An object is a subset of a class

  3. In Java, the Statement interface contains many basic database operation methods. The following statement is incorrect ( B).
    A: ResultSet executeQuery(String sql): can execute SQL statements and obtain ResultSet objects
    B: boolean executeUpdate(String sql): can perform operations such as insert, delete, update, etc.
    C: boolean execute(String sql): can execute any SQL statement, Indicates whether the SQL statement is executed successfully
    D:int executeUpdate(String sql): Insert, delete, update and other operations can be performed

  4. If a Java class contains the following main function, the result of compiling and running this class is ( C).
    A: A compilation error appears in the first line
    B: A compilation error appears in the second line
    C: A compilation error appears in the third line
    D: The program runs correctly, the output result is: a+b=17.2

public static void main(String args[]) {
    
    
    double a = 10.2;          //第1行
    int b = 7, result;        //第2行
    result = a + b;           //第3行
    System.out.println("a+b=" + result);
}
  1. In Java, the incorrect statement of the following options is ( D).
    A: java.util.Random class is used to generate random numbers
    B: nextInt() method of java.util.Random class returns a uniformly distributed int value in this random generator sequence
    C: nextInt( of java.util.Random class The) method returns an int value uniformly distributed between 0 (inclusive) and the specified value (exclusive) in this random generator sequence.
    D: Execution code: System.out.println(new java.util.Random().nextInt (10)+1); the output value cannot be 10

  2. There is the following JavaScript code, after the page runs, output ( C).
    A:abc
    B:0
    C:NaN
    D: The page reports an error and cannot run

<script type=“text/javascript”>
var x=parseInt("abc"); 
document.write(x);
</script>  
  1. On the JSP page, the following ( C) statement can introduce the class java.util.Date to the JSP page.
    A:<% page import =“java.util.Date” %>
    B:<%@ page import =“java.util.Date” @%>
    C:<%@ page import =“java.util.Date”% >
    D:<%@ import =“java.util.Date” %>

  2. In JSP, the following description about Cookie is wrong ( C).
    A: Cookie is to save user-related data on the client
    B: Cookie can save string
    C: Cookie can save any type of object
    D: It is not recommended to save important or sensitive content in Cookie

  3. In JSP, the following statements about forwarding and redirection are correct ( B D).
    A: Regardless of forwarding or redirection, the new URL address is displayed in the client browser.
    B: Redirection can be understood as the browser submits at least two requests. It plays a role on the client side, by requesting a new address to achieve page redirection
    C: forwarding and redirection can share data within the request range
    D: forwarding can be achieved through the getRequestDispatcher().forward() method of the request. Its function is to realize the sharing of request data during the interaction of multiple pages

  4. Regarding HTML Ajax workflow, the correct statement is ( B).
    A: The server side generates js events.
    B: The XMLHttpRequest object must be created.
    C: After the server side processes the request, it must be returned in plain text.
    D: The XMLHttpRequest object has 4 response states

  5. Analyze the following program carefully, the number of cycles of while is ( D)
    A, 1 B, 10 C, 6 D, an infinite loop, and the number cannot be determined

	int i=0; 
	while(i<10) {
    
    
		if(i<1) continue;
		if(i==5) break; i++; 
	}
  1. In order to distinguish different methods with the same name in overloaded polymorphism, it is required: ( B).
    A) Different parameter names B) Different formal parameter lists
    C) Different return value types D) Options A, B, and C are correct

  2. Which of the following is not a subinterface of Collection? ( C).
    A) List B) Set C) Map D) SortedSet

  3. Which of the following statements are correct ( C)
    A. The constructor in the class cannot be omitted
    B. The constructor must have the same name as the class, but the method cannot have the same name as the class
    C. The constructor is executed when an object is new
    D. A class can only define one constructor

  4. The meaning of CSS style background-position: 5px -10px is ( D).
    A. The background image is offset by 5px to the left and 10px downward
    . B. The background image is offset by 5px to the left and 10px upwards
    . C. The background image is offset by 5px to the right and 10px downward
    . D.The background image is offset 5px to the right and 10px up

  5. Which of the following descriptions is correct? D
    A. Multithreading is unique to the Java language
    B. Multi-threading requires multiple CPUs
    C. Multi-threading requires a computer to have a single CPU
    D. Java language supports multithreading

  6. What is the execution result of the following code? C
    A. The large.txt file is created on the local hard disk
    B. It fails on Unix systems because the path separator is incorrect
    . C. The large.txt file is not created on the local hard disk
    D. If the large.txt file already exists, an exception is thrown

public class Example {
    
    
 public static void main(String[] args) {
    
    
  File f = new File("c:\\large.txt");
 }
  1. Please select the following code operation result? ( C)
    A, 0
    B, 1
    C, 2
    D, 3
public class test {
    
    
public static void main(String args[]) {
    
    
int i=0, j=2;
do {
    
    
i=++i;
j--;
} while(j>0);
System.out.println(i);
}
}
  1. Please select the following code running result? ( A)
    A, compile error
    B, run error
    C, null
    D, ""
Character c1=-13;
Character c2=-13;
System.out.println("c1==c2"+(c1==c2));
  1. Custom class Account, create this type of object account, which option can not return the Class object correctly? ( A)
    A, account.class
    B, Account.class
    C, account.getClass()
    D, Class.forName("Account")

3. Essay questions (40 points in total).

  1. What are the similarities and differences between abstract class and interface? (6 points)
    Answer:抽象类和接口都不能够实例化,但可以定义抽象类和接口类型的引用。一个类如果继承了某个抽象类或者实现了某个接口都需要对其中的抽象方法全部进行实现,否则该类仍然需要被声明为抽象类。接口比抽象类更加抽象,因为抽象类中可以定义构造器,可以有抽象方法和具体方法,而接口中不能定义构造器而且其中的方法全部都是抽象方法。抽象类中的成员可以是private、默认、protected、public的,而接口中的成员全都是public的。抽象类中可以定义成员变量,而接口中定义的成员变量实际上都是常量。有抽象方法的类必须被声明为抽象类,而抽象类未必要有抽象方法。
  2. What are the characteristics of the three interfaces of List, Map, and Set when accessing elements? (6 points)
    Answer:List以特定索引来存取元素,可以有重复元素。Set不能存放重复元素(用对象的equals()方法来区分元素是否重复)。Map保存键值对(key-value pair)映射,映射关系可以是一对一或多对一。Set和Map容器都有基于哈希存储和排序树的两种实现版本,基于哈希存储的版本理论存取时间复杂度为O(1),而基于排序树版本的实现在插入或删除元素时会按照元素或元素的键(key)构成排序树从而达到排序和去重的效果。
  3. What is the difference between Statement and PreparedStatement? Which is better? (6 points)
    Answer:与Statement相比,①PreparedStatement接口代表预编译的语句,它主要的优势在于可以减少SQL的编译错误并增加SQL的安全性(减少SQL注射攻击的可能性);②PreparedStatement中的SQL语句是可以带参数的,避免了用字符串连接拼接SQL语句的麻烦和不安全;③当批量处理SQL或频繁执行相同的查询时,PreparedStatement有明显的性能上的优势,由于数据库可以将编译优化后的SQL语句缓存起来,下次执行相同结构的语句时就会很快(不用再次编译和生成执行计划)。 补充:为了提供对存储过程的调用,JDBC API中还提供了CallableStatement接口。存储过程(Stored Procedure)是数据库中一组为了完成特定功能的SQL语句的集合,经编译后存储在数据库中,用户通过指定存储过程的名字并给出参数(如果该存储过程带有参数)来执行它。虽然调用存储过程会在网络开销、安全性、性能上获得很多好处,但是存在如果底层数据库发生迁移时就会有很多麻烦,因为每种数据库的存储过程在书写上存在不少的差别
  4. The difference between request forwarding and redirection (6 points)
    Answer:
    1、重定向是两次请求,转发是一次请求,因此转发的速度要快于重定向
    2、重定向之后地址栏上的地址会发生变化,变化成第二次请求的地址,转发之后地址栏上的地址不会变化,还是第一次请求的地址
    3、转发是服务器行为,重定向是客户端行为。重定向时浏览器上的网址改变 ,转发是浏览器上的网址不变
    4、重定向是两次request,转发只有一次请求
    5、重定向时的网址可以是任何网址,转发的网址必须是本站点的网址
  5. Write method Given parameters a, b, c, find the root of a quadratic equation with y=ax^2+bx+c (8 points)
    Tip: △=b 2-4ac value, if △ is less than 0, a quadratic equation with one variable No root. If △ is equal to 0, the one-variable quadratic equation has two equal roots. If △ is greater than 0, the one-variant quadratic equation has two unequal real roots (' 'means square)
    答:
{
    
    
        public static void main(String [] args){
    
    
        Scanner sc = new Scanner(System.in);
        System.out.println("输入2次方的系数");
        int a = sc.nextInt();
        System.out.println("输入1次方的系数");
        int b = sc.nextInt();
        System.out.println("输入0次方的系数");
        int c = sc.nextInt();
        //判断方程是否有解
        if((b*b - 4*a*c)<0){
    
    
            System.out.println("方程无解!");
            return;
        }
        else{
    
    
            System.out.println("方程有解!");
        }
        double x1 = (-b + Math.sqrt(b*b - 4*a*c))/2*a;
        double x2 = (-b - Math.sqrt(b*b - 4*a*c))/2*a;
        System.out.println("根分别是 " + x1 + "\t" + x2);
    }
}

  1. Verify the "Ghost Valley Conjecture": For any natural number, if it is an odd number, multiply it by 3 and add 1; if it is an even number, divide it by 2 to obtain a new number, and then perform the calculation according to the above calculation rules, and keep going Go on and you will eventually get 1. (8 points)
    答:
import java.util.Random;

/**
 * @Author: 老张
 * @Date: 2020/10/22 8:44
 */
public class Test {
    
    

    public static void main(String[] args) {
    
    
        /*
         * 验证“鬼谷猜想”:对任意自然数,若是奇数,
         * 就对它乘以3再加1;若是 偶数,就对它除以2,
         * 这样得到一个新数,
         * 再按上述计算规则进行计算,
         * 一直进 行下去,最终必然得到1。 */
        int num;
        Random rd=new Random();
        //Integer.MAX_VALUE为最大的整数
        num=1+rd.nextInt(Integer.MAX_VALUE);//产生数的范围-2[31]----2[31]-1
        //System.err.println(rd.nextInt(100));//产生数>=0且<100
        System.out.println("原本的数为"+num);
        while(num!=1){
    
    
            System.out.println("产生的新数是"+num);
            if(num%2==0){
    
    
                //偶数
                num=num/2;
            }
            else{
    
    
                num=num*3+1;
            }
        }
        System.out.println(num);
    }
}

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_46914021/article/details/109385550