Java Advanced face Test "turn" __java

Source: Internet
Author: User

First, talk about final, finally, finalize the difference.

Final if a class is declared final, it means that it cannot derive a new subclass, so a class cannot be declared 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 is used to clear exceptions. If an exception is thrown, the matching catch clause executes, and then the control enters the finally block (if any).

Finalize () do the necessary cleanup before the garbage collector clears the object out of memory. It is defined in the Object class, so all of the classes inherit it.

Second, Anonymous Inner class (anonymous inner Class) can inherit other classes, can you implement interfaces?

An anonymous inner class is an inner class without a name. Other classes cannot be inherited, but can be implemented as an interface by another inner class.

Third, the Static Nested class differs from the Inner class.

Nested class (generally C + +), Inner class (generally Java). The most important difference between a Java inner class and a C + + nested class is whether there is a reference to an external point.

Note: the static inner Class (Inner Class) means:

1 Creating an object of a static inner class

2 Cannot access an external class object from an object in a static inner class

The difference between the four,& and the &&.

& is a bitwise operator. && is a boolean logical operator.

Five, the difference between HashMap and Hashtable.

Are classes that are part of the map interface, which enables you to map unique keys to specific values.

The HashMap class allows a null key and multiple null values.

The Hashtable class does not allow null keys and null values. It's also slower than HASHMAP, because it's synchronized.

VI, the difference between Collection and collections.

Collections is a Java.util class that contains a variety of static methods for collection operations.

Collection is a Java.util interface, which is the parent interface of various collection structures.

VII, when to use Assert.

An assertion is a statement that contains a Boolean expression, which is assumed to be true when the statement is executed. If the expression evaluates to False, then the system reports a assertionerror.

Example:

ASSERT (a > 0); Throws an assertionerror if a <= 0

Assertions can be of two forms:

Assert Expression1;

Assert Expression1:expression2;

Expression1 should always produce a Boolean value.

Expression2 can be any expression that results in a value. This value is used to generate a String message that displays more debugging information.

The assertion is disabled by default. To enable assertions at compile time, you need to use the source 1.4 tag:

Javac-source 1.4 Test.java

To enable assertions at run time, you can use-enableassertions or-ea tags.

To choose to disable assertions at run time, you can use-da or-disableassertions tags.

To enable assertions in a system class, you can use-esa or-DSA tags. You can also enable or disable assertions on a package basis.

You can place assertions at any location that is expected to not be reached normally. Assertions can be used to validate parameters that are passed to a private method. However, assertions should not be used to validate arguments passed to public methods because, regardless of whether the assertion is enabled, the public method must check its

Parameters. However, you can test the post condition with assertions in a public method or in a Non-public method. In addition, assertions should not change the state of the program in any way.

What is the GC, VIII? Why should there be a GC?

GC is a garbage collector. Java programmers do not have to worry about memory management because the garbage collector is automatically managed. To request garbage collection, you can call one of the following methods:

System.GC ()

Runtime.getruntime (). GC ()

Ninth, String s = new string ("XYZ"), several string Object created?

Two objects, one is a string type "XyX", and one is a reference object s that points to "XyX".

Tenth, Math.Round (11.5) and how much? How much is math.round (-11.5)?

Math.Round (11.5) returns (long) 12,math.round (-11.5) returns (long)-11;

21st, can the method of abstract be static at the same time, can it be native at the same time, can it be synchronized?

Are not

22nd, is the interface inheritable to the interface? Does an abstract class implement (implements) interfaces? Can an abstract class inherit an entity class (concrete Class)?

Interfaces can inherit interfaces. Abstract classes can implement (implements) interfaces, and abstract classes can inherit entity classes, provided that an entity class must have an explicit constructor.

23rd, start a thread with run () or start ()?

Starting a thread calls the start () method so that the virtual processor represented by the thread is operational, meaning that it can be scheduled and executed by the JVM.

This does not mean that the thread will run immediately. The run () method can produce flags that must exit to stop a thread.

Individual guesses, which may be the following structure:

Run () {

Mythread.start ();

······

}

24th, can the constructor constructor be override?

Constructor constructor cannot be inherited, so overriding cannot be overridden, but can be overloaded overloading.

25th, can you inherit the string class?

The string class is a final class and therefore cannot be inherited.

26th, 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.

27th, there is a return statement in try {}, so will the code in the finally {} after this try be executed, when it is executed, before or after it?

Will execute, before return.

28th, Programming question: Calculate 2 times 8 in the most efficient way?

Programmers with a C background are particularly interested in asking such questions.

29th, two object values are the same (x.equals (y) = = true), but can have different hash code, this sentence is correct?

No, there's the same hash code.

30th, when an object is passed as a parameter to a method, this method can change the property of the object and return the result of the change, so is this the value pass or the reference pass?

is a value pass. The Java programming language has only value delivery. When an object instance is passed to a method as a parameter, the value of the parameter is a reference to that object. The contents of an object can be changed in the method being invoked, but the reference to the object will never change.

31st, does the Swtich function on a byte, whether it acts on a long, and whether it acts on a string?

Switch (EXPR1), expr1 is an integer expression. Therefore, the arguments passed to the switch and case statements should be int, short, char, or byte. Long,string can not act on Swtich.

32nd, the programming question: writes a singleton to come out.

The main purpose of Singleton mode is to ensure that only one instance of a class classes exists in a Java application.

General singleton patterns usually have several forms:

The first form: Define a class whose constructor is private, it has a static private class variable that is instantiated when the class is initialized, gets a reference to it through a public getinstance method, and then invokes the method.

public class Singleton {

Private Singleton () {}

It is not strange to define an instance of yourself inside yourself.

Note that this is private only for internal calls

private static Singleton instance = new Singleton ();

This provides a static method for external access to this class, which can be accessed directly from the

public static Singleton getinstance () {

return instance;

}

}

Second form:

public class Singleton {

private static Singleton instance = NULL;

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.