preface

This set lists many IT companies interview real questions, to apply for the Java programmer position common examination points and knowledge system are classified and summarized.

The problem set is suitable for programmers applying for Java and Java SE positions as a review, learning, and reinforcement material for interview, as well as for other programmers as an extended reading material.

The problem set includes common algorithms, interview questions, and new advanced technologies such as microservices architecture. The topic set is very comprehensive and is a good guide for Java programmers who have been working for 1-5 years or so.

You can also access the latest version of the interview questions online:Java Zero Basics Tutorial (including project and interview questions)

31. Talk about Java polymorphism

Three conditions for realizing polymorphism (prerequisites, upward transition, downward transition)

1. the existence of inheritance; (Inheritance is the basis of polymorphism, without inheritance there can be no polymorphism.)

2. Subclasses override methods of their parent classes. (The method overridden by the subclass will be called in polymorphisms)

3. A parent class reference variable points to a subclass object. (Type conversions involving subclasses to superclasses)

Student person = new Student()

To point a reference from a parent class to a subclass object, an upward cast is automatically cast. In this case, the method called by a reference variable of the parent class overrides or inherits the method of the parent class, not the method of the parent class. In this case, the method called by a reference variable of the parent class cannot call the method specific to the child class.

Student stu = (Student)person;

Assigning a reference to a subclass object to a reference to a subclass is a downward cast in which a cast must be performed. A downward cast must be cast to the real subclass type to which the parent reference refers, otherwise a ClassCastException will appear, not an arbitrary cast

You can use the Instanceof operator in conjunction with casting for downward conversions, such as a ClassCastException

32. Briefly describe Java’s garbage collection mechanism

In traditional C/C++, the programmer is responsible for reclaiming allocated memory.

Disadvantages of explicit garbage collection:

1) The program forgets to recycle in time, which leads to memory leakage and reduces system performance.

2) Program error recovery program core class library memory, resulting in system crash.

Java language does not require programmers to directly control the memory reclamation, which is automatically reclaimed by THE JRE in the background, known as garbage collection mechanism, referred to as GC.

1) It can improve the programming efficiency.

2) Protect the integrity of the program.

3) Its overhead affects performance. The Java virtual machine must keep track of useful objects in the program and determine which ones are useless.

Features of garbage collection mechanism:

1) Garbage collection reclaims object space in JVM heap memory, not stack memory data.

2) Other physical connections, such as database connection, input stream output stream, Socket connection cannot be done.

3) Garbage collection occurs unpredictably, and the program cannot accurately control the execution of garbage collection mechanism.

4) You can set the reference variable of the object to NULL, indicating that the garbage collection mechanism can collect the object.

Today’s JVMS have a variety of garbage collection implementation algorithms, with varying performance.

Before garbage collection can reclaim any object, its Finalize method will always be called first (reactivating the object if the method is overridden and a new reference variable rereferences the object).

Programmers can tell the System to do garbage collection via system.gc () or Runtime.geTruntime ().gc() with some effect, but whether the System does garbage collection is still uncertain.

You should never call the Finalize method of an object actively. You should give it to the garbage collector.

33. Basic data types and wrapper classes

1) Wrapper classes for the eight basic data types

2) Why introduce wrapper classes for primitive types

2.1 Basic data types are convenient, simple and efficient.

2.2 However, the basic data types in Java are not object-oriented (no attributes, methods), which has many inconveniences in practical use (for example, the elements of a collection can only be Object).

To solve this problem, a Wrapper Class is designed for each basic data type, so that the eight classes corresponding to the basic data type are collectively referred to as the Wrapper Class.

3) Wrap conversions between classes and primitive data types

3.1 wrapper classes — — — — — – wrapperInstance. XxxValue () — — — — — – > basic data types

3.2 ——- New WrapperClass(Primitive)

3.2 ——- New WrapperClass(Primitive)

4) Automatic packing and unpacking

JDK1.5 provides autoboxing and Autounboxing, which enable automatic conversions between wrapper classes and basic data types

5) Wrapper classes can also convert primitive type variables to and from strings

Basic type variable –> string.valueof ()– >String Basic type variable <– wrapperclass.parsexxx (String)– String

34. Difference between Integer and int

Int is one of the eight primitive data types that Java provides. Java provides a wrapper class for each primitive type. Integer is the wrapper class that Java provides for int.

Int is one of the eight primitive data types that Java provides. Java provides a wrapper class for each primitive type. Integer is the wrapper class that Java provides for int.

In Hibernate, if an OID is defined as an Integer type, Hibernate can determine whether an object is temporary based on whether its value is null. If an OID is defined as an int, it also needs to set its unsaved-value property to 0 in the HBM mapping file.

In addition, Integer provides a number of integer-related operations, such as converting a string to an Integer, and defines constants that represent the maximum and minimum values of integers.

Java.sql.Date and java.util.Date

Date is a subclass of java.util.Date. It is a thin wrapper around millisecond values that allows JDBC to identify millisecond values as SQL Date values. The millisecond value represents the number of milliseconds since 00:00:00 GMT, January 1, 1970. To be consistent with the definition of SQL DATE, the millisecond value wrapped by the java.sql.date instance must be “normalized” by setting the time, minute, second, and millisecond to zero in the specific time zone associated with the instance. Java.sql.Date is a database Date, and java.util.Date is a pure Java Date.

2) The Date and Time classes provided in JAVA, java.sql.Date and java.sql.Time, only read certain points from the database, which sometimes results in data loss. For example, a field containing 2002/05/22 5:00:57pm reads the date as 2002/05/22 and reads the time as 5:00:57pm. You need to know how accurately the database stores time. Some databases, such as MySQL, have an accuracy of milliseconds, while others, including Oracle, store data of type SQL DATE in milliseconds without saving the data. An undiscovered BUG can occur when you get a Date object in JAVA. Reading dates from a database attempts to compare whether two date objects are equal. If the milliseconds are missing, two date objects that were thought to be equal may return false using the Equals method. .sql.Timestamp is more accurate than java.util.Date. This class packages a getTime() method, but it does not return the extra precision part of the data, so you must use…

Date is a Java Date object, whereas java.sql.Date is used for SQL statements and contains only the Date without the time part.

36. Output a list of all files and subdirectories in a directory using a recursive algorithm

37. Which of the following is true about Java compilation () (select one)

38. Which of the following statements is true ()

39.Java interface modifiers can be () (select one)

40. Given the following code, the program will print () (select one)