Java Error Mark_1

Source: Internet
Author: User

New Ket Network

The following description of the Init,service,destroy method in the servlet is incorrect.
The init () method is the starting point for the servlet's life. Once a servlet is loaded, the server will call its init () method immediately
Service () method handles all requests made by the client
Destroy () method flags the end of the servlet lifecycle
The servlet uses the synchronization mechanism under multithreading, so the servlet is thread-safe in concurrent programming

Source: Niu Ke Net

The servlet itself is not thread-safe under multithreading.

If you define a member variable in a class and make changes to the member variable in the service based on a different thread, you can cause an error when concurrency occurs. It is best to define a local variable in a method, not a class variable or a member variable of an object. Because the local variables in the method are in the stack, each of them has separate operating space without interfering with each other, so thread safety is achieved.

Which of the following assignment statements is correct ()
Long test=012
Float f=-412
int other = (int) True
Double d=0x12345678
BYTE b=128

Source: Niu Ke Net

Choose Abd

A and B in long and float, the normal definition needs to be plus L and F, but long and float are basic types and will be converted so that no exception is reported. AB Right

A Boolean type cannot be converted with any type and a type exception error is reported. So C is wrong.

The D option can be defined so that D is correct.

In the E option, the byte value range is-128-127. Report an exception:
Cannot convert from int to byte. So the E option is wrong.

1
Public interface IService {String name= ' default ';}
The default type equivalence represents which item:
The correct answer: C your answer: B

Public String name= "default";
public static String name= "Default";
public static final String name= "default";
Private String name= "default";

The

Variables inside the interface are all public and final. So you can write this:
public static final int i=10;
or
int i=10; (You can omit a portion of it)
Notice that you want to give the variable an initial value at the time of the declaration
Explanation:
First you have to figure out what the interface means. An interface is to provide a unified ' protocol ', and attributes in an interface are also ' protocol ' . They are public, static, and final constants. The equivalent of a global constant. An
abstract class is a class that is not ' complete ', and is equivalent to an intermediate layer of interfaces and concrete classes. It satisfies the abstraction of the interface and satisfies the concrete realization.
If an interface can define a variable, but the methods in the interface are all abstract, the property cannot be modified in an interface by behavior. Some people would say, no relationship, you can modify the properties of an interface by implementing the behavior of the object of the interface. This is certainly not a problem, but consider such a situation. If interface A has a static variable a of public access rights. In terms of Java semantics, we can change the value of variable a in an interface without accessing the variable A through A.A = XXX By implementing the object of the interface. As can be done in an abstract class, all objects that implement interface A also automatically have the value of the changed a, which means that one place changes a, and the value of a in all these objects is changed accordingly. What is the difference between this and the abstract class, how to embody the higher level of abstraction of the interface, how to embody the unified protocol provided by the interface, then what is the interface of this abstraction to do? So there is no variable in the interface, and if there are variables, the idea that the unified abstraction provided by the interface is inconsistent. Therefore, the attribute in the interface must be constant, can only read and can not be changed, so as to provide a unified property for the object that implements the interface.
in layman's terms, what you think is going to change is placed in your own implementation and cannot be placed in an interface, which is just a higher-level abstraction of the attributes and behavior of a class of things. For the modification, the extension (different implementation implements) is open, and the interface is a manifestation of the closing principle.

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.