In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the frequently asked JAVA interview questions what the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this frequently asked JAVA interview questions which articles will have a harvest, let's take a look.
What is value passing and reference passing? Value transfer is for the basic variable, passing a copy of the variable, changing the copy does not affect the original variable. Reference passing is generally for object-type variables, passing a copy of the object's address, not the original object itself. It is generally believed that the transfer within java is the transfer of values. The passing of instance objects in java is reference passing.
Can I access non-static variables in the static environment? The static variable belongs to the class in Java, and its value is the same in all instances. The static variable is initialized when the class is loaded by the Java virtual machine. If your code tries to access non-static variables without instances, the compiler will report an error because the variables have not been created and have not been associated with any instances.
Explains the use of stack (stack), heap (heap), and method area (method area) in memory. Usually we define a variable of a basic data type, an object reference, and the on-site storage of function calls all use the stack space in JVM. The objects created by the new keyword and constructor are placed in the heap space, which is the main area managed by the garbage collector. because the current garbage collectors use generation-by-generation collection algorithms, the heap space can also be subdivided into the new generation and the old generation, and more specifically, it can be divided into Eden, Survivor (which can be divided into From Survivor and To Survivor) and Tenured. The method area and heap are memory areas shared by each thread, which are used to store class information, constants, static variables, JIT compiler compiled code and other data that have been loaded by JVM; literal in the program, such as directly written 100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100, and constants are all placed in the constant pool, which is a part of the method area. Stack space is the fastest to operate, but the stack is very small. Usually, a large number of objects are placed in the stack space, and the stack and heap size can be adjusted by the startup parameters of JVM. Running out of stack space will cause StackOverflowError, while insufficient heap and constant pool space will cause OutOfMemoryError.
What is the difference between an interface and an abstract class? From the design level, abstraction is the abstraction of the class, is a kind of template design, interface is the abstraction of behavior, is a kind of behavior specification.
Java provides and supports the creation of abstract classes and interfaces. Their implementations have something in common, but the difference is that all the methods in the * * interface are abstract. Abstract classes can contain both abstract and non-abstract methods. **
A class can implement many interfaces, but it can only inherit all the methods that an abstract class can not implement an abstract class and interface declaration, in which case the class must also be declared abstract.
An abstract class can implement an interface without providing an interface method implementation. * * the variables declared in the Java API are all final by default. Abstract classes can contain variables that are not final. The member function in the Java interface is public by default. The member function of an abstract class can be private,protected or public. **
Interfaces are absolutely abstract and cannot be instantiated. An abstract class cannot be instantiated either, but it can be called if it contains a main method. You can also refer to the difference between abstract classes and interfaces in JDK8.
What is the difference between String, StringBuilder and StringBuffer? The Java platform provides two types of strings: String and StringBuffer/StringBuilder, which can store and manipulate strings. Where String is a read-only string, which means that the string content referenced by String cannot be changed. The string object represented by the StringBuffer/StringBuilder class can be modified directly. StringBuilder, introduced in Java 5, is exactly the same as StringBuffer's approach, except that it is used in a single-threaded environment, because none of its aspects are modified by synchronized, so it is also more efficient than StringBuffer.
If the hashcode of the two keys is the same, how do you get the value object? When we call the get () method, HashMap uses the hashcode of the key object to find the bucket location, then calls the keys.equals () method to find the correct node in the linked list, and finally finds the value object it is looking for.
What's the difference between HashMap and Hashtable? 1. HashMap is not thread-safe, HashTable is thread-safe.
2. Null values are allowed for HashMap keys and values, but not for HashTable.
3. Because of thread safety, HashMap is more efficient than HashTable.
4. Hashtable is synchronous, but HashMap is not. Therefore, HashMap is more suitable for single-threaded environments, while Hashtable is more suitable for multithreaded environments.
Generally speaking, it is not recommended to use HashTable now. ① is HashTable is a legacy class, and many internal implementations are not optimized and redundant. Even in a multithreaded environment, ② now has a synchronous ConcurrentHashMap alternative, and there is no need to use HashTable because it is multithreaded.
How to decide whether to choose HashMap or TreeMap? HashMap is the best choice for operations such as inserting, deleting, and locating elements in Map. However, if you need to traverse an ordered key collection, TreeMap is the better choice. Depending on the size of your collection, it may be faster to add elements to HashMap, and replace map with TreeMap for orderly key traversal.
This is the end of the article on "what are the frequently asked JAVA interview questions?" Thank you for reading! I believe you all have a certain understanding of the knowledge of "what are the frequently asked JAVA interview questions". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.