Home  >  Article  >  Java  >  Java smart flow interview written test questions including answers

Java smart flow interview written test questions including answers

(*-*)浩
(*-*)浩Original
2019-11-19 16:40:182958browse

Java smart flow interview written test questions including answers

1 The following description of the stack is incorrect (B)

A. The stack is a first-in, last-out linear table (recommended learning: java programmer interview questions)

B. The stack can only store sequentially

C. The stack has a memory function

D. The insertion and sum of the stack During the deletion operation, there is no need to change the stack bottom pointer

2 For a linear table of length n, in the worst case, the correct number of comparisons corresponding to the following sorting methods is (D )

A. Bubble sort is n/2

B. Bubble sort is n

C. Quick sort is n

D. Quick sort is n(n-1)/2

3 After reading the following code, the correct statement below is (A)

public class Person{ 
int arr[] = new int[10]; 
public static void main(
String args[ ]){ 
System.out.println(arr[1]); 
} 
}

A When compiling, Error

B is correct when compiling, but error will be generated when running

C Output is empty

D Output 0

4 After executing the following program The output result is (D)

public class Test { 
 public static void main(String[] args) { 
 StringBuffer a = new StringBuffer("A"); 
 StringBuffer b = new StringBuffer("B"); 
 operator(a,b); 
 System.out.println(a+","+b); } 
 public static void operator(StringBuffer x,StringBuffer y){ 
 x.append(y); 
 y=x; }
}

A . A,A

B. A,B

C. B,B

D. AB ,B

5 The following are not persistent: (A)

A. Convert the object into a string and transmit it through the network, and receive the characters at the other end Restore the object from the string

B. Read the program data from the database

C. Read the program configuration information from the XML configuration file

D. The data is saved as a file

6 The output result of the following code is (C)

int x= 0; int y=10; do{ y--; ++x; }while(x<6); System.out.println(); }

A. 5,6

B. 5,5

C. 6,5

D. 6,6

7 The input sequence of a stack is 123, then none of the following sequences The sequence that may be the stack output is (C)

A. 2 3 1

B. 3 2 1

C. 3 1 2

D. 1 2 3

8. When n = 5, the return value of the following function is (D)

int foo(int n){ if(n<2) return n; return foo(n-1)+foo(n-2); }

A. 1

B. 8

C. 7

D. 5

9 Explain what a Servlet is and talk about the life cycle of a Servlet

Servlet is a server-side Java application that is platform- and protocol-independent and can generate dynamic Web pages. It acts as the middle layer between client requests (web browsers or other HTTP client programs) and server responses (databases or applications on the HTTP server).

Servlet is a server-side Java application located inside the Web server. Unlike traditional Java applications started from the command line, Servlet is loaded by the Web server. The Web server must contain a Java virtual machine that supports Servlet. The Servlet life cycle can be divided into four stages: loading and instantiation, initialization, service, and destruction.

When the client requests for the first time, it first determines whether the Servlet object exists. If it does not exist, the Web container creates the object and then calls the init() method to initialize it. The initialization method is only called once during the entire Servlet life cycle.

After completing the creation and instantiation of the Servlet object, the Web container will call the service() method of the Servlet object to process the request.

When the Web container is closed or the Servlet object is to be deleted from the container, the destroy() method will be automatically called.

10 What are the functions and uses of filters?

For a web application, a filter is a component within the web container that filters specific request resource request information and response information. When a request comes, the web container will determine whether there is a filter associated with the information resource. If so, it will be handed over to the filter for processing, and then handed over to the target resource. When responding, it will be handed over to the filter for processing in the reverse order. , and finally returns it to the user's browser.

Common filter uses mainly include: unified authentication of user requests, recording and auditing of user access requests, filtering or replacing data sent by users, converting image formats, and processing response content. Compress to reduce transmission volume, encrypt and decrypt requests or responses, trigger resource access events, etc.

11 In 2006, someone worked for 24 consecutive days and earned a total of 190 yuan (daily wage of 10 yuan, Sunday wage of 5 yuan, and no pay for Sunday rest). It is known that he started working on a certain day in late January, and the 1st of this month happened to be Sunday. The day when this person finished working was February (C)

A. 2 February 6th

B. February 14th

C. February 18th

D. February 21st

12 by There is a bus from point A to point B. The total journey time is 42 minutes. After arriving at the terminus, the driver will rest for at least 10 minutes and the bus will turn around. If there is a bus on line A and point B, there will be one every 8 minutes from both terminals ( (not necessarily at the same time), then this route needs at least two buses (C)

A. 15

B. 14

C. 13

D.12

#13 In the 10 fruit plates numbered 1 to 10, each plate contains fruits, a total of 100 pieces. There are 16 in the first plate, and the sums of the fruits in the three adjacent fruit plates are equal. Find the maximum number of fruits in the 8th plate (A)

A. 11

B. 12

C. 13

14. 14

14 A snail fell into a 20-meter-deep well. It climbed up 3 meters during the day and fell 2 meters at night. How many days does it take to climb out?

I climbed 3 meters on the first day, then fell 2 meters, actually climbed 1 meter;

On the second day, I started from 1 meter and climbed up 3 meters. , then fell 2 meters, actually climbed 2 meters;

On the third day, I started from 2 meters and climbed up 3 meters, then fell 2 meters, actually climbed 3 meters;

.......

On the eighteenth day, I started climbing 3 meters from 17 meters, which happened to be 20 meters. I reached

Correct answer: 18

15 Suppose there is an infinite amount of water in a pond. Now there are two empty kettles with capacities of 5 liters and 6 liters respectively. Ask how to use these two kettles to obtain 3 liters of water.

Answer: Fill the 5L bucket with water and pour all the water into the 6L bucket;

Fill the 5L bucket again and pour water into the 6L bucket until it is full. At this time, 4L water is left in the 5L bucket;

Empty the 6L bucket and pour the 4L water in the 5L bucket into the 6L bucket;

Fill the 5L bucket with water and pour water into the 6L bucket. If it is full, there will be 3L of water in the 5L bucket.

16 There are three lights in the room and three switches outside the room. You can’t see the situation inside the room from outside the room. You can only enter the door once. What method do you use to distinguish which switch controls which one? lamp.

Answer: First turn on the first switch, turn it on for a while and then turn it off, then turn on the second switch, enter the room and touch each lamp. The one that generates heat is the first switch. The light that lights up is the second switch, and the light that doesn't change is the third switch.

17 Two blind men each bought two pairs of black socks and white socks. The 8 pairs of socks were made of cloth and the same size. Each pair of socks was connected by a piece of trademark paper. A blind man accidentally mixed eight pairs of socks together and asked them how to retrieve two pairs of black socks and two pairs of white socks.

Answer: Divide each pair of socks into two.

Everyone takes one.

In this way, each person has four black socks and four white socks.

Everyone has two pairs of black socks and two pairs of white socks.

18 There is a square diamond at the door of each elevator from the first to the tenth floor. The diamonds are different sizes. When you take the elevator from the first to the tenth floor, the elevator door will open once on each floor. , can only hold one diamond in his hand, and asks how to get the biggest diamond.

Answer: The elevator will open on each floor, so take it on the first floor. When you get to the second floor, change it if it is bigger. If it is smaller, don’t change it. Keep going up like this. , after reaching the top level, you will get the biggest

The above is the detailed content of Java smart flow interview written test questions including answers. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn