


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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Choosing a Docker image for Node may seem like a trivial matter, but the size and potential vulnerabilities of the image can have a significant impact on your CI/CD process and security. So how do we choose the best Node.js Docker image?

Cross-domain is a scenario often encountered in development, and it is also an issue often discussed in interviews. Mastering common cross-domain solutions and the principles behind them can not only improve our development efficiency, but also perform better in interviews.

The Go framework is a set of components that extend Go's built-in libraries, providing pre-built functionality (such as web development and database operations). Popular Go frameworks include Gin (web development), GORM (database operations), and RESTful (API management). Middleware is an interceptor pattern in the HTTP request processing chain and is used to add functionality such as authentication or request logging without modifying the handler. Session management maintains session status by storing user data. You can use gorilla/sessions to manage sessions.

The JS singleton pattern is a commonly used design pattern that ensures that a class has only one instance. This mode is mainly used to manage global variables to avoid naming conflicts and repeated loading. It can also reduce memory usage and improve code maintainability and scalability.

What is JPA? How is it different from JDBC? JPA (JavaPersistence API) is a standard interface for object-relational mapping (ORM), which allows Java developers to use familiar Java objects to operate databases without writing SQL queries directly against the database. JDBC (JavaDatabaseConnectivity) is Java's standard API for connecting to databases. It requires developers to use SQL statements to operate the database. JPA encapsulates JDBC, provides a more convenient and higher-level API for object-relational mapping, and simplifies data access operations. In JPA, what is an entity? entity

How does JavaScript determine data type? This article will share with you 8 ways to use JS to determine data type, which can effectively help work and interviews. The interviewer smiled slightly after reading it.

The url module and querystring module are two very important URL processing modules. It is often used when developing node servers.

Translator | Planning by Zhu Xianzhong | Xu Jiecheng Unlike other software development tools that developers trust, AI tools have some unique risks in terms of training, construction, hosting, and usage. Since the release of ChatGPT at the end of 2022, the Internet has been filled with arguments supporting and doubting it in almost equal proportions. Whether you like it or not, AI is making its way into your development organization. Even if you don’t plan to develop an AI product or leverage an AI tool to write the code for you, it may still be integrated into the tools and platforms used to build, test, and run source code. AI tools present some unique risks that may impact the productivity gains from automating tasks. These risks are mainly
