Java programming ape Face question Summary

Source: Internet
Author: User
Tags bitwise logical operators

(This topic will be updated continuously, please note)

first, to talk about final, finally, finalize the difference.

Final is used to declare properties, methods, and classes, respectively, that the property is immutable, that the method is not overridden, and that the class is not inheritable. Finally is part of the exception-handling statement structure that always runs. Finalize is a method of the object class that, when run by the garbage collector, calls this method of the reclaimed object, and can override this method to provide garbage collection of other resources, such as closing the file.

second, can Anonymous Inner class (anonymous inner Class) be enough to extends (inherit) other classes, can implements (implement) interface (interface)?

The ability to inherit other classes or complete other interfaces is often used in swing programming.

Thirdly, the Static Nested class and the Inner class are different, the more said the better (some of the questions are very general).

The static Nested class is an inner class declared static (static) that can be instantiated without relying on an external class instance. The usual inner classes need to be instantiated after the external class is instantiated.

the difference between the fourth,& and &&.

& is a bitwise operator that represents the bitwise AND Operation,&& is a logical operator that represents the logical and (and).

Five, the difference between HashMap and Hashtable.

HashMap is a lightweight implementation of Hashtable (non-thread-safe implementation), and they all end up with the map interface, the main difference being that the HashMap agrees with the null (NULL) key value (key) because it is not thread-safe and may be more efficient than Hashtable.

the difference between the Collection and the collections.
  
Collection is the ancestor interface of the collection class, and the inheritance and his interface are mainly set and List.collections is a helper class for the collection class, he provides a series of static methods to implement the search, sort, thread-safe operation of various sets.

seventh, when to use Assert.

1.4 New keyword (syntax), used to test the Boolean expression state, can be used to debug the program. Usage assert, which represents the assumption that the expression is true (true), the following statement runs, otherwise throws Assertionerror. Another way to use the Assert < Boolean expression is to say that the expression is assumed to be true, followed by an expression that is ignored, otherwise the value of the subsequent expression is used for the build parameters of the Assertionerror. Note the compile time to add-source 1.4 parameters, otherwise error. ] To add –ea parameters at run time, otherwise the Assert row is ignored

Eighth, what is GC? Why do you have a GC?
  
GC is the meaning of garbage collection (Gabage Collection), memory processing is the programmer easy failure, forget or wrong memory recycling will cause the program or system instability or even crash, The GC feature provided by Java can proactively monitor whether an object exceeds the scope to achieve its own purpose of actively reclaiming memory, and the Java language does not provide a way to release the displayed operation of the allocated memory.

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

Two

Tenth, Math.Round (11.5) how much? Math.Round (-11.5) how much?

Math.Round (11.5) ==12math.round ( -11.5) ==-11round method returns the closest long integer to the number of parameters, plus 1/2 to ask for its floor.

11th, short s1 = 1; s1 = s1 + 1; what's wrong? short S1 = 1; s1 + = 1; what's wrong?

Short S1 = 1; S1 = s1 + 1; (S1+1 operation result is int type, must be strong conversion type) short S1 = 1; S1 + = 1; (able to compile correctly)

12th, what is the difference between sleep () and wait ()?

Sleep is a thread-class method that causes this thread to pause for a specified time and give the opportunity to another thread, but the monitoring state remains and then resumes itself. Calling sleep does not release the object lock. Wait is a method of the object class that calls the wait method on this object to cause this thread to discard the object lock, enter the waiting lock pool waiting for this object, and only have the Notify method (or Notifyall) issued against this object before the thread enters the object lock pool ready to get the object lock into the running state.

13th, does Java have a goto?

No, but is to retain keyword very 13 of the problem, assuming which interview asked this question, I advise you still do not enter this company.

14th, does the array have the length () of this method? Does the string have length () of this method?

The array has no length () of this method and has the length property.
String has the length () method.

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

The overridden overriding and overloaded overloading of a method are different manifestations of Java polymorphism. Overriding overriding is a representation of polymorphism between a parent class and a subclass, and overloading overloading is a representation of polymorphism in a class. Suppose that a method defined in a subclass has 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 called, and for it the definition in the parent class is "masked". Assume that multiple methods with the same name are defined in a class, either with different number of parameters or with different parameter types, which are called overloads of the Method (overloading). The overloaded method is the ability to change the type of the return value.


16th, the elements in set cannot be repeated, so what is the way to differentiate between repetition or not? Is it the same as or equals ()? What's the difference?

The elements in the set cannot be repeated, so use the iterator () method to distinguish between repeated or not. Equals () is the interpretation of two sets for equality.
The Equals () and = = methods Determine whether the reference value points to the same object Equals () is overwritten in the class so that when the contents and types of the two detached objects match, the truth is returned.

17th, give me one of your most common runtime exception.

The references are as follows:
ArithmeticException,
Arraystoreexception,
Bufferoverflowexception,
Bufferunderflowexception,
Cannotredoexception,
Cannotundoexception,
ClassCastException,
Cmmexception,
Concurrentmodificationexception,
Domexception,
Emptystackexception,
IllegalArgumentException,
Illegalmonitorstateexception,
Illegalpathstateexception,
IllegalStateException,
Imagingopexception,
Indexoutofboundsexception,
MissingResourceException,
Negativearraysizeexception,
Nosuchelementexception,
NullPointerException,
Profiledataexception,
ProviderException,
Rasterformatexception,
SecurityException,
SystemException,
Undeclaredthrowableexception,
Unmodifiablesetexception,
Unsupportedoperationexception

18th, what is the difference between error and exception?

Error indicates a serious problem in situations where recovery is not impossible but very difficult. Let's say a memory overflow. It is impossible to expect the program to handle this situation.
Exception represents a design or implementation issue. That is, it represents a scenario where the program is assumed to be normal and never occurs.

19th, List, Set, map inherit from collection interface?

List,set is
Map is not

20th, what is the difference between abstract class and interface?

A class that declares the existence of a method and does not implement it is called an abstract class, which is used to create a class that embodies some basic behavior, declares a method for that class, but does not implement the class in that class. An instance of the abstract class cannot be created. However, it is possible to create a variable whose type is an abstract class, and it points to an instance of the detailed subclass. Cannot have abstract constructors or abstract static methods. The subclasses of the abstract class provide implementations for all abstract methods in their parent class, otherwise they are also abstract classes. Instead, implement the method in the subclass. Other classes that know their behavior can implement these methods in the class.

An interface (interface) is a variant of an abstract class. In an interface, all methods are abstract. Multiple inheritance can be obtained by implementing this interface. All the methods in the interface are abstract, without a program body. The interface can only define static final member variables. The implementation of an interface is similar to a subclass except that the implementation class cannot inherit the behavior from the interface definition. When a class implements a special interface, it defines a method (which is given by the program body) to all such interfaces. It can then invoke the interface's method on whatever object that implements the interface's class. Because there is an abstract class, it agrees to use the interface name as the type of the reference variable. The usual dynamic binder will take effect. A reference can be converted to an interface type or converted from an interface type, and the instanceof operator can be used to determine whether the class of an object implements an interface.

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

Are not

22nd, can interfaces inherit interfaces? Can an abstract class implement an (implements) interface? Does an abstract class inherit entity classes (concrete Class)?

Interfaces can inherit interfaces. Abstract classes can implement (implements) interfaces, and abstract classes can inherit entity classes, but only if the entity class must have a clear constructor.

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

Starting a thread is calling the start () method so that the virtual processor represented by the thread is in an executable state, which means it can be dispatched and executed by the JVM. This does not mean that the thread will execute immediately. The run () method can produce a flag that must be exited to stop a thread.

24th, can the constructor constructor be override?

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

25th, is it possible to inherit the string class?

The string class is the final class and cannot be inherited.

26th, when a thread enters an synchronized method of an object, can other threads enter another method of this object?

No, an synchronized method of an object can only be visited by a thread.


27th, there is a return statement in the try {}, then the code in the finally {} immediately after the try will not be run, when is it run, before or after the return?

Run and run before return.

28th, the programming question: the most efficient way to figure out 2 times 8 and so on?

A program with a C background ape is particularly fond of asking such questions.
2 < < 3

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

Not correct, there is the same hash code.

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

is a value pass. The Java programming language only passes the number of parameters by value. 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 the object can be changed in the called method, but the object's reference is never changed.

31st, can the Swtich function on a byte, can it function on a long, can it function on a string?

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

32nd, Programming Questions: Write a singleton out。

The main function of the singleton mode is to ensure that in a Java application, only one instance of class classes exists.
The general singleton pattern usually has several forms:

The first form defines a class whose constructor is private, and it has a static private class variable that, when the class is initialized, gets a reference to it through a public getinstance method, followed by a method in the call.

public class Singleton {
Private Singleton () {}
Is it very strange to define an instance of yourself within yourself?
Note that this is private only for internal calls
private static Singleton instance = new Singleton ();
Here is a static method for external access to this class, which can be used to directly interview
public static Singleton getinstance () {
return instance;
}
}


Another form:

public class Singleton {
private static Singleton instance = NULL;
public static synchronized Singleton getinstance () {
This method is better than the above, and does not have to be generated every time, just for the first time
Generate an instance when used, improve the efficiency!
if (instance==null)
Instance=new Singleton ();
return instance; }
}


Other forms:
Defines a class whose constructors are private and all methods are static.
Generally feel that the first form should be more secure


There are also some problems, add the following. I hope you will continue to add


 
1. It is a good idea to introduce the final modified variables (both the basic type variable and the reference type variable separately).
2. Do not know how to describe a better narrative, anonymous the inner class itself is a class that implements a particular interface or inherits other classes.
3. Non-static classes cannot have static methods. Take a look at the Java Collections Framework code and say a lot of things.
4.& is both a bitwise operator and a logical operator.
Both & and && are logical operators, and the difference is that they are,&& for short-circuit calculations.
6. Be able to add a reference to the documentation.
11. It may be better to say the detailed reasons.
13.java has goto this keyword, but has not yet been used.
15.overload and polymorphism have no relationship whatsoever. Polymorphism is the basic characteristic of object-oriented, which is related to inheritance and overriding. Originally thought that the overload as a multi-state from C + +, and later turned the basic C + + classic book, but also stressed that polymorphism is only and inheritance, virtual function, overriding related, so do not know where this erroneous thinking from.
16.public interface Set <e>extends Collection <E> A Collection that does not include repeated elements. More specifically, the set does not include elements that satisfy e1.equals (E2) to E1 and E2, and includes a maximum of one null element. As its name implies, this interface mimics the mathematical set abstraction.
Look at the document.
22. "An abstract class can inherit an entity class, but only if the entity class must have a clear constructor." "What do you mean, who rules?"
27. This is more complex, such as

public class Main {

public static void Main (string[] args) {
SYSTEM.OUT.PRINTLN (Test ());
}

public static Boolean test () {
Boolean B = false;
try {

return B = 4 > 3;
} finally {
System.out.println (b);
return false;
}
}
}
As can be seen in this example, the expression after return has been computed, and the return statement is suspended, assuming that there is no return in Finally, this return returns.
Assuming finally has a return, then the return in finally is returned.
29. There is no way to meet the unruly procedure ape.

31. And enumerations?

Java programming ape Face question Summary

Related Article

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.