Niu Ke's Diary (October 26, 2021)

Keywords: Java Back-end

Title:

5
 Basic Java Which of the following is the language function stored in java In the bag? ()
java.lang
java.io
java.net
java.util

Resolution:

java.lang Package contains
 Packaging
String class
Math class     ——    Include function
Class class
Object class


java.util     Provide tool classes including collection framework, event model, date and time, etc;
java.io       Provide input through file system, data stream and serialization;
java.net     Provide classes for real-time network application and development;
java.sql     Provide use java Language accesses and processes data stored in data sources API;
java.awt  and  java.swing  Provided GUI Classes developed and designed, awt It provides all classes for creating interfaces and drawing graphics and images,
swing The package provides a set of "lightweight" components, and try to make these components work the same on all platforms;
java.text    Classes and interfaces that provide a natural language independent way to handle text, dates, numbers, and messages.

Title:

hypothesis A Class has the following definitions, set a yes A Class, which of the following statements is wrong to call? ()
public class A
{
    public int i;
    static String s;
    void method1(){}
    static void method2(){}
}

	System.out.println(a.i);
	a.method1();
	A.method1();
	A.method2();

Resolution:

Static members and static methods can be called directly through the class name; Other members and methods need to be instantiated into objects and called through objects.

Title:

If an interface Cup There's a way use(),There are classes SmallCup Implementation interface Cup,Then in class SmallCup What's right?  ( )
void use() { ...}
protected void use() { ...}
public void use() { ...}
All the above statements can be used in classes SmallCup in

Resolution:

Since the interface is implemented, it is necessary to implement the interface, so the method is equivalent to rewriting the method. The rewriting of the method needs to meet the following requirements: three identical, one large and one small (the method name, return value type and formal parameters are the same; access permission > = before rewriting; throw exception < = before rewriting)

Title:

Which of the following options is created correctly socket connect?
Socket s = new Socket(8080);
Socket s = new Socket("192.168.1.1",8080)
SocketServer s = new Socket(8080);
Socket s = new SocketServer("192.168.1.1",8080)

Resolution:

Refer to the answers downstairs and make a note
Server side: the instance provided by ServerSocket ServerSocket server = new ServerSocket (port number)
Client: instance provided by Socket Socket client = new Socket(IP address, port number)

Title:

In a distributed game server system, which communication mode is not feasible between different servers?
The Conduit
 Message queue
 Cache database
 socket

Resolution:

For pipes, there are the following types:
① Ordinary PIPE: there are usually two restrictions: one is simplex, that is, it can only be transmitted in one direction; The second is blood relationship, that is, it is often used between father and son processes (or between processes with blood relationship).
② s_pipe: the first restriction mentioned above is removed and bidirectional transmission is realized.
③ name_pipe: it removes the second restriction above and realizes the communication between different processes without blood relationship.
Obviously, the requirement is that the communication between different servers requires full duplex, while the pipeline can only be half duplex. Although it can be bidirectional, there can only be one direction transmission at the same time. The difference between full duplex and half duplex can be understood as follows:

Title:

The correct description of the file is ()
Text files are“.txt"Files with suffix names are binary files.
File Class is Java Basic class for reading and writing files in.
Whether text file or binary file, it will be thrown at the end of the file EOFException Abnormal.
Java Text files and binary files in can be operated as binary files.

Resolution:

A. Files are divided into text files and binary files. Computers only know binary, so they are actually different interpretation methods of binary. Text files are characters displayed in different coding formats, such as Ascii, Unicode, etc. the suffix names of text files in window are ". TXT" and ". Log" , source files of various programming languages, etc.; binary files are files that can only be read by special applications, such as ". PNG" and ". BMP" Most of the files in the computer are binary files.
B.File class is a class that operates on the whole file or file attributes, such as creating a file, deleting a file, checking whether a file exists, etc. file content cannot be operated; file content is operated by IO stream.
C. When the end of the file or stream is unexpectedly reached during the input process, an EOFException exception is thrown. Normally, when the end of the file is read, a special value is returned to indicate that the file reading is completed. For example, read() returns - 1 to indicate that the file reading is completed.
D. As mentioned in option A above, both text files and binary files are stored in binary form in the computer, so they are read as binary files.

Title:

about Java Which is wrong about parameter passing in?
In the method, modifying a parameter of a base type does not affect the original parameter value
 In a method, changing a reference to an object parameter does not affect the original reference
 In the method, modifying an object's properties affects the original object's parameters
 In the method, modify the collection and Maps The element of does not affect the original collection parameters

Resolution:
https://www.nowcoder.com/questionTerminal/72096d298bd344168441361f9c16659c

Title:

The following statements about exceptions are correct ()
RuntimeException Exceptions of and its subclasses can not be handled
Catch The statement in the segment does not allow exceptions to occur again
 In the method definition throws The identified exception must be handled by the method in calling the method
 All possible exceptions in the program must be catch Otherwise, it will cause compilation errors
 screen

Resolution:
A

There are two kinds of exceptions, one is the RuntimeException and the other is the CheckedException.
The compiler does not force the exception to be caught. It will throw the exception to the upper layer until the processing code is encountered. Common run exceptions are: nullpointexception (null pointer exception), indexoutofboundexception (out of bounds exception).....
Check exceptions. All exceptions inherited from Exception and not running exceptions are checked exceptions, which need to be caught with try catch in the program. Common exceptions are IO exceptions and SQL exceptions.

Title:

Related below JAVA What is wrong with the description of exception class?
Inheritance structure of exception: base class is Throwable,Error and Exception inherit Throwable,RuntimeException and IOException Equal inheritance Exception
 wrong RuntimeException It is usually an external error(wrong Error),It is generally try{}catch Captured by statement block
Error Class system describes Java Internal errors in the operating system and resource depletion, Error No snapping required
RuntimeException The system includes incorrect type conversion, array out of bounds access, trying to access null pointers, etc. it must be try{}catch Captured by statement block

Resolution:
D

Run time exception, so the name suggests that an exception occurs when the program is running. An implicit premise is that the program cannot detect the existence of an exception when compiling. The author himself does not know whether his code contains run-time exceptions, so it is impossible to use try{}catch {} capture in advance

Title:

If you want to listen TCP How to create port 9000 on the server side socket?
new Socket("localhost",9000);
new ServerSocket(9000);
new Socket(9000);
new ServerSocket("localhost",9000);

Resolution:

Answer B.
ServerSocket(int port) is the port bound by the server. Call accept() to listen and wait for the client to connect. It returns a socket in a connection queue.
Socket (InetAddress address, int port) is a socket stream that creates a client to connect to the host. InetAddress is a class used to record the host, and port specifies the port.

Title:

3
 What is the output of the following code?
public class B
{
    public static B t1 = new B();
    public static B t2 = new B();
    {
        System.out.println("Tectonic block");
    }
    static
    {
        System.out.println("Static block");
    }
    public static void main(String[] args)
    {
        B t = new B();
    }
}
Static block construction block construction block
 Building block static building block building block
 Building block building block static building block
 Building blocks building blocks building blocks static blocks

Resolution:

Correct answer: C
At the beginning, the JVM loads B.class and declares all static members. t1 and t2 are initialized to the default value and null. Because t1 and t2 need to be explicitly initialized, it explicitly initializes t1, initializes the code block → constructor (if not, it calls the default constructor). Eh! How can static code blocks not be initialized? Because the static part has been initialized at the beginning, although only the static variable has been initialized, the static block will not be executed when initializing t1. Because the JVM thinks that this is the second time to load class B, the static will be ignored during t1 initialization, so the non static part, that is, the construction block part, will be initialized directly (output 'construction block') Then the constructor (no output). Then, the initialization process of t2 is the same as that of t1 (output 'building block'). At this time, all static variables are initialized, then the static block part (output 'static block') is executed, and then the main method is executed. Similarly, new objects are created, and the building function is called to output ('building block ')

Title:

stay Web In the application,(    )Be responsible for HTTP Request converted to HttpServletRequest object
Servlet object
HTTP The server
Web container
JSP Webpage

Resolution:

C
Http: http protocol (HyperText Transfer Protocol) is a transfer protocol used to transfer hypertext from WWW server to local browser.
servlet: it is a set of technical standards, including a series of interfaces related to web applications, which is used to provide macro solutions for the implementation of web applications
web container: for example, tomcat is used to accept and respond to client requests, and is responsible for converting HTTP requests into HttpServletRequest objects, that is, creating servlet instance objects
jsp Web page: the server page of Java is also a servlet in essence, which is composed of html web page code, java code and jsp tags. When the servlet processes the data, it will be forwarded to jsp, which is responsible for displaying the data

Title:

Which of the following expressions returns true ()
String a="My field1";
String b="My field1";
    String c=new String("My field1");
    String d=new String("My field1");

a==b
a==c
c=d
a.equals(b)
a.equals(c)

Resolution:
Correct answer: A D E

==, if it acts on a variable of basic data type, directly compare whether its stored "values" are equal; If it acts on variables of reference type, the address of the Object pointed to is compared with the equals method. Note: the equals method cannot act on variables of basic data type. ① In the Object class, the equals method is used to compare whether the references of two objects are equal, that is, whether they point to the same Object. ② The String class overrides the equals method to compare whether the strings stored in the pointed String Object are equal. Other classes, such as Double, Date, Integer, etc., override the equals method to compare whether the contents stored by the pointed Object are equal

Title:

servlet What does the cycle include:
initialization
 Destroy
 Request processing
 start

Resolution:

right key: A B C   

Title:

Related below JAVA Description of exception class,What is true()
Exception inheritance structure:The base class is Throwable,Error and Exception . realization Throwable, RuntimeException and IOException Equal inheritance Exception
 wrong RuntimeException It is usually an external error(Not considered Error In case of),It can be used in the current class try{}catch Captured by statement block
Error Class system describes Java Internal errors in the operating system and resource depletion,Error No snapping required
RuntimeException The system includes incorrect type conversion, array out of bounds access, trying to access null pointers, and so on,Must be try{}catch Captured by statement block

Resolution:
Correct answer: A B C

Why the D option is wrong: a simple example: when we develop with myeclipse or eclipse
Non runtime exceptions always make mistakes when we write, reminding us to try catch or throw
However, the run-time exception can not be detected, and only the run-time exception will make an error, so there is no need to try catch

Title:

Which of the following statements is true about the runtime constant pool
 The size of the runtime pool is affected by the size of the stack area
 The size of the runtime pool is affected by the size of the method area
 It stores various literal values generated during compilation
 Store symbol references generated at compile time

Resolution:
Correct answer: B C D

The Runtime Constant Pool is part of the method area. In addition to the Class version, field, method, interface and other description information, there is also a Constant Pool Table in the Class file, which is used to store various literal quantities and symbol references generated by the compiler. This part will be stored in the Runtime Constant Pool in the method area after the Class is loaded.

Posted by dolce on Mon, 25 Oct 2021 23:05:23 -0700