preface

Gold three has ended, silver four has been opened, time waits for no one, the opportunity missed no longer, take a good grasp, strive for one stroke to win the spring recruitment, smooth job-hopping increase salary. So today xiaobian will share a “spring recruitment JAVA interview manual”, hope to help you prepare for the interview!

1. What is THE B/S architecture? What is the C/S architecture

2. What are the development platforms for Java?

3. What is JDK? What is the JRE?

A:

  1. JDK: Java Development Kit: Java development kit: Java development kit is the environment that developers need to install
  2. JRE: Java Runtime Environment: Java runtime Environment required for Running Java programs

4. What are the features of the Java language

5. The difference between object-oriented and process-oriented

What is a data structure?

7. What are Java data structures?

What is OOP?

The relationship between class and object?

10. There are several data types in Java

Naming rules for identifiers.

12. The instanceof keyword

**instanceof is strictly a Java binocular operator that tests whether an object is an instanceof a class. It can be used as:

boolean result = obj instanceof Class
Copy the code

Where obj is an object, Class is a Class or interface, result is true when obj is an object of Class, a direct or indirect subclass of obj, or an implementation of its interface, otherwise false.

Note: The compiler checks to see if obj can be converted to the class type on the right. If it cannot be converted, an error is reported. If the type cannot be determined, the compiler will compile it at runtime.

inti=0; 
System.out.println(i instanceof Integer);I must be a reference type, not a primitive type
System.out.println(i instanceof Object);// Failed to compile
 Integer integer=newInteger(1); 
 System.out.println(integer instanceof Integer);//true 
 //false. The JavaSE specification states that the instanceof operator returns false if obj is null. System.out.println(nullinstanceofObject);
Copy the code

13. What is an implicit conversion and what is an explicit conversion

Can a Char type be converted to an int? Can I convert it to a string, can I convert it to a double

What is unpacking?

A:

  1. Boxing automatically converts the base data type to the wrapper type (int–>Integer); Unboxing the valueOf(int) method of Integer automatically converts the wrapper type to a primitive data type (Integer–>int).
  2. Before Java SE5, if you wanted to generate an Integer object with a value of 10, you had to do this:
Integer i = new Integer(10);
Copy the code

Autoboxing has been available since Java SE5. If you want to generate an Integer object with a value of 10, you just need to do this:

Integer i = 10;
Copy the code

Interview question 1: What does the following code output?

public class Main { public static void main(String[] args) { Integer i1 = 100; Integer i2 = 100; Integer i3 = 200; Integer i4 = 200; System.out.println(i1==i2); System.out.println(i3==i4); }}Copy the code

Results:

true false
Copy the code

16. What are the wrapper classes in Java?

17. What does a Java class contain?

How do you solve the problem of errors in floating-point data operations?

19. What are the characteristics of object-oriented?

20, access modifiers, public, private, protected, and don’t write what is the difference between (the default)?

A: Class members default to default when they do not write access modifiers. The default is public for other classes in the same package and private for classes not in the same package. Protected is public for subclasses and private for classes that are not parent-child in the same package. In Java, external class modifiers can only be public or default, and class members (including inner classes) can have the above four modifiers.

21. Is String the most basic data type?

22, flfloat f = 3.4; Is that correct?

23, short s1 = 1; s1 = s1 + 1; Didn’t you? short s1 = 1; s1 += 1; Didn’t you?

The difference between overloading and overwriting

25, The difference between equals and ==

The difference between ++ I and I ++

27. What is the structure of the program?

28, How many ways can arrays be instantiated?

Default values for various data in Java

What are the common Java packages?

31, What are the common methods of class Object?

Are there Pointers in Java?

33, Java is value pass reference pass?

34. Can I change the length of an array after I instantiate it?

Suppose there are 5 elements in an array. What if I reverse the order of the array?

36, What is the difference between forms and arguments?

Can constructors be called explicitly?

What is method overloading?

A: Static instantiation: When you create an array, you already specify the elements in the array.

int [] a= new int[] {1 , 3 , 3}
Copy the code

Dynamic instantiation: When you instantiate an array, only the extent of the array is specified. All elements in the array are the default values of the array type

Can the constructor be overridden? Can I reload it?

What is the difference between inner classes and static inner classes?

41, What does the Static keyword do?

42. What is the role of fifinal in Java?

A:

Final is also one of the most popular questions to ask in an interview, but I find it boring and usually answer the following five questions:

  1. Classes modified by fifinal may not be inherited.
  2. Methods decorated by fifinal cannot be overridden.
  3. Variables modified by fifinal cannot be changed. If you decorate a reference, it means that the reference is immutable and what the reference points to is mutable.
  4. Methods that are modified by fiFinal are attempted by the JVM to be inlined to improve performance.
  5. Constants modified by fiFinal are stored in the constant pool at compile time.

In addition, the compiler is better at following two reordering rules for fifinal fields: there is no reordering between a write to a fifinal field within a constructor and a subsequent assignment of a reference to the constructed object to a reference variable. There is no reordering between the first reading of a reference to an object containing the FiFinal field and the subsequent first reading of the fifinal field.

What is the difference between stringBuffffffer and StringBuilder

44, String STR = “aaa”, same as String STR =new String(” aaa “)

What are the common methods of math class in Java?

What are the common methods of String?

A:

CharAt: Returns the character at the specified index

IndexOf () : returns the indexOf the specified character

Replace () : string replacement

Trim () : Removes whitespace at both ends of a string

Split () : Split string, returns a split array of strings

GetBytes () : Returns a byte array of strings

Length () : Returns the length of the string

ToLowerCase () : converts the string toLowerCase

ToUpperCase () : converts a string toUpperCase characters

Substring () : intercepts a string

Format () : formats a string

Equals () : String comparison

47. Is inheritance single or multiple inheritance in Java?

What do Super and this mean?

49. What is the difference between a common class and an abstract class?

What is an interface? Why do you need interfaces?

What are the characteristics of the interface?

52. What is the difference between abstract classes and interfaces?

53. What does Hashcode do?

54, Java four kinds of references, weak and weak soft virtual?

A:

Strong reference

Strong references will not be collected if the application is out of memory (OOM).

String str = new String("str");
Copy the code

Soft references

Soft references are reclaimed when the program runs out of memory.

// Note that WRF is also a strong reference to SoftReference,
 // SoftReference refers to a reference to a new String(" STR "), that is, T in the SoftReference class
  SoftReference<String> wrf = new SoftReference<String>(new String("str"));
Copy the code

Possible scenarios: When the cache is created, the objects created are put in the cache, and when memory runs out, the JVM reclaims the objects created earlier.

A weak reference

A weak reference is a reference that is collected as soon as the JVM garbage collector finds it.

WeakReference<String>wrf=newWeakReference<String>(str);
Copy the code

WeakHashMap key in Java source code uses weak references. My understanding is that once I don’t need a reference, the JVM will automatically handle it for me, so I don’t need to do anything else.

Phantom reference

A virtual reference is reclaimed in much the same way as a weak reference, but it is placed in the ReferenceQueue before being reclaimed. Note that other references are recycled by the JVM before being passed into the ReferenceQueue. Because of this mechanism, virtual references are mostly used for reference destruction processing. In addition, the virtual reference must be created with the ReferenceQueue

Example:

PhantomReference<String>prf=newPhantomReference<String>(new String("str"),newReferenceQueue<>());
Copy the code

Available scenarios: Some operations before object destruction, such as resource release, etc. ** object.Finalize () can also do this, but it is not secure and inefficient. All references refer to objects instead of four subclasses of Reference.

55, How many ways can Java create objects?

56, Is it possible for two unequal objects to have the same Hashcode

57, What is the difference between a copy and a shallow copy?

58, What is the use of static?

Is there any difference between a=a+ B and a+=b?

Fifinal, fiFinalize (), fiFinally

61. Steps for JDBC operations

62, when using JDBC, how to prevent SQL injection problems.

How do I call a stored procedure in JDBC?

64. Do you know connection pools and what are the benefits of using them?

65. What data source technologies do you know? What are the benefits of using data sources?

The difference between & and &&?

How is a static inner class defined?

What is a member inner class?

A:

A non-static class defined inside a class is a member inner class. Member inner classes cannot define static methods and variables (except for final modifications). This is because the in-member class is non-static, and the class initializes the static members first. If the in-member class is allowed to define static variables, the order in which the static variables are initialized is ambiguous. Example:

public class Out { 
private static int a; 
private int b; 
public class Inner { 
public void print(a) { System.out.println(a); System.out.println(b); }}}Copy the code

69, The difference between a Static Class and an Inner Class?

70, When to use assert?

71, Java has goto?

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

What is the most efficient way to work out 2 times 8?

74, Flfloat type flfloat f=3.4

What kinds of sorting methods are there? Please list.

What is the difference between static variables and instance variables?

Name some common classes, packages, interfaces, please name 5.

78, What is the use of a.hash code ()? What does it have to do with A. als(b)?

What are compile-time constants in Java? What are the risks of using it?

80. How do I get out of the current multiple nested loops in Java?

81. Can the constructor be overridden?

82, Two objects with the same value (x.equals(y) == true) can have different hash codes.

Is it possible to inherit the String class?

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

What is the difference between String and StringBuilder?

The difference between overriding and overriding. Can overloaded methods be differentiated by return type?

87, Can a char variable store a Single Chinese character? Why?

What are the similarities and differences between an abstract class and an interface?

81, What is the difference between a Static Nested Class and an Inner Class?

A:

A Static Class is declared to be Static (static), which can be instantiated independently of the external class instance. The normal inner class needs to be instantiated by the outer class, and the syntax looks weird as follows: * Poker class (a deck of cards) *@authorLuoHao * /public class Poker { private static String[] suites = {"Spade"."Red peach"."Sucks"."Square"}; private static int[] faces = {1.2.3.4.5.6.7.8.9.10.11.12.13}; private Card[] cards; /** * constructor ** / public Poker(a) { cards = new Card[52]; for(int i = 0; i < suites.length; i++) { for(int j = 0; j < faces.length; j++) { cards[i * 13 + j] = newCard(suites[i], faces[j]); *}}}/** ** ** ** / public void shuffle(a) { for(int i = 0, len = cards.length; i < len; i++) { int index = (int) (Math.random() * len); Card temp = cards[index]; cards[index] = cards[i]; cards[i] = temp; }}/** ** license *@paramIndex Licensing position * */ public Card deal(int index) { return cards[index]; }/** * Card class (a single card) * [inner class] *@authorLuoHao * * / public class Card { private String suite; // private int face; Public Card(String suite, int face) {this.suite = suite; this.face = face; }@Override public String toString() { String faceStr = ""; switch(face) { case 1: faceStr = "A"; break; case 11: faceStr = "J"; break; case 12: faceStr = "Q"; break; case 13: faceStr = "K"; break; default: faceStr = String.valueOf(face); } return suite + faceStr; Class PokerTest {public static void main(String[] args) {Poker Poker = new Poker(); poker.shuffle(); Card c1 = poker.deal(0); Poker.Card c2 = poker.new Card(" heart ", 1); // Create a card system.out.println (c1); // system.out.println (c2); // Print: heart A}}
Copy the code

Is there a memory leak in Java? Please describe it briefly.

91. Can abstract methods be static, native, and synchronized at the same time?

Can calls to non-static methods be made from inside a static method?

How to implement object cloning?

Does an interface extend an interface? Does an abstract class implement an interface? An abstract class?

Are concrete classes inheritable?

95. Can a “Java” source file contain multiple classes (not inner classes)? What are the restrictions?

Can Anonymous Inner classes inherit from other classes? Can interfaces be implemented?

97. Can an inner class reference a member of its containing class? Are there any restrictions?

What is the use of fifinal in Java?

The last

Friends in need can pay attention to the public number [procedures yuan xiao Wan] can be obtained. JavaOOP interview question summary

Space is limited, other content will not be shown here one by one, sorting is not easy, welcome everyone to exchange, like xiaobian to share the article remember to pay attention to me like yo, thank you for your support! Important things say three times, forward + forward + forward, must remember to forward oh!!