[Private use] java end-of-term review arrangement

foreword

The information is organized according to the examination scope issued by the school. The school is different, and the reference is not much.
The content of the exam is concentrated in the first 6 chapters , corresponding to the content on the review outline.
The key points of programming question 345 are
the short answer questions.



1. Types of Exam Questions

question type Score/question quantity Points for each question
1. multiple choice 2 15 30
2. True or False 2 10 20
3. program reading questions 3 5 15
4. short answer questions 5 3 15
5. Programming 10 2 20

2. Topics and knowledge points

1. Multiple choice questions, true or false questions

  1. Features of the Java language (multiple choice questions, judgment questions)
  2. Identifier naming rules. (multiple choice questions, true or false questions)
  3. Java program file name naming rules (java source program file name and application program class name), and file extension (multiple choice), main method (multiple choice, judgment), main class
  4. Integer (decimal, octal, hexadecimal) legal constant representation, character constant (single character, string constant) representation, real type legal constant representation. The encoding used by the character.

Integer constants can be decimal, octal, or hexadecimal constants. The prefix specifies the radix: 0x or 0X means hexadecimal, 0 means octal, and no prefix means decimal by default.
Integer constants can also take a suffix, the suffix is ​​a combination of U and L, U means unsigned integer (unsigned), L means long integer (long). The suffix can be uppercase or lowercase, and U and L can be in any order.
The specific content of the constant

  1. Expression evaluation of mixed data type operations: (multiple-choice questions, judgment questions, reading programs)
    (1) master the operation rules of common operators mentioned in textbooks, and operands (such as %, /, logical operators && and | |, etc.), including compound assignment operators (+=, -=, *=, etc.)
    (2) Data type conversion: automatic conversion conditions, and when mandatory conversion and syntax format are required
    (3) Conditional operations use of symbols
  2. Master the programming of branch structure and loop structure (multiple choice questions, program reading questions, programming questions)
    (1) if statement, if~else statement 
    (2) switch statement
    (3) structure of loop statement (for, while, do-while)
    (4) The use of break and continue statements and return statements.
    (5) and their combination.
  3. Definition and use of one-dimensional array; definition and use of two-dimensional array; access to array elements
  4. Java object-oriented programming
    (1) Master the definition of classes (member variables, member methods and construction methods) and use, object creation
    (2)
    (3)
    (4) usage of package and import (multiple choice questions, judgment questions)
    (5) Method call and parameter passing, method of parameter passing (value passing and reference passing) (selection, program reading questions)
    (6)
    (7) What are the access modifiers of the class (multiple choice questions, judgment questions)
    (8) Class Private members and public members
    (9) Member access modifiers: private, protect, public, default modifiers, what are their access rights (multiple choice questions, judgment questions)
    (10) The format of method overloading (choice Questions, judgment questions)
    (11) The function and definition of construction methods, overloading and calling of construction methods (multiple choice questions, judgment questions, program reading questions) (12) The
    use of static member variables and static member methods (multiple choice questions, judgment questions Question, program reading question)
    (13)
    (14) Subclass creation (note that the parent class construction method is automatically called in the subclass construction method), and the transformation object (program reading question)

(15)
(16) Definition of abstract classes
(17) Implementation of interfaces and interfaces, using interfaces to achieve multiple inheritance
(18)
9. The way the program handles errors and exceptions, the basic structure of exception handling is used try-catch-finally, The use of throw and throws and their respective functions (multiple choice questions, judgment questions, program reading questions)
10. The common input and output methods of Scanner can be input by keyboard and files. Familiar with commonly used file character/byte input and output streams, random streams, and buffered streams. (Multiple choice questions, true or false questions)
11. Common layout managers GridLayout, FlowLayout, BorderLayout layout methods (multiple choice questions)
12. Master the event processing mechanism, familiar with the method of registering listeners for event sources, and familiar with ActionEvent events. (Multiple Choice Questions, True or False Questions)
13. Functions and uses of Connection, Statement, ResultSet, and prepareStatement related to database operations (Multiple Choice Questions, True or False Questions)

2. Short answer questions

  1. Three steps to develop and run Java programs
    1. Create Java source programs
    2. Compile source files
    3. Run class (bytecode) files

  2. The difference between instance variables and local variables
    1. Instance variables are declared in the class rather than in the method. Local variables are declared within methods.
    2. Instance variables have default values, but local variables do not.
    3. The instance variable is not allowed to have the same name, but it can have the same name as the local variable. When the name is the same, the local variable takes precedence. Local variables cannot have the same name.

  3. The relationship between classes and objects
    Classes are templates for creating objects, without classes there are no objects. The result of the instantiation of a class is an object, and the abstraction of an object is a class, which describes a group of objects with the same characteristics (attributes) and the same behavior.

  4. The respective functions of this and super
    this:
    1. Reference the current object. When the name of the instance variable and the local variable conflict, use this to represent the instance variable.
    2. Use this() in the construction method to call other construction methods of this class
    super:
    1. Reference the parent class object. Access the overridden property of the parent class or call the overridden method of the parent class.
    2. super() is used in the construction method of the subclass, which can determine which construction method of the parent class to call when jvm constructs the parent class object.

  5. The concept of inheritance and polymorphism
    Inheritance is an important way to achieve polymorphism. Inheritance is a mechanism for creating new classes from existing classes, which refers to extending functions on the basis of existing classes. Polymorphism means that when a method of the parent class is overridden by its subclass, each subclass object can exhibit different behaviors by using the upward transformation of the object.

  6. The difference between method overloading and overriding (also called overriding)
    1. Overriding implements runtime polymorphism, while overloading implements compile-time polymorphism.
    2. The rewritten method parameter list must be the same; the overloaded method parameter list must be different.
    3. The return value type of the rewritten method can only be the parent class type or a subclass of the parent class type, while the overloaded method has no requirement for the return value type.

  7. The difference between an interface and an abstract class
    1. Generally, there are only abstract method declarations in an interface, and abstract classes can define other members.
    2. Interfaces cannot be inherited but can only be implemented, and abstract classes are specially used for inheritance.
    3. A class can implement multiple interfaces, but a class can only inherit one abstract class.
    4. The interface emphasizes the realization of specific functions, while the abstract class emphasizes the relationship of ownership.


3. Program reading questions

  1. Program reading questions 1 and 2 of textbook P57
    1.1 Answer: you, apple, sweet

    Because else has no parentheses, z is reassigned

    1.2 Answer: Jeep is fine.

    When i=1: the condition case 1 is satisfied in the switch statement, the letter "J" is output, and there is no break; the statement will not jump out of the loop, so case2 will also be executed, and the letter "e" will be output, and a break will be encountered after running case 2 Statement, jump out of the loop. That is, when i=1, "Je" is printed.
    When i = 2, it starts running directly from case 2
    , and prints out "e". Without a break statement, execution continues and "OK" is printed. That is, when i=3, "p is good" is printed out
    ; when i=4, the case condition is not satisfied, the default statement is run, and "good" is printed out to leave the loop.
    The end result is "Jeep is good". break jumps out for breaking.

  2. Program reading questions 1, 2, 3, 4 of textbook P120
    2.1 Answer: [Code 1]: 1. [Code 2]: 121. [Code 3]: 121.

    The redFish object is an instance of the Fish class, so it has the properties of the Fish class, and the output weight is 1.
    The lake.setFish method passes the redFish object, and assigns the redFish object to the fish object in the Lake, then the two have the same reference and thus have exactly the same variable. Then when lake.foodFish(120) is called, the weight of the fish object in the lake object becomes 121, and the references of redFish and fish are the same, and their variables are also the same, so the weight in redFish also becomes 121.

    2.2 Answer: sum = -100.

    Knowledge point: usage of this keyword.
    The main class declares that the object of class B first calls the setX method to pass the parameter as -100, but the statement in the method body is x=x, the x on the right side of the equal sign is the parameter passed in, and the x on the left side of the equal sign is the same It also refers to this parameter, so it is meaningless to assign the value of the parameter to itself.
    When calling the setY method, the this.y on the left of the equal sign refers to the member variable y under the current class, so the member variable y is assigned a value of -200 at this time, and the sum of x+y returned is -100.

    2.3 Answer: 27.

    Knowledge point: Class variables (static variables)
    No matter how many objects a class instantiates, they all share the class variables in the class. The n in b1 is 3, and the n in b2 is 5. After calling b1.getSum and summing, the result is 1+2+3=6 assigned to s1. Since sum is a class variable, the sum in b2 is also 6. Then call b2.getsum to sum, that is, 6+1+2+3+4+5=21 is assigned to s2. At this time, the sum in b1 also becomes 21, and the final output value of s1+s2 is 6+ 21=27.

    2.4 Answer: [Code 1]: 100. [Code 2]: 20.0.

    Knowledge point: method overloading,
    method overloading requires that the method name must be the same, the parameter list is different (the number of parameters is different or the parameter type is different), [code 1] the parameters passed are two int variables 10 and 10, then the same as The int f(int x, int y) method matches, and the output result is 100. [Code 2] The parameters passed are int 10 and double 10.0, which match double f(int x, double y), and the output result is 20.0. Note that it cannot be written as 20 , returns a double type.

  3. Program reading questions 1, 2, 3, 4 of textbook P153
    3.1 Answer: [Code 1]: 15.0. [Code 2]: 8.0.

    Class B inherits Class A, but the f method in B does not override the one in Class A (parameter types are different), [Code 1] calls f to pass two ints, and actually calls the method of Class B itself, and the return value is a double, so 15.0 is output. [Code 2] Call f to pass two doubles, the method inherited from class A is called, and the output is 8.0.

    3.2 Answer: [Code 1]: 11. [Code 2]: 110.

    Object a is an object of class A, which calls its own method of class A, and then let a instantiate class B, and a is called an up-transformation object. At this time, the subclass overrides the method of the parent class is called.

    3.3 Answer: [Code 1]: 98.0. [Code 2]: 12. [Code 3]: 98.0. [Code 4]: 9.

    Code 1 calls the f method of the b object. The b object is instantiated by class B, and calls the f method of class B itself. After passing in 10.0 and 8.0, the super keyword is used to call the f method of the parent class, and the assignment of 18.0 is obtained Give m, and finally return 18.0+10.0*8.0 which is 98.0.
    [Code 2] Call the static method g in class B to pass in 3, and then call the g method in the parent class to pass in 3. After getting 9 and assigning it to m, output 9+3, which is 12.
    [Code 3] The a object is an up-transformation object, and the up-transformation object can call the method of rewriting the parent class and the method derived from the parent class, so the method f called by a is the method it rewrites, and the specific process is the same as [Code 1] 】Same, the answer is 98.0.
    [Code 4] Because the g method is a static method, the static method is not allowed to be rewritten, so the g method in class B is equivalent to the unique method of this class, then the g method called by a is actually the parent class, and the output The result is 9.

    3.4 Answer: [Code 1]: 120. [Code 2]: 120. [Code 3]: -100.

  4. Program reading questions 1, 2, 3 of textbook P173
    4.1 Answer: [Code 1]: 15.0. [Code 2]: 8.0.

    Class B implements the A interface and overrides the methods in A. A a = new B() is an interface callback (you can assign a reference to an object created by a class that implements a certain interface to the interface variable declared by the interface. Then the interface variable can call the interface implemented by the class method.) So use the interface variable a to call the f method in class B. returns 15.0.
    B b = (B)a casts the object a into an object of class B, and you can call the g method in class B to return 8.

    4.2 Answer: [Code 1]: 18. [Code 2]: 15.

    Class B inherits Class A and implements the Com interface. Com com = b is the interface callback, so com can call the add method in Class B to output 18. A a = b is the upcast (the subclass reference is assigned to the parent class object) , then a can also call the subclass to rewrite the method add of the parent class, and output 15.

    4.3 Answer: No way

  5. Textbook P189 program reading questions 1, 2,
    3 5.1 Answer: Hello everyone, I wish you success in your work!
    5.2 Answer: p is an interface variable.
    5.3 Answer: Hello fine thanks.

4. Programming questions

  1. Find the sum of the series (cumulative sum), such as: example 5 on page 44 of textbook P51, example 6 on page 45 of textbook P51

Example 5: Calculate the sum of the first 12 items of 8+88+888+8888+...

public class Example3_5  {
    
    
    public static void main( String args[ ] )   {
    
      
         long sum = 0 , a = 8 , item = a , n = 12 , i =1;
         for (  i=1; i<=n; i++)   {
    
    
                  sum = sum + item;
                  item = item*10+a ;
          }
          System.out.println(sum) ;
      }
  }

my process

package 书上例题;

class888加到第12项的和 {
    
    

	public static void main(String[] args) {
    
    
		long sum=0,n=0,a=8, i;
		for(i=1;i<=12;i++) {
    
    			
			n=n*10+a;
			sum=sum+n;			
		}
		System.out.println("计算结果为:"+sum);
	}

}

operation result
insert image description here

Example 6: Use the while statement to calculate the sum of the first 20 items of 1+1/2!+1/3!+1/4!+···.

public class Example3_6  {
    
    
    public static void main( String args[ ] )  {
    
    
        double sum = 0 , item = 1 ;
        int i = 1 , n = 20 ;
        while ( i <= n )   {
    
    
             sum = sum + item ;
             i = i+1 ;
             item = item * (1.0 / i ) ;
         }
         System.out.println( " sum = " +sum ) ;
     }
 }

my process

package 书上例题;

classwhile计算算术 {
    
    

	public static void main(String[] args) {
    
    
		// TODO 自动生成的方法存根
		double sum=0.0 , n=1.0 ;
		int i=0 ;
		while (i<=20) {
    
    
			i = i + 1 ;
			n = (1.0/i )* n ;
			sum = sum + n ;				
		}
		System.out.println("前20项和为:"+sum);
	}
}

operation result
insert image description here

  1. Programming questions 1, 3, 5, 6 of textbook P58

Programming question 1: Write an application program to find 1!+2!+···+10!.

public class Ti1  {
    
    
    public static void main ( String args)  {
    
    
         double sum = 0 , a =1 ;
         int i = 1 ;
         while ( i <= 20 )  {
    
    
              sum = sum +a ;
              i++ ;
              a = a*i
          }
          System.out.println( " sum = " +sum ) ;
      }
  }

Programming question 3: Use do-while and for loops to calculate the sum of the first 20 terms of 1+1/2!+1/3!+1/4!+···.

public class Ti3  {
    
    
   public static void main ( String args[ ] )  {
    
    
        double sum = 0 , a=1 ,i =1 ;
        
        do {
    
      sum = sum +a ;
                i++ ;
                a =( 1.0 / i ) *a ;
        }
        while ( i < 20 ) ;
        System.out.println("使用 do-while 循环计算的 sum = " +sum) ;
        
        for ( sum = 0 , i = 1 , a = 1 ; i<=20 ; i++  )   {
    
    
                a = a*( 1.0 / i) ;
                sum = sum + a ;
        }
        System.out.println(" 使用 for 循环计算的 sum = " +sum) ;
    }
}  

Programming question 5:

Programming question 6: Find the largest positive integer n whose output satisfies 1 + 2 + 3 + ··· + n < 8888.
My process

package 书上例题;

class 求满足小于8888的最大整数n {
    
    

	public static void main(String[] args) {
    
    
		// TODO 自动生成的方法存根
		int sum = 0 , n = 1 , m = 1 ;
		for (n = 1; n <=m ; n++) {
    
    
			if (sum >= 8888) {
    
      //如果sum值大于8888,就让 n > m 结束循环
				m = n - 1;
				System.out.println("n为:"+ (n-1));
		    }
			else {
    
       //否则输出 当前sum的值,并且让 n < m 进行下一次循环
				sum = sum + n ;
				m = n + 1 ;
			}
		}
	}
}

operation result
insert image description here

  1. Design a circle, rectangle, and triangle class to calculate the area and perimeter.
public class Circle {
    
    
        private double radius ;
        public static final double PAI=3.14;
        public double getRadius() {
    
    
                return radius;
        }
        
        public void setRadius(double radius) {
    
    
                this.radius = radius ;
        }
        public double getArea() {
    
    
                return PAI*radius*radius ;
        }
        public double getCircumference() {
    
    
                return 2*PAI*radius;
        }
}
public class Rectangle {
    
    
            private double broadth;
            private double longth;
            
            public double getBroadth() {
    
    
                        return broadth;
                }
                public void setBroadth(double broadth) {
    
    
                        this.broadth = broadth;
                }
                public double getLongth() {
    
    
                        return longth;
                }
                public void setLongth(double longth) {
    
    
                        this.longth = longth;
                }
                        
            public double getArea() {
    
       //类的操作
                    return getBroadth()*getLongth();            
            }
            
            public double getCircumference() {
    
      //方法的命名采用动宾结构,代表做事
                    return 2 * (getBroadth() + getLongth());                    
            }                
}
public class Triangle {
    
    
        private double highth;
        private double bottom;
        public double a,b,c;
        
        public double getHighth() {
    
    
                return highth;
        }
        public void setHighth(double highth) {
    
    
                this.highth = highth;
        }
    public double getBottom() {
    
    
            return bottom;
    }
    public void setBottom(double bottom) {
    
    
            this.bottom=bottom;
    }
    
    public double getArea() {
    
    
            return 0.5*highth*bottom;
    }
    public double getCircumference() {
    
    
            return a+b+c ;
    }
}
public class Main {
    
    

        public static void main(String[] args) {
    
    
                Rectangle a1 = new Rectangle ();   
        a1.setLongth(2) ; //通过.使用这个对象的属性
        a1.setBroadth(3) ;        
        System.out.println("矩形的面积为:" +a1.getArea()+"; 周长为:" +a1.getCircumference());
        
        Circle c1 = new Circle();
        c1.setRadius(4);
        System.out.println("圆的面积为:"+c1.getArea()+"; 周长为:"+c1.getCircumference());
        
        Triangle t1 = new Triangle();
        t1.a=4;
        t1.b=5;
        t1.c=7;
        t1.setHighth(4);
        t1.setBottom(5);
        System.out.println("三角形的面积为:"+t1.getArea()+"; 周长为:"+t1.getCircumference());    
        }
}

4. Design a Point class to represent a point in a two-dimensional geometric plane and calculate the distance between two points.

public class Point {
    
    
	
	private double x ,y ;
	
	public Point(double x, double y) {
    
     //构造方法是与类名同名的方法,初始化
		this.x = x;
		this.y = y;	
	}
	//访问私有字段get\set方法
	public double getX() {
    
     //获取值
		return x;
	}

    public void setX(double x) {
    
    
    	this.x = x ;
    }
	
    public double getY() {
    
    
    	return y;
    }
    
    public void setY(double y) {
    
    
    	this.y = y;
    }
    
    public double calDistance(Point otherPoint) {
    
    
    	double dx = x - otherPoint.getX();
    	double dy = y - otherPoint.getY();
    	double d = Math.sqrt(dx*dx + dy*dy);
    	return d;
    }
}
public class Main {
    
    

	public static void main(String[] args) {
    
    
		Point p1,p2;
		p1 = new Point(45,7);
		p2 = new Point(5,5);
		System.out.println("p1点坐标:("+p1.getX()+","+p1.getY()+")");
		System.out.println("两点间的距离为:" +p1.calDistance(p2));
	}
}

5. Textbook P76 example 6 (summation), textbook P81 example 8 (cone combined circle object)
//P68 //P72

    class Computer{
    
    
            int add(int x, int y) {
    
    
                    return x+y;
            }
    }
    
    class Main{
    
    
            public static void main(String args[]) {
    
    
                    Computer com = new Computer();
                    int m = 100;
                    int n = 200;
                    int result = com.add(m, n);
                    System.out.println(result);                   
            }
            
    }

Summarize

dead man

Guess you like

Origin blog.csdn.net/weixin_52248428/article/details/125208489