First, talk about the difference between final, finally and Finalize.

Final – Modifiers (keywords) modify a class so that it cannot be inherited; Modifier method, cannot be overridden; Modifier member variables that cannot be assigned twice (so an initial value must be given); Cannot be used with abstract;

Finally – Used specifically after a try-catch block, usually to close some stream or other.

Finalize – Method name. Specifically used for garbage collection mechanisms; Every object has a Finalize () method;

When retrieving objects, reference chains that are not connected with GC Roots will be marked and screened for the first time after reachabness analysis. The screening condition is whether it is necessary to execute this method. When objects do not overwrite this method or have been called, this method will not be executed. This method is the only way for elephants to escape death

Does Anonymous Inner Class extends(extends) other classes and implements(implements) interfaces?

An anonymous inner class is an inner class without a name. There is no extends(extends) other classes, but an inner class can act as an interface implemented by another inner class.

The more you say the better, the more you can say.

Nested Class, Inner Class, Inner Class. The biggest difference between Java inner classes and C++ nested classes is whether they have references to the outside.

A static Inner Class means to create an object of a static Inner Class, without the need for an external Class object. An external class object cannot be accessed from an object of a static inner class

Hashtable inherits from the Dictionary class, and HashMap is an implementation of the Map interface introduced in Java1.2

A HashMap allows NULL as an entry key or value, whereas a Hashtable does not

Also, HashMap contains containsValue and containsKey without containing Hashtable contains methods. Because the CONTAINS method is misleading. The main difference is that Hashtable’s method is Synchronize, whereas HashMap does not. Instead of synchronizing its method for multiple threads accessing Hashtable, HashMap must provide external synchronization for it.

Fourth, the difference between & and &&.

& is the bit operator; Whether the front face or the wrong face, the back is involved in the operation.

&& is a Boolean logical operator; As long as the first one is true, the next one is not evaluated.

5, The difference between HashMap and Hashtable.

1. HashMap and Hashtable are both implementation classes of the Map interface

Hashtable is thread-safe, HashMap is thread-unsafe;

3. A HashMap allows a key-value to be null, but a Hashtable does not

4. HashMap is accessed using a fast and secure failure mechanism

The difference between Collections and Collections.

It’s all under the java.util package

Collections is the class that contains various static methods for operations on Collections.

Collection is the interface, which is the parent interface of various collections.

7. When to use assert.

An assertion is a statement containing a Boolean expression that is assumed to be true when executed. If the expression evaluates to false, an AssertionError is reported. It is used for debugging purposes:

Assert (a > 0); // throws an AssertionError if a <= 0

Assertions can take two forms:

Assert Expression1;

(2) Assert 1: Expression2;

Expression1 should always produce a Boolean value.

Expression2 can be any expression that yields a value. This value is used to generate String messages that show more debugging information.

Assertions are disabled by default. To enable assertions at compile time, use the Source 1.4 tag:

Javac – 1.4 the Test source. Java

To enableassertions at run time, use the -enableassertions or -ea flag.

To choose to disableassertions at run time, use the -da or -disableassertions tag.

To enable assertions in system classes, use the -esa or -dSA flag. Assertions can also be enabled or disabled on a package basis.

Assertions can be placed at any location that would not normally be expected to arrive. Assertions can be used to validate arguments passed to private methods. However, assertions should not be used to validate arguments passed to public methods, because public methods must check their arguments regardless of whether assertions are enabled. However, you can use assertions to test postconditions in both public and non-public methods. In addition, assertions should not change the state of the program in any way.

Eight, what is GC? Why GC?

The GC is the garbage collector. Java programmers do not need to worry about memory management because the garbage collector manages it automatically. To request a garbage collection, call one of the following methods:

System.gc()

Runtime.getRuntime().gc()

String s = new String(“xyz”); How many String objects are created?

Two objects, one is “xyx”; One is the reference object S to “xyx”.

Ten, what is math.round (11.5)? What is math.round (-11.5)?

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

Short s1 = 1; s1 = s1 + 1; What’s wrong with that? short s1 = 1; s1 += 1; What’s wrong with that?

short s1 = 1; s1 = s1 + 1; S1 +1 = short; s1+1 = short; s1+1 = short; S1 =(short)(s1 + 1). short s1 = 1; S1 += 1 is correct.

What is the difference between sleep() and wait()?

wait(); Wait times need not be specified; Release locks while releasing execution

Sleep (): wait time must be specified; [Fixed] Release execution, but not lock The status changes from running to temporarily blocked

Does Java have a Goto?

Yes, it exists as a Java reserved word

Does an array have a length() method? Does String have a length() method?

Arrays do not have a length() method, they have a length property.

String has the length() method.

The difference between “Overload” and “Override” Can the Overloaded method change the type of the return value?

Overwriting is a manifestation of polymorphism between parent and subclass, and overloading is a manifestation of polymorphism within the same class.

Override overrides a method and overrides it to achieve a different effect.

Overload means that we can define some methods with the same name, define different input parameters to distinguish these methods, and then when we call them, the JVM will choose the appropriate method to execute based on the different parameter styles.

The Overload method can change the type of value returned.

16. Elements in a Set cannot be repeated, so what is the way to tell whether they are repeated or not? Equals == or equals()? What’s the difference?

Elements in a Set cannot be repeated. Use the iterator() method to distinguish between repeated elements. Equals () checks whether two sets are equal.

The equals() and == methods determine whether a reference value refers to the same object. Equals () is overridden in the class so that it returns true if the contents and types of two separate objects match.

Give me one of your most common Runtime exceptions.

ArithmeticException,ArrayStoreException,BufferOverflowException,BufferUnderflowException,CannotRedoException,CannotUndoE xception,ClassCastException,CMMException,ConcurrentModificationException,DOMException,EmptyStackException,IllegalArgumen tException,IllegalMonitorStateException,IllegalPathStateException,IllegalStateException, ImagingOpException,IndexOutOfBoundsException,MissingResourceException,NegativeArraySizeException,NoSuchElementException, NullPointerException,ProfileDataException,ProviderException,RasterFormatException,SecurityException,SystemException,Unde claredThrowableException,UnmodifiableSetException, UnsupportedOperationException

What is the difference between error and exception?

Error indicates a general error or a low-level resource error that cannot be controlled. Let’s say memory runs out.

Exception represents a design or implementation problem. Programmer errors such as arithmetic exceptions.

I have a QQ group, the group does not regularly share technology dry goods, industry secrets, gather all kinds of wonderful fun topics and popular trends! If you like my share, you can use QQ search 650385180 add group follow.

Do List, Set, Map inherit from Collection interface?

The List, the Set is

The Map is not

What is the difference between class and interface?

All methods in an interface are implicitly abstract. Abstract classes, on the other hand, can contain both abstract and non-abstract methods. A class can implement many interfaces, but can inherit only one abstract class. To implement an interface, a class must implement all the methods declared by the interface. However, a class may not implement all the methods declared by an abstract class, in which case, of course, the class must also be declared abstract. Abstract classes can implement interfaces without providing implementations of interface methods.

Variables declared in Java interfaces are final by default. Abstract classes can contain non-final variables.

Member functions in Java interfaces are public by default. The member functions of an abstract class can be private, protected, or public. Interfaces are absolutely abstract and cannot be instantiated. An abstract class cannot be instantiated either, but can be called if it contains the main method.

21. Can abstract method be static, native, and synchronized?

Can’t

22. Is an interface inheritable? Does an abstract class implement an interface? Can abstract classes inherit from concrete classes?

Interfaces can inherit from interfaces. An abstract class implements an interface. An abstract class can inherit an entity class, but only if the entity class has an explicit constructor.

Do I start a thread with run() or start()?

The start () method is used to start a thread. When a thread is started with start(), it enters the ready state, making the virtual processor it represents runnable, which means it can be scheduled and executed by the JVM. This does not mean that the thread will run immediately. The run() method, if any, starts when the CPU allocates it time. START() is the method that calls the RUN() method. The RUN() method is what you have to override. The RUN() method contains the body of the thread

Can the Constructor be overridden?

Overriding is something that happens between a parent class and a subclass, whereas the Constructor cannot be inherited and therefore cannot be overridden, but can be overridden

Can I inherit the String class?

The String class is final and cannot be inherited.

Public Final Class Stringextends Objectimplements Serializable, Comparable, CharSequence 26, When a thread accesses a synchronized method of an object, can other threads access other synchronized methods of the object?

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

27. If there is a return statement in the try {}, will the code in finally {} immediately following the try be executed and when, before or after the return?

Will be executed, before return.

Twenty-eight, programming problem: the most efficient way to figure out 2 times 8 is what?

2 < < 3

X.equals (y) == true), but can have different hash codes.

No, it has the same hashcode.

30. When an object is passed as an argument to a method that changes the object’s properties and returns the changed result, is it value passing or reference passing?

It’s value passing. The Java programming language only passes parameters by value. When an object instance is passed to a method as a parameter, the parameter’s value is a reference to that object. The contents of the object can be changed in the method being called, but the reference to the object is never changed.

Can swtich work on byte, can swtich work on long, can swtich work on String?

In switch (expr1), expr1 is an integer expression. Therefore, the arguments passed to the switch and case statements should be int, short, CHAR, or byte. Neither long nor String works on swtich.

Programming problem: Write a Singleton.

/ / the evil Chinese type

class singeleton{

//1. Privatize the constructor so that classes outside the class cannot call the constructor

private singeleton(){

}

// create an object for this class. Since the constructor is privatized, external classes can no longer create objects for this class

// Since the object is placed in the property, it can be privatized by providing external methods that external classes can use to call the object

private static singeleton instence=new singeleton();

//3. Privatize the instance object, called through a public method

//4. This public method can only be called by the class because it is set to static, and instances of the class must also be static

Public static singeleton getSingeleton(){// The return type is singeleton***********

// Is privatized and can only be accessed through a class, so the class must be static

// This method returns the object instence

return instence;

}

}


/ / LanHanShi

class singeleton2{

private singeleton2(){

}

private static singeleton2 instence2=null;

public static singeleton2 getSingeleton(){

if(instence2! =null){

instence2=new singeleton2();

}

return instence2;

}

}

To this Java programmer development or really interested. You can ask me for some Java learning video Java architecture exchange group: 650385180, this is free, I hope that students do not have a granted attitude when looking for me, after all, it is my efforts, I hope you really want to learn Java heart, I will do my best to help you become an excellent programmer.

Note: like friends can like and follow, learning progress together