I believe there are still many friends who just learned Java for a short time and only know the basics of Java. They will go to the company to interview for jobs and then follow the big guys to improve their skills.
But for those of you who don’t know what a basic Java programmer like us will be asked when going to an interview company, here I have compiled some basic interview questions and looked at the basic Interview questions and answers in Java. I hope you will be helpful. Let’s start with the questions and answers.
Friends in need can click:This! Point the, code word: J j.
1. What are the differences between JRE, JDK, and JVM?
JVM: The English name (Java Virtual Machine), is we all know the Java Virtual Machine. It only recognizes files of the type xxx.class.
JRE: Java Runtime Environment (JRE), which includes Java virtual machines (VMS) and core class libraries required by Java programs. If you want to run a developed Java program, the computer only needs to install the JRE.
JDK: English name (Java Development Kit), JDK is provided for the use of Java test personnel, which contains Java Development tools, including JRE. So if you install the JDK, you don’t need to install the JRE separately.
The development tools include compilation tool (javac.exe), packaging tool (jar.exe) and so on.
In simple terms: JDK>JRE>JVM, using the Java program developed by JDK, to run JRE.
2. Can a Char in Java store a Chinese character?
Java uses Unicode, two bytes (16 bits) to represent a character, whether it’s a Chinese character or alphanumeric, or any other language. In Java, char is two bytes.
So you can store Chinese.
3.Java data types?
4. What are the automatic type conversion rules?
Rule 1: If an operand is double, the entire expression can be promoted to double
Rule 2: Meet the conditions for automatic type conversion
Both types should be compatible
Numeric types (integer and floating point) are compatible
The target type is greater than the source type
For example, double is greater than int
5. What is the precedence order of the operators?
Arithmetic operators > relational operators > logical operators
! > > > comparison operators arithmetic operators && > | |
6. What is the difference between if and switch selection structures?
A. the same
Are structures for dealing with multiple branching conditions
B. the difference
The switch selection structure can only handle the case of equivalent condition judgment
The multiple if selection structure is suitable for the case where a variable is in a continuous interval
7. What is the difference between a While loop and a do While loop?
A. Different execution sequences
While determines and then executes
Do while
B. The initial condition does not meet the cyclic condition
The While loop never executes once
The Do while loop is executed at least once
Friends in need can click:This! Point the, code word: J j.
A. Application situation
Break is often used in switch structures and loop structures
Continue is commonly used in loop structures
B. Function (in cyclic structure)
The Break statement terminates the layer loop, and the program jumps to the next statement outside the loop block
Continue Jumps out of the current loop and enters the next loop
9. How to use arrays?
1. The statement
2. Allocate space
3. Assignment (side declaration side assignment; Dynamic input information assignment from the keyboard)
4. Crunch the data
10. The relationship between classes and objects?
1. Class is an abstract concept that does not exist in real time/space. It only defines abstract properties and behaviors for all objects.
2. An object is a concrete of a class. It’s a real thing.
* Simply put: a class is a template for an object, and an object is an instantiation of a class.
11. What are the development steps of the class?
1. Discover classes (Define classes)
2. Write properties
3. Compilation method
- Use properties and methods
12. What is the difference between a local variable and a member variable?
A. Different scope
Member variables are visible throughout the class; A local variable is limited to the method it defines.
B. The initial value is different
Assigns initial values to member variables; Local variables are not assigned initial values.
C. Different priorities
When a member variable has the same name as a local variable in the same class, the local variable has higher priority.
D. Declare the location
Member variables are inside the class and outside the method. Local variables are inside the method
13. What are the differences between static variables and instance variables?
A static variable is a variable that is modified by a static modifier. There is only one memory space in the class. The static variable can be allocated during the loading process. To access.
B. An instance variable must depend on an instance. The object must be created and then accessed through the object.
C. A static variable is initialized only once, no matter how many objects of a class are created. All instances can access the static variable, and it can be accessed directly by the class name.
Can the String class be inherited?
Can’t.
The String class is final and therefore cannot be inherited.
15. What are the common methods in the String class?
Get the length of strings: Length () Compare strings: equals() Connect strings: concat() Extract strings: subString () Search strings: indexOf() Split strings: split() Ignore string case: EqualsIgnoreCase () converts all English characters toLowerCase: toLowerCase() converts all English characters toUpperCase: toUpperCase() removes Spaces: trim()
16. What is the difference between String, StringBuffer, StringBuilder?
String: Applies to a small number of String operations
StringBuilder: Thread-unsafe, suitable for large numbers of operations in the character buffer under a single thread
StringBuffer: Thread-safe and inefficient applies to situations where multiple threads perform a large number of operations in the character buffer
(Operations are concatenation of strings.) Concatenate SQL in JDBC
17. What do you think of the four features of object orientation?
Packaging:
Encapsulation is generally thought of as binding data to methods that manipulate it, and data can only be accessed through defined interfaces. The methods we write in our classes encapsulate the implementation details; We write a class that encapsulates data and data operations. Encapsulation, so to speak, is hiding everything that can be hidden and providing only the simplest programming interface to the outside world. (Reduce code redundancy) Inheritance: Inheritance is the process of creating a new class by taking inherited information from an existing class. Classes that provide inheritance information are called superclasses (superclasses, base classes); The class that gets the inheritance information is called a subclass (derived class).
Polymorphism:
Polymorphism refers to allowing objects of different subtypes to respond differently to the same message. Simply put, the same object reference calls the same method but does different things. Polymorphism is divided into compile-time polymorphism and run-time polymorphism. Method overload implements compile-time polymorphism (also known as pre-binding), while method override implements runtime polymorphism (also known as post-binding)
Abstract:
Abstract is the process of constructing a class by summarizing the common features of a class of objects, including data abstraction and behavior abstraction. Abstractions focus only on what properties and behaviors an object has, not on the details of those behaviors.
18. What is the difference between method overloading and method overwriting? (Method overloading occurs within a class and method overwriting occurs between parent and child classes.) Method overloading and overwriting are both ways of implementing polymorphism, the difference being that the former implements compile-time polymorphism while the latter implements runtime polymorphism. Overloading occurs when a method with the same name has different argument lists (different parameter types, different number of arguments, or both) and is considered overloaded.
Rewriting occurs between a subclass and its parent class. Rewriting requires that the subclass overridden method has the same return type as the parent overridden method, is more accessible than the parent overridden method, and cannot declare more exceptions than the parent overridden method (Richter’s substitution principle). Overloading has no special requirements for return types.
Rules for method overloading:
1. The method names are the same, and the sequence, type, and number of parameters in the parameter list are different.
2. Overloading occurs within a class regardless of the return value of a method.
3. Different exceptions can be thrown and there can be different modifiers.
Method override rules:
1. The argument list and return type must be exactly the same as the method being overridden.
2. Constructors cannot be overridden, methods declared final cannot be overridden, and methods declared static cannot be overridden, but can be declared again.
- A subclass cannot have more access rights than its parent class if it occurs between parent classes.
19. What is the difference between public, protected, private and friendly by default?
20. What is the initialization order under multiple inheritance?
Parent class before child class, property before constructor.
21. What is the thinking behind using runtime polymorphic development?
A. Write a parent class
B. Write subclasses that override parent methods
C. At runtime, use the type of the parent class and the object of the subclass
Pet Pet = new Dog();
22. What is the difference between upward transformation and downward transformation in the class?
Downcast: Parent class to subclass (cast using Instanceof) (object Instanceof class or interface)
Upcast: Subclass to parent (automatic type conversion) using the type of the parent class, subclass object
Provide [free] Java architecture learning materials, learning technology content includes: Spring, Dubbo, MyBatis, RPC, source code analysis, high concurrency, high performance, distributed, performance optimization, micro services advanced architecture development and so on.
Friends in need can click:This! Point the, code word: J j.
There are Java core knowledge points + a full set of architect learning materials and video + first-line factory interview gem + resume template can be received + Ali Meituannetease Tencent Xiaomi IQiyi Quick hand bilibilibilii interview questions +Spring source code collection +Java architecture practice ebook.