Java interview questions (a) - Java foundation

1. JDK and JRE What is the difference?

JRE (JavaRuntimeEnvironment), Java Runtime Environment , which is the Java platform. All Java programs can be run under JRE. Ordinary users only need to run java program has developed good, you can install the JRE.

JDK (Java Development Kit) is a program developer to compile, debug java program with the development kit. JDK tools is a Java program, also need JRE to run. In order to maintain the independence and integrity of the JDK, during the installation of the JDK, the JRE is part of the installation. So, there is a directory called jre in JDK installation directory for storing JRE files.

JVM (JavaVirtualMachine, Java Virtual Machine) is a part of the JRE. It is a fictional computer, is on by the actual computer simulation of various computer functions to achieve. The JVM has its own sound hardware architecture, such as processors, stacks, registers, etc., also has a corresponding instruction. The most important feature of the Java language is cross-platform operation. Use JVM is to support independent of the operating system, cross-platform.

2. == and equals What is the difference?

"==" comparison when compared to the value of basic data types, when compared to the comparison reference type is an address

" Equals " is the Object The method defined in Object of equals comparison also address ( return ( the this == obj )), but the system will rewrite the general class equals method to compare the contents of

3. The two objects hashCode () are the same, equals () also necessarily to true , right?

Not, Java in a predetermined two objects are equal (i.e., the equals () evaluates to to true ), the hashCode must be equal,

Instead two objects have the same hashcode value, they are not necessarily equal

4.final in java what role?

final modified class is final class can not be inherited

final modified method can not be overridden

final modified variables constant, can only be assigned once, the value can not be changed after the assignment

5.java in Math.round (-1.5) equal to how much?

Indeed Math.round (a)  returns (long) Math.floor (a + 0.5d )

All Math.round (-1.5) equals -1

6.String belongs to the basic data type?

String is a reference data type, the Java basic There are eight types: byte , int , Short , Long , float , Double , char , boolean .

7.java operating string What are classes? What is the difference between them?

String: immutable sequence of characters

StringBuffer: variable sequence of characters, but the efficiency is relatively low thread-safe

StringBuider: variable sequence of characters, thread-safe, high efficiency

8.String str = "i" and the String str = new new String ( " i " ) the same?

Not the same, String str = "i" will only create an object in constant pool, and if the constant pool of the same object already exists no longer create a direct reference to the object, String str = new new String ( " i " ) , whether kept constant pool the same object does not exist will create an object on the heap, if the constant pool is not the same object creates an object in the constant pool again

9. How to reverse a string?

May be used StringBuffer or StringBuider in reverse () method

10.String commonly used methods of the class are those?

indexOf (): Returns the index of the specified character.

charAt (): Returns the character at the specified index.

replace (): replacement string.

trim (): removing a blank string ends.

split (): Split string, returns an array of strings after the division.

getBytes (): returns a string type byte array.

length (): returns the length of the string.

toLowerCase (): turn into lowercase string.

toUpperCase (): turn a string to uppercase characters.

substring (): string taken.

equals (): comparison string.

11. abstract class must be abstract way?

Abstract class does not necessarily contain an abstract method, but a method comprising the abstract class is an abstract class must

12. The ordinary classes and abstract classes What are the differences?

Defines an abstract class common method may not be directly instantiated,

Abstract class defines the abstract methods can not be directly instantiated

 13. abstract classes can use the final modified it?

An abstract class can not be final modification itself is an abstract class can not be instantiated, the definition of abstract class is to give the other class inheritance, if the final modification can not be inherited

14. interfaces and abstract classes What is the difference?

The main purpose is to reduce repetitive abstract class code, and the purpose is to achieve a connection between the interface module, to realize the transmission of information between modules, reducing the coupling between modules (abstract class is mainly used in the module, the interface is mainly used The inter-module).

An abstract class can have various types of variables, and the interface can only be a static const

An abstract class can have a conventional method, and the interface can have only abstract method

Abstract class can only inherit from a parent class, an interface can inherit multiple parent interfaces

A class can only inherit a class, but can implement multiple interfaces

An abstract class can have a constructor, the interface can not have a constructor

15.java the IO stream is divided into several?

Into the direction of the flow: the input stream (flow from the destination program) (from a data source to the flow of the program) and output streams

Divided by memory unit: byte stream (in bytes of the data stream unit operation) and the character stream (operation data in characters)

By treatment points: nodes stream (a data source or destination directly read and write) and the process flow (not directly connected to the data source or destination, but the other stream is processed packaging, thereby improving the performance of the program)

16.BIO , NIO , AIO What is the difference?

BIO : Block IO synchronous blocking IO , is what we usually use the traditional IO , which is characterized by simple and easy to use mode, low concurrent processing capability.

NIO : New IO synchronous non-blocking IO , is the traditional IO upgrade, the client and the server through Channel (channel) communication, to achieve multiplexing.

AIO : Asynchronous IO is NIO upgrade, also known as NIO2 , implements asynchronous non-blocking IO , asynchronous IO operation based on the event and the callback mechanism.

17. Files common method what it is?

Files.exists () : detects file path exists.

Files.createFile () : create the file.

Files.createDirectory () : Create a folder.

Files.delete () : Delete a file or directory.

Files.copy () : Copy the file.

Files.move () : move the file.

Files.size () number to view the file:

Files.read () : read the file.

Files.write () : write to the file.

Guess you like

Origin www.cnblogs.com/gaojinshun/p/10777878.html