After the systematic study of Java, it is expected that everyone will master the basic knowledge. But there are always a few required questions during the interview. The following interview questions of basic Java can help you.
1. Is String the most basic data type?
A: No. There are only eight basic data types in Java: byte, short, int, long, float, double, char, and Boolean. Except for primitive type and enumeration type, the else is a reference type.
2. What's the difference between an int and an Integer?
A: Java is a programming language. It is almost pure object-oriented. But basic data types are introduced for programming convenience. In order to manipulate these primitive data types as objects. Java has introduced wrapper class for each. The wrapper class for int is Integer. Autoboxing/unboxing has been introduced since Java 5. It enables them convert to each other.
3. The difference between the String and StringBuffer/StringBuilder?
A: The Java platform provides two types of string: String and StringBuffer/StringBuilder. They can store and manipulate strings. If the string is a read-only string, it means that the content cannot be changed. The string objects of StringBuffer/StringBuilder can be modified directly. StringBuilder was introduced in Java 5. It is the same as the StringBuffer. The difference is that it's in a single thread. Because all aspects of it are not synchronized. And it is more efficient than StringBuffer.
4. The difference between Overload and Override. Can overloaded methods be distinguished by their return type?
A: Method overloading and overwriting are both ways of implementing polymorphism. The difference is that the former implements polymorphism in compiling. The latter implements polymorphism in running time. Overloading occurs in one class. Methods with the same name are considered overloaded. For they have different parameter lists (different parameter types, different number of parameters, or both). Overrides occur between subclasses and superclasses. Overrides require the overridden methods of subclasses have the same return type as superclasses. Better access than the overridden methods of superclass. No more declared exceptions than the overridden methods of superclass (Richter substitution principle). Overloading has no special requirements on the return type.
5. What are the similarities and differences between abstract classes and interfaces?
A: Neither abstract classes nor interfaces can be instantiated. But you can define references to abstract classes and interface types. A class inherits an abstract class or implements an interface. Then it needs to implement all of its abstract methods. Otherwise, the class still needs to be declared as an abstract. Interfaces are more abstract than abstract classes. Because constructors can be defined in an abstract class. There can be abstract methods and concrete methods. The constructor cannot be defined in the interface. And the methods are all abstract methods. Members of an abstract class can be private, default, protected, or public. But members of an interface are all public. A member variable can be defined in an abstract class. For the member variables defined in the interface are actually constants. Classes that have abstract methods must be declared as abstract classes. However, abstract classes don't have to own abstract methods.
The above five interview questions of basic Java are relatively frequent. In preparation for the interview, you need memorize, then can calmly deal with the test.