[Java High Salary Interview Collection] Day1, let me give you a few interview appetizers

Welcome friends to subscribe to my new column " Java High Salary Interview Collection ", here I will share with you the core test points and techniques commonly seen in Java interviews, and help everyone on the road to Java learning!

Appetizers

1. What are JDK, JRE and JVM?

2. What is object-oriented

3. What are the data types of Java?

4. Explain the construction method

5. How to understand method overloading and rewriting?

6. Explain the this and super keywords

7. Interpretation of the Three Musketeers of Strings (String, StringBuilder, StringBuffer)

8. The difference between equals and ==

9. Explain interfaces and abstract classes


Hello, hello, I’m the little gray ape, a programmer who can write bugs,

After careful consideration in many ways, I still opened such a column "Java High Salary Interview Collection". The name may be a bit exaggerated. After all, everyone sitting here must be a bigwig in the technical field. In this column, I think Share with you some common interview questions in java interviews, as well as some of our many Java programmers often overlooked or often used in development, including many aspects such as technology and management.

After all, many interviews will not allow you to directly tell the completion process of a complete project, but rather important issues that are often ignored by programmers during project development, and sometimes even take A seemingly simple question to let us pay IQ tax. But in many cases, it is precisely those unobtrusive interview questions that make us miss our beloved offer.

So after thinking about it for a long time, I still want to publish a column about Java interviews here to help you solve and deal with the pits you may encounter in the interview. At the same time, it is also a record and a record of my own Java learning path. In summary, I also shared with you a few common coping skills for Internet interviews before. Interested friends can read my article " Six Common Problems and Coping Techniques for Internet Interviews, no more pits in 2021! "

Before proceeding with the complete study, let me share with you some appetizers, a few common questions in Java interviews:

 

1. What are JDK, JRE and JVM?

JDK: The development toolkit provided by the developer is for program developers. It includes a complete jre, Java runtime environment, and other toolkits for developers.

JRE: The environment that the package depends on when running is in jre

JVM: When we run a program, JVM is responsible for converting bytecode into specific machine code. JVM provides memory management, garbage collection, and safety mechanisms. It is independent of hardware and operating system. It is exactly that java programs can be written more than once. The reason for execution.

 

2. What is object-oriented

Encapsulation: Encapsulation is a method of privatizing the properties of an object while providing some properties that can be accessed by the outside world.

inherit:

  • Java is inherited by multiple singles,

  • The subclass has non-private properties and methods of the parent class

  • The subclass can have its own attributes and methods, that is, the subclass can extend the parent class

  • Subclasses can implement the methods of the parent class in their own way

Polymorphism: the reference of the parent class points to the child class

 

3. What are the data types of Java?

Many people will fall into this seemingly simple question. When it comes to data types, many people think of int, char and other types the first time, but we will find that the question asked in the question is Data types, not basic data types.

There are two types of data, namely "basic data type" and "reference data type"

The basic data types include the following table:

 

byte

short

int

long

double

float

char

boolean

Byte size

1

2

4

8

8

4

2

1

Footprint size

8

16

32

64

64

32

16

8

 

The reference data types include three types: class, interface, array

So why are there "basic data types" and "reference data types" in Java?

The reason is because the reference type is in the heap, the basic type is in the stack,

The stack space is small and contiguous, and is often placed in the cache. The reference type has a high cache rate and requires one more dereference.

Moreover, the object has to store an additional object header, which is too high a waste of space for basic data types.

 

4. Explain the construction method

What are the rules for the construction method?

  • The constructor name must be consistent with the class name

  • The constructor does not hold any return value type, and the keyword void cannot be added

  • Any class has a constructor, if there is no display definition, the system will define a default no-parameter constructor for the class

  • If the constructor is explicitly defined, the system will not create the default constructor without parameters.

  • Multiple construction methods can be written in a class, and the construction methods form an overload relationship.

 

5. How to understand method overloading and rewriting?

For method overloading and rewriting, these are two very confusing concepts, so here is a table of comparison:

Overload

Rewrite

  1. Happens in the same class

  2. The method name must be the same, and the parameters must be different, including the type, number, and order. The method return value and access modifier can be different.

  3. Occurs at compile time

  1. Occurs in the parent-child class

  2. Method name and parameter list must be the same

  3. The return value range is less than or equal to the parent class

  4. The access modifier range is greater than or equal to the parent class

  5. The thrown exception range is less than or equal to the parent class

 

The above are a few conceptual interview questions that are common in Java interviews. Next, I will share with you a few comparative interview questions.

6. Explain the this and super keywords

There are the following precautions in the use of this and super keywords:

  • The Super keyword is used to access the variables and construction methods of the parent class from the subclass, as well as the construction method

  • When Super calls other constructors in the parent class, it should be placed in the first line of the constructor when calling

  • This keyword is used to refer to the current instance of the class, this can call the construction method of the current class

  • This should also be placed in the first line when calling other construction methods in this class

  • Neither this nor super can be used in static methods
     

7. Interpretation of the Three Musketeers of Strings (String, StringBuilder, StringBuffer)

 

Variability

Thread safe

performance

String

Modified by final, immutable

safe

When making changes, repoint

StringBuilder

char[] value variable

Not safe

10%-15% improvement over StringBuffer

StringBuffer

char[] value variable

Locked, safe

 

 

8. The difference between equals and ==

This question is also the two commonly used methods for comparison during development, but do you really understand these two methods?

==: Determine whether the values ​​of two basic data types are equal, or whether the addresses of two reference type objects are equal

equals(): Determine whether to use an object, more flexible

Next, let's look at an example of a classic interview question:

public static void main(String[] args) {
Integer x = new Integer(500);
Integer y = new Integer(500);
System.out.println(x == y);

Integer i = 128;
Integer j = 128;
System.out.println(i == j);

Integer a = 127;
Integer b = 127;
System.out.println(a == b);
   
}

The results of the above example are as follows:

The first one is false, the reason is because: x and y are two new objects, so the addresses of these two objects are different

For the second and third, why is the first false and the second true? The reason is because the storage range of integer in the constant pool is [-128, 127], 127 is within this range, so it is directly stored in the constant pool, 128 is not in this range, so a new one will be created in the heap Object

 

9. Explain interfaces and abstract classes

Interface is an abstraction of behavior, it is a collection of abstract methods

  • The interface does not need to be instantiated, all members are modified by public static final by default

  • All methods in the interface, either abstract methods or static methods

  • Abstract classes cannot be instantiated like interfaces

  • There can be one or more abstract methods in an abstract class, or no abstract methods

  • Abstract class is the extraction of shared method implementation or shared member variables, mainly used for code reuse through inheritance

It should be noted here that starting from Java 8, the interface has added support for the default method method.

After Java9, support for private default method was added. In other words, both the default method and the static method in the interface in java8 can have a method body

 

The above are a few common appetizers in Java interviews I shared with you. In fact, it can be seen from many Java-related interviews that many interviewers will pay more attention to the assessment of Java basics. After all, any advanced Java technology is It is built on the basic framework, and I will continue to share with you in this column about the core test points that are common in Java interviews.

Friends who find it useful can subscribe to the column,

Little Grey Ape will accompany you to make progress together!

 

 

Guess you like

Origin blog.csdn.net/weixin_44985880/article/details/112235066