Java programmer interview 32 questions

xiaoxiao2021-03-06  14

First, talk about the difference between Final, Finally, Finalize. Final? Modifier (keyword) If a class is declared as Final, it means that it cannot be derived from new subclasses and cannot be inherited as a parent class. Therefore, a class cannot be declared as Abstract, and it is declared as final. Declaring variables or methods to Final, ensuring that they are not changed in use. Variables that are declared for final must give initial values ​​at the time of declaration, and only read in future references, cannot be modified. The method that is declared for Final is also only available, and the FinalLip is not overloaded when providing the finally block to perform any clear operation. If you throw an exception, then the matching catch clause will execute, and then the control will enter the Finally block (if any). Finalize? method name. Java technology allows the use of the Finalize () method to make the object to clear the object from the memory before making the necessary cleanup work. This method is called by the garbage collector when it is determined that this object is not referenced. It is defined in the Object class, so all classes have inherited it. Subclasses override the Finalize () method to organize system resources or perform other cleanup work. The Finalize () method is called by this object before the garbage collector deletes the object.

Second, anonymous inner class (anonymous internal class) can be extends other classes, can IMplements INTERFACE (interface)? Anonymous internal class is an internal class without name. You cannot extends other classes, but an internal class can be implemented as an interface, and is implemented by another internal class.

Third, Static Nested Class and Inner Class are different, the more you say, the better (the interview question is very general). NESTED CLASS (generally C statement), Inner Class (typically Java said). The maximum difference between Java internal classes and C nested classes is whether there is a reference to the outside. Specific visible http://www.frontfree.net/Articles/services/view.asp?id=704&page=1 Note: Static Inner Class means 1 Create a Static internal class, no need for an external class Object, 2 cannot access an external class object from an object of a Static internal class

The difference between fourth, & and &&. & Is a bit operator. && is the Boolean logic operator.

Fifth, the difference between HashMap and HashTable. Both of the MAP interface, implement the unique key to a specific value. The HashMap class is not classified or sorted. It allows a NULL key and multiple NULL values. Hashtable is similar to HashMap, but NULL keys and NULL values ​​are not allowed. It is also slower than HashMap because it is synchronized.

Sixth, the difference between Collection and Collectes. Collections is a class under java.util that contains a variety of static methods related to the collection. Collection is an interface under java.util, which is a parent interface of a variety of collections.

Seventh, when do you use Assert. As an assertion, a statement containing Boolean expression, assuming that the expression is TRUE when this statement is executed. If the expression is calculated as false, then the system will report an AssertionError. It is used to debug purposes: assert (a> 0); // throws an assertionError if a <= 0 assertion can have two forms: assert expression1; assert expression1: expness2; Expression1 should always generate a Boolean value. Expression2 can be any expression that draws a value. This value is used to generate a String message displaying more debugging information. As default, it is disabled by default. To enable assertions while compiling, you need to use Source 1.4 tag: Javac -Source 1.4 Test.java To enable assertion at runtime, you can use the -enableassertions or -ea tag. To disable assertion at runtime, you can use the -DA or the -disableAssertions tag. To enable assertion in the system class, you can use the -esa or -dsa tag. You can also enable or disable assertions on the basis of the package. An assertion can be placed at any position that is not reached in normal conditions. As an assertation can be used to verify the parameters passing to the private method. However, assertions should not be used to verify parameters passing to the public method, as there is no matter whether it is enabled, the public method must check its parameters. However, it can be used in public methods or in a non-public method to use asserts to test the post condition. In addition, the assertion should not change the status of the program in any way. Eighth, what is GC? Why have a GC? (Foundation). GC is a garbage collector. Java programmers don't have to worry about memory management because the garbage collector will automatically manage. To request garbage collection, one of the following methods can be called: system.gc () runtime.getRuntime (). GC ()

Ninth, string s = new string ("xyz"); create a few String Object? The two objects, one is "XYX", one is the reference object S with "XYX".

Tenth, Math.Round (11.5) is equal to? Math.Round (-11.5) is equal to? Math.Round (11.5) Returns (long) 12, Math.Round (-11.5) Return (long) -11; second Eleven, whether the method of Abstract can be static, whether it is Native at the same time, is it possible to be synchronized?

Typographic, whether the interface can inherit the interface? Whether the abstraction class can be implemented? Does the abstract class can inherit the physical class (Concrete Class)? The interface can inherit the interface. Abstract classes can be implemented, whether abstract classes can inherit physical classes, but provided that the entity class must have a clear constructor.

Second, the thirteenth, starting a thread is Run () or start ()? Starting a thread is calling the start () method so that the virtual processor represented by the thread is running, which means it can be scheduled by JVM and carried out. This doesn't mean that the thread will run immediately. The Run () method can generate a flag that must be exited to stop a thread.

Chapter 24. Whether the constructor can be can't be inherited by the Override® constructor constructor, so Overriding cannot be overridden, but Overloading can be overloaded.

The second fifteenth, can you inherit the String class? The String class is not inherited by Final.

Twentydays, when a thread enters an SYNCHRONIZED method of an object, other methods of other threads can enter this object? No, one Synchronized method of an object can only be accessed by one thread. 27. There is a Return statement in Try {}, so the code in finally {} after this try is not executed, when is executed, before returnome or after it will be executed, in Return Pre-execution.

Chapter 28. Program: Two multiplier with the most efficient method is equal to a few? There are C backgrounds, special programs like to ask this question.

2 << 3

The second nine, the two object values ​​are the same (x.equals (y) == True, but there can be different Hash Code, this sentence is wrong? No pair, there is the same haveh code.

Thirty, when an object is passed as a parameter to a method, this method can change the properties of this object, and can return the resulting result, then here is the value delivery or reference delivery? Is a value transfer. The Java programming language is only passed by the value. When an object instance is transmitted to the method as a parameter, the value of the parameter is a reference to the object. The content of the object can be changed in the called method, but the reference to the object will never change.

Thirty-first, whether SWTICH can act on Byte, whether it can act on long, can it work on String? Switch (expr1), expr1 is an integer expression. Therefore, the parameters passing to the Switch and the CASE statement should be int, short, char or byte. Long, String can not work on SWTICH.

Article 32. Program: Write a Singleton. The main role of the Singleton mode is to ensure that only one example exists in a Java application. General Singleton mode usually has several forms: the first form: Define a class, its constructor is private, it has a state of static private, instantoneation, and GetInstance through a public Method Get a reference to it, then calls it. Public class singleton {private singleton ()} // define one instance in itself, is it very strange? / Note This is private only for internal calling private static singleton instance = new singleton (); // here provides a static method for external access to this Class, you can directly access public static singleton getInstance () {return instance;}} The second form: public class singleleton {private static singleleton instance = null; public static synchronized singleton getInstance () {// This method is improved above, do not have to generate an object each time, only the first time // Generate an instance and improve efficiency! IF (instance == null) instance = new singleleton (); return instance;}} Other forms: Define a class, its constructor is

转载请注明原文地址:https://www.9cbs.com/read-48137.html

New Post(0)