1. The difference between String, StringBuffer and StringBuilder
(Related tutorial recommendations: java interview questions)
The value of String is immutable, which results in a new String object being generated every time an operation is performed on String.
Objects of the StringBuffer and StringBuilder classes can be modified multiple times without generating new unused objects
The speed is: StringBuilder > StringBuffer > String
The biggest difference between the StringBuilder class and StringBuffer is that StringBuilder's methods are not thread-safe.
Look at the picture:
(Recommended tutorial: java entry program)
2. All All classes inherit from the object class. What are the direct subclasses of the object class that you have used? What are the commonly used methods of the object class?
Boolean
Character
Class
ClassLoader
Compiler
Enum
String
System
Thread
Common methods of Object class
toString ();
- ## equals();
- hashCode();
3. What are generics, how are they used, and what are their benefits?
is a special type that defers the work of type clarification until when the object is created or the method is called. Parameterized type, pass the type as a parameter. It is a design pattern that supports polymorphism very well, such as various containers. Benefits: Advances runtime problems to the compilation period, avoiding forced type conversion.4. Why should serialversionUID be used for Java object serialization?
1. Why serialize objects?- The process of converting objects into byte sequences is called object serialization
- The process of restoring a byte sequence into an object is called object deserialization
java video tutorial)
5. Advantages and disadvantages of reflection
1. AdvantagesReflection improves the flexibility and scalability of Java programs, reduces coupling, and improves adaptive capabilities. It allows programs to create and control objects of any class without raising the hard-coded target class. Reflection is not available in some other commonly used languages, such as C, C, Fortran or Pascal. Java reflection technology has a wide range of applications, such as software testing, JavaBean, etc. Many popular open source frameworks such as Struts, Hibernate, and Spring use this technology in their implementation. 2. Disadvantages (1) Performance OverheadReflection includes some dynamic types, so the JVM cannot optimize these codes. Therefore, reflective operations are much less efficient than those non-reflective operations. We should avoid using reflection in frequently executed code or in programs with high performance requirements. (2) Security RestrictionsUsing reflection technology requires that the program must run in an environment without security restrictions. This is a problem if a program must run in a security-restricted environment, such as an applet. . (3) Exposure of InternalsSince reflection allows code to perform some operations that are not allowed under normal circumstances (such as accessing private properties and methods), using reflection may cause leading to unexpected side effects. The code has functional errors that reduce portability. Reflective code breaks abstraction, so when the platform changes, the behavior of the code may also change.The above is the detailed content of Collection of classic Java interview questions (3). 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

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 English version
Recommended: Win version, supports code prompts!

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Linux new version
SublimeText3 Linux latest version

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
