Home > Java > JavaInterview questions > Do you know what technical difficulties are often encountered in Java interviews?

Do you know what technical difficulties are often encountered in Java interviews?

王林
Release: 2020-11-04 17:05:34
forward
2933 people have browsed it

Do you know what technical difficulties are often encountered in Java interviews?

This article has compiled some technical problems that are often encountered during interviews, and I hope it can help you.

(Related video recommendation: java course)

1. Can a ".java" source file include multiple classes (not internal classes) ? What are the restrictions?

There can be multiple classes, but there can only be one public class, and the public class name must be consistent with the file name.

2. Does Java have goto?

is a reserved word in Java that is not currently used in Java.

3. Talk about the difference between & and &&.

& and && can be used as logical AND operators, indicating logical AND (and). When the results of the expressions on both sides of the operator are true, the entire operation result is true. Otherwise, as long as If one of the parties is false, the result is false. && also has the function of short-circuiting, that is, if the first expression is false, the second expression will no longer be evaluated. & can also be used as a bitwise operator. When the expressions on both sides of the & operator are not of boolean type, & represents a bitwise AND operation.

4. How to get out of the current multiple nested loops in JAVA?

In Java, if you want to jump out of multiple loops, you can define a label before the outer loop statement, and then use the break statement with the label in the code of the inner loop body to jump out of the outer loop. .

5. Can the switch statement act on byte, long, or String?

In switch (expr1), expr1 can only be an integer. Expressions or enumeration constants (larger font size). Integer expressions can be int basic types or Integer wrapper types. Since byte, short, and char can all be implicitly converted to int, these types and the wrapper types of these types it is also fine. Obviously, the long type does not comply with the syntax of switch and cannot be implicitly converted to int type, so it cannot be used in switch statements. String can be used after jdk1.7.

6. Can a Chinese character be stored in a char variable? Why?

The char variable is used to store Unicode-encoded characters. The Unicode-encoded character set contains Chinese characters, so , of course Chinese characters can be stored in char type variables. However, if a special Chinese character is not included in the unicode encoding character set, then the special Chinese character cannot be stored in this char variable. Additional explanation: Unicode encoding occupies two bytes, so the char type variable also occupies two bytes.

(Recommendations for more related interview questions: java interview questions and answers)

7. When using the final keyword to modify a variable, is it a reference that cannot be changed or a reference? The object cannot be changed?

When using the final keyword to modify a variable, it means that the reference variable cannot be changed, but the content of the object pointed to by the reference variable can still be changed.

8. What is the difference between static variables and instance variables?

The difference in syntax definition: the static keyword must be added before static variables, but not before instance variables.

The difference when the program is running: Instance variables belong to the attributes of an object. An instance object must be created before the instance variable in it will be allocated space and this instance variable can be used. Static variables do not belong to an instance object, but to a class, so they are also called class variables. As long as the program loads the bytecode of the class without creating any instance objects, the static variables will be allocated space, and the static variables can be used.

9. Is it possible to issue a call to a non-static method from inside a static method?

Can't. Because non-static methods are associated with objects, an object must be created before method calls can be made on the object. However, static methods do not need to create an object when calling, and can be called directly.

In other words, when a static method is called, no instance object may have been created. If a call to a non-static method is issued from a static method, which object is the non-static method associated with? What about? This logic cannot be established, so a static method internally issues a call to a non-static method.

10. What is the mechanism to implement polymorphism in Java?

relies on the fact that the reference variables defined by the parent class or interface can point to the instance object of the subclass or specific implementation class, and the method called by the program is dynamically bound at runtime, which is the specific instance pointed by the reference variable. The method of the object is the method of the object running in the memory, not the method defined in the type of the reference variable.

11. Can an inner class reference members of its containing class? Are there any restrictions?

absolutely okay. If it's not a static inner class, there's no limit!

If you regard the static nested class as a special case of the inner class, then in this case you cannot access the ordinary member variables of the outer class, but you can only access the static members in the outer class.

Have you gotten these 11 frequently asked questions? If you encounter such a question next time you go for an interview, I hope you can answer it fluently and get an offer from your favorite company as soon as possible!

Related recommendations:Getting started with java

The above is the detailed content of Do you know what technical difficulties are often encountered in Java interviews?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template