In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you the "java primary development interview questions", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "what are the java primary development interview questions" this article.
What are the aspects of object-oriented features?
Abstract:
Abstraction is to ignore aspects of a topic that have nothing to do with the current goal in order to pay more attention to the aspects related to the current goal. The abstraction does not intend to understand all the problems, but only chooses some of them, without some details for the time being. Abstraction includes two aspects, one is process abstraction, the other is data abstraction.
Inheritance:
Inheritance is a hierarchical model that joins classes and allows and encourages class reuse. It provides a way to clearly express commonalities. A new class of an object can be derived from an existing class, a process called class inheritance. The new class inherits the characteristics of the original class, which is called the derived class (subclass) of the original class, and the original class is called the base class (parent class) of the new class. A derived class can inherit methods and instance variables from its base class, and the class can modify or add new methods to better suit specific needs.
Encapsulation:
Encapsulation surrounds the process and data, and access to the data can only be accessed through a defined interface. Object-oriented computing begins with the basic concept that the real world can be depicted as a series of fully autonomous, encapsulated objects that access other objects through a protected interface.
Polymorphism:
Polymorphism means that objects of different classes are allowed to respond to the same message. Polymorphism includes parametric polymorphism and inclusion polymorphism. Polymorphic language has the advantages of flexibility, abstraction, behavior sharing and code sharing, which solves the problem of the same name of application function very well.
Is String the most basic data type? What are the basic data types?
The basic data types include byte, int, char, long, float, double, boolean, and short.
The java.lang.String class is of type final, so it cannot be inherited or modified. To improve efficiency and save space, we should use the StringBuffer class
What's the difference between int and Integer?
Java provides two different types: reference type and primitive type (or built-in type). Int is the raw data type of java, and Integer is the wrapper class provided by java for int. Java provides wrapper classes for each primitive type.
Primitive type wrapper class
BooleanBoolean
CharCharacter
ByteByte
ShortShort
IntInteger
LongLong
FloatFloat
DoubleDouble
The behavior of the reference type and the original type is completely different, and they have different semantics. Reference types and primitive types have different characteristics and uses, including size and speed issues, which type of data structure this type is stored in, and the default values specified when the reference type and the original type are used as instance data for a class. The default value of object reference instance variables is null, while the default values of primitive type instance variables are related to their types.
The difference between String and StringBuffer?
The JAVA platform provides two classes: String and StringBuffer, which can store and manipulate strings, that is, character data that contains multiple characters. This String class provides a string whose values are immutable. The string provided by this StringBuffer class is modified. You can use StringBuffer when you know that the character data is about to change. Typically, you can use StringBuffers to dynamically construct character data.
What are the similarities and differences between runtime exceptions and general exceptions?
The exception indicates the abnormal state that may occur during the running of the program, and the run-time exception represents the exception that may be encountered in the usual operation of the virtual machine, which is a common running error. The java compiler requires methods to declare that non-runtime exceptions may occur, but not to declare that uncaught runtime exceptions must be thrown.
Name the life cycle of Servlet and tell the difference between Servlet and CGI.
After Servlet is instantiated by the server, the container runs its init method, runs its service method when the request arrives, and the service method automatically dispatches to run the doXXX method (doGet,doPost) corresponding to the request, and calls its destroy method when the server decides to destroy the instance.
Servlet is different from cgi in that it runs its service method in a multi-threaded way. An instance can serve multiple requests, and its instances are generally not destroyed, while CGI generates a new process for each request and destroys it after the service is completed, so it is less efficient than servlet.
Storage performance and characteristics of ArrayList,Vector, LinkedList
Both ArrayList and Vector use an array to store data. The number of elements in this array is larger than the actual stored data in order to add and insert elements. They both allow elements to be indexed directly by ordinal numbers, but inserting elements involves memory operations such as array element movement, so index data is fast and data insertion is slow. Vector usually performs worse than ArrayList due to the use of synchronized method (thread safety), while LinkedList uses two-way linked lists to achieve storage. Indexing data by ordinal number requires forward or backward traversal, but when inserting data, you only need to record the front and back items of this item, so the insertion speed is faster.
What technologies are used to implement EJB? And tell the difference between SessionBean and EntityBean, the difference between StatefulBean and StatelessBean.
EJB includes Session Bean, Entity Bean, Message Driven Bean, based on JNDI, RMI, JAT and other technologies.
SessionBean is used in J2EE applications to perform server-side business operations, such as accessing databases and calling other EJB components. EntityBean is used to represent the data used in the application system.
To the client, SessionBean is a non-persistent object that implements some business logic running on the server.
For clients, an EntityBean is a persistent object that represents an object view of an entity stored in persistent storage, or an entity implemented by an existing enterprise application.
Session Bean can also be subdivided into Stateful Session Bean and Stateless Session Bean, both of which can execute system logic in method, except that Stateful Session Bean can record the status of callers, so generally speaking, a user will have an entity corresponding to Stateful Session Bean. Stateless Session Bean is also a logical component, but it is not responsible for recording user status, that is, when a user calls Stateless Session Bean, EJB Container does not look for a specific Stateless Session Bean entity to execute the method. In other words, it is very likely that when several users execute the methods of a Stateless Session Bean, it will be the Instance of the same Bean. From a memory point of view, Stateful Session Bean compared with Stateless Session Bean, Stateful Session Bean will consume more memory of J2EE Server, but the advantage of Stateful Session Bean is that it can maintain the state of the user.
The difference between Collection and Collections.
Collection is the parent interface of the collection class, and the main interfaces inherited from it are Set and List.
Collections is a helper class for collection classes. It provides a series of static methods to search, sort, thread-safe, and so on.
The difference between & and & &.
& is a bitwise operator for bitwise and operation, and & & is a logical operator for logic and (and).
The difference between HashMap and Hashtable.
HashMap is a lightweight implementation of Hashtable (a non-thread-safe implementation). They all complete the Map interface. The main difference is that HashMap allows null (null) keys (key), which may be more efficient than Hashtable because of non-thread safety.
HashMap allows null to be a key or value of an entry, while Hashtable does not.
HashMap removed Hashtable's contains method and changed it to containsvalue and containsKey. Because the contains method is easily misleading.
Hashtable inherits from the Dictionary class, and HashMap is an implementation of Map interface introduced by Java1.2.
The biggest difference is that Hashtable's method is Synchronize, while HashMap is not. When multiple threads access Hashtable, they do not need to synchronize their methods themselves, and HashMap must provide external synchronization for it (if it is ArrayList:List lst = Collections.synchronizedList (new ArrayList ()); if it is HashMap:Map map = Collections.synchronizedMap (new HashMap ());).
Hashtable and HashMap both use roughly the same hash/rehash algorithm, so there won't be much difference in performance.
The difference between final, finally and finalize.
Final is used to declare properties, methods, and classes, respectively, indicating that properties are immutable, methods are not overridden, and classes are not inheritable.
Finally is part of the structure of the exception handling statement, which means that it is always executed.
Finalize is a method of the Object class, which is called when the garbage collector executes, and can override other resource collection when this method provides garbage collection, such as closing files, and so on.
What's the difference between sleep () and wait ()?
Sleep is a method of the thread class (Thread), which causes this thread to suspend execution for a specified time and give the execution opportunity to other threads, but the monitoring state is maintained and will be automatically restored later. Calling sleep does not release the object lock.
Wait is a method of the Object class. Calling the wait method on this object causes the thread to abandon the object lock and enter the waiting lock pool waiting for the object. Only after the notify method (or notifyAll) is issued against this object can the thread enter the object lock pool and get ready to acquire the object lock and enter the running state.
The difference between Overload and Override. Can the method of Overloaded change the type of return value?
The rewriting Overriding and overloading Overloading of the method are different manifestations of Java polymorphism. Rewriting Overriding is a manifestation of polymorphism between parent and child classes, and overloading Overloading is a manifestation of polymorphism in a class. If a method is defined in a subclass with the same name and parameters as its parent class, we say that the method is Overriding. When an object of a subclass uses this method, the definition in the subclass is called, and for it, the definition in the parent class seems to be "masked". If multiple methods of the same name are defined in a class, they either have a different number of parameters or have different parameter types, it is called Overloading of the method. The method of Overloaded is that you can change the type of return value.
What's the difference between error and exception?
Error says recovery is a serious problem in situations that are not impossible but difficult. For example, memory overflow. It is impossible to expect the program to handle such a situation.
Exception represents a design or implementation problem. That is, it means that if the program works properly, it will never happen.
What are the similarities and differences between synchronous and asynchronous, and under what circumstances do you use them respectively? Give an example.
If the data will be shared between threads. For example, the data being written may later be read by another thread, or the data being read may have been written by another thread, then the data is shared data and must be accessed synchronously.
When an application calls a method on an object that takes a long time to execute, and you don't want the program to wait for the method to return, you should use asynchronous programming, which is often more efficient in many cases.
What's the difference between abstract class and interface?
A class that declares the existence of a method without implementing it is called an abstract class, which is used to create a class that reflects some basic behavior and declare methods for the class, but cannot implement the class in the class. You cannot create an instance of the abstract class. However, you can create a variable whose type is an abstract class and point to an instance of a concrete subclass. There can be no abstract constructor or abstract static method. The subclasses of the Abstract class provide implementations for all abstract methods in their parent class, otherwise they are also abstract classes. Instead, implement the method in a subclass. Other classes that know their behavior can implement these methods in the class.
The interface (interface) is a variant of the abstract class. In an interface, all methods are abstract. Multiple inheritance can be achieved by implementing such an interface. All the methods in the interface are abstract, and none of them has a program body. Interfaces can only define static final member variables. The implementation of an interface is similar to a subclass, except that the implementation class cannot inherit behavior from the interface definition. When a class implements a particular interface, it defines (that is, given by the program body) the methods of all such interfaces. It can then call the methods of the interface on any object of the class that implements the interface. Because of the abstract class, it allows the interface name to be used as the type of the reference variable. The usual dynamic linking will take effect. References can be converted to or from interface types, and the instanceof operator can be used to determine whether an object's class implements an interface.
What's the difference between heap and stack.
The stack is a linear collection in which the addition and deletion of elements should be completed in the same segment. The stack is processed on a last-in-first-out basis.
A stack is a constituent element of a stack
The difference between forward and redirect
Forward is a resource requested by the server. The server directly accesses the URL of the target address, reads the response content of that URL, and then sends it to the browser. The browser has no idea where the content sent by the server comes from, so its address bar is still the original address.
Redirect means that the server sends a status code according to logic, telling the browser to request that address again. Generally speaking, the browser will re-request with all the parameters just requested, so the session,request parameters can be obtained.
The difference between EJB and JAVA BEAN?
Java Bean is a reusable component, and there is no strict specification for Java Bean. Theoretically, any Java class can be a Bean. In general, however, because Java Bean is created by a container (such as Tomcat), Java Bean should have a no-parameter constructor, and usually Java Bean also implements the Serializable interface for Bean persistence. Java Bean is actually equivalent to the local in-process COM component in the Microsoft COM model, and it cannot be accessed across processes. Enterprise Java Bean is equivalent to DCOM, that is, distributed components. It is based on Java's remote method invocation (RMI) technology, so EJB can be accessed remotely (across processes, across computers). But EJB must be deployed in containers such as Webspere, WebLogic, and EJB customers never access the real EJB components directly, but through their containers. EJB containers are proxies for EJB components, and EJB components are created and managed by the container. The customer accesses the real EJB component through the container.
The difference between Static Nested Class and Inner Class.
Static Nested Class is an inner class that is declared static (static) and can be instantiated without relying on external class instances. The usual inner class can only be instantiated after the external class is instantiated.
What is the difference between dynamic INCLUDE and static INCLUDE in JSP?
Dynamic INCLUDE is implemented with jsp:include actions. It always checks for changes in the files it contains, is suitable for including dynamic pages, and can take parameters.
Static INCLUDE is implemented with include pseudo code, and will not check the changes of the files it contains. It is suitable for containing static pages.
When to use assert.
Assertion (assertion) is a common debugging method in software development, and this mechanism is supported in many development languages. In implementation, assertion is a statement in the program, it checks a boolean expression, a correct program must ensure that the value of the boolean expression is true; if the value is false, indicating that the program has been in an incorrect state, the system will give warning or exit. Generally speaking, assertion is used to ensure the most basic and critical correctness of the program. Assertion checking is usually turned on during development and testing. To improve performance, assertion checking is usually turned off after the software is released.
What is GC? Why is there a GC?
GC means garbage collection (Gabage Collection). Memory processing is a place where programmers are prone to problems. Forgetting or incorrect memory collection will lead to instability or even collapse of the program or system. The GC function provided by Java can automatically monitor whether the object exceeds the scope so as to achieve the purpose of automatic memory collection. Java language does not provide a display operation method to release allocated memory.
Short S1 = 1; S1 = S1 + 1; what's wrong with it? Short S1 = 1; S1 + = 1; what's wrong with it?
Short S1 = 1; S1 = S1; (the result of S1 = S1 is int, and the type needs to be cast)
Short S1 = 1; S1 + = 1; (can be compiled correctly)
How much is Math.round (11.5)? How much is Math.round (- 11.5)?
Math.round (11.5) 12
Math.round (- 11.5)-11
The round method returns the long integer closest to the parameter, and the parameter is added by 1 / 2 to find its floor.
String s = new String ("xyz"); how many String Object have been created?
Two.
Design 4 threads, of which two threads increase by 1 for j at a time, and the other two threads decrease by 1 for j at a time. Write the program.
The following program uses internal classes to implement threads without considering the order when adding or subtracting j.
Private int Jistine public static void main (String args []) {ThreadTest1 tt=new ThreadTest1 (); Inc inc=tt.new Inc (); Dec dec=tt.new Dec (); for (int item0polii)
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.