Java interview questions, test questions, simple questions

Source: Internet
Author: User
Tags finally block sql injection thread class stringbuffer

1, the difference between String and StringBuffer

The string class provides strings that cannot be changed numerically.

The string provided by the StringBuffer class is modified.

2. Start a thread with run () or start ()?

With start ()

3, final, finally the difference.

final-modifier (keyword) If a class is declared final, it means that it cannot derive a new subclass and cannot be inherited as a parent class. Thus a class cannot be declared as abstract and declared final. Declaring a variable or method final can guarantee that they will not be changed in use. A variable declared as final must be given an initial value at the time of declaration, and can only be read and not modified in future references. A method that is declared final is also used only and cannot be overloaded.

Finally-provides a finally block to perform any cleanup operations when the exception is processed. If an exception is thrown, the matching catch clause executes, and then the control enters the finally block (if any).

4, List and Map differences?

A list is an object collection that allows objects to be duplicated.

A map is a collection of key-value pairs and does not allow key duplication.

5, the PreparedStatement in JDBC compared to the benefits of statement

Relatively safe, can prevent SQL injection;

Have precompiled function, the same operation batch data efficiency is high

6. What are the collection classes you know? Main methods.

The most commonly used collection classes: List and Map.

The specific implementations of the list include ArrayList and vectors, which are variable size lists that are more suitable for building, storing, and manipulating any

7. What is the difference between abstract class and interface?

An interface is public and cannot have private methods or variables that are used for others to use, and abstract classes can have private or private variables.

In addition, the implementation of interface must implement all the methods defined in the interface, and the implementation of abstract classes can selectively rewrite the need to use the method, the general application, the most top-level is the interface, and then the abstract class implementation interface, and finally to the specific class implementation.

Also, an interface can implement multiple inheritance, and a class can inherit only one superclass, but it can inherit multiple interfaces by inheriting them, as well as an identity (in which there are no methods, such as remote interfaces) and data sharing (variables that are all constants).

8, Scope public,private,protected, and do not write when the difference?

Default to friendly when not written

The variables and methods declared by the public indicate that they can be used outside the package.

The variables and methods declared by private are only available within the declared class.

Protected is not available outside the package. Can be used in the package.

9. The difference between = = and equals

= = To determine whether the value of the base data type is equal or to determine whether the object's address is equal. Equals () is a method in the object class that lets you determine whether two objects are equal by overriding the method.

10, there are several ways to implement a thread in Java. What keyword modifies the synchronization method?

There are two ways to implement multiple threads: inheriting the thread class and implementing the Runnable interface

Cosmetic Sync method: Synchronized keyword

11. What are the aspects of object-oriented features

Abstraction, inheritance, encapsulation, polymorphism

12. When a thread enters an synchronized method of an object, can other threads enter other methods of this object?

No, one synchronized method of an object can only be accessed by one thread.

13. What are the characteristics of the transaction?

Atomicity, consistency, isolation, and persistence

14. What are the three ways to get class?

Class name. class;

instance. GetClass;

Class.forName (full class name);

15, does the array have length () This method? String there is no length () This method

The array has no length () method, and has a property of length.

String has the length () method.

16. There are several types of streams in Java. The JDK provides some abstract classes for each type of stream for inheritance, say what classes they are respectively.

byte streams, stream of characters.

Byte stream inherits from InputStream OutputStream

The character stream inherits from the InputStreamReader OutputStreamWriter. There are many other streams in the java.io package, mainly to improve performance and ease of use.

17, the difference between the byte stream and the character streams

A byte stream can be used for any type of object, including binary objects, while a character flow can only handle characters or strings;

A byte stream provides the ability to handle any type of IO operation, but it cannot handle Unicode characters directly, and the character streams can.

18, the difference between overload and override. Can the overloaded method change the type of the return value?

Overload (method overload) is the expression of polymorphism in a class, and Override (method overrides) is the manifestation of polymorphism between the parent class and the subclass. If you define a method in a subclass with the same name and parameters as its parent class, we say that the method is overridden (overriding). When an object of a subclass uses this method, the definition in the subclass is invoked, and the definition in the parent class is "masked". If multiple methods with the same name are defined in a class, either with a different number of parameters or with different parameter types, they are called overloads of the Method (overloading).

The overloaded method can change the type of the return value.

19, the difference between integer and int

int is the original data type of Java, and integer is the encapsulated class provided by Java for Int.


20. What are the basic data types of Java? String is not a basic data type?

Byte,int,char,long,float,double,boolean,short;

No

 

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.