Java interview topic Daquan :)

xiaoxiao2021-03-05  29

1. What are the object-oriented features 1. Abstraction: Abstract is ignored those aspects that have nothing to do with the current goals in a topic in order to pay more attention to the current goals. Abstract does not intend to understand all the questions, but just choose some of them, temporarily do not use some details. Abstract includes two aspects, one is abstract, and the other is data abstraction. 2. Inheritance: Inherit is a hierarchical model of a linkage, and allows and encourages the reuse of classes, which provides a clear expression of a commonality. A new class of an object can be derived from the existing class, which is called class inheritance. New categories inherit the characteristics of the original class, the new class is called the original class (subclass), and the original class is called a new class (parent class). Detective classes can inherit methods and instance variables from its base class, and class can modify or add new methods to make it more suitable for special needs. 3. Package: The package is surrounded by the process and data, and the access to the data can only pass through the defined interface. Object-oriented calculations began in this basic concept, that is, the real world can be depicted into a series of complete autonomous, encapsulated objects, which access other objects through a protected interface. 4. Polymorphism: Polymorphism means that different class objects are allowed to respond to the same message. Polymorphisms include parameterized polymorphisms and polymorphisms. The polymorphic language has the advantages of flexible, abstract, behavioral sharing, code sharing, and well solves the application function of the same name. 2, String is the most basic data type? Basic data types include Byte, int, char, long, float, double, boolean, and short. The java.lang.string class is final type, so this class cannot be inherited, and this class cannot be modified. In order to improve efficiency, we should use StringBuffer class 3, int and integer to provide two different types: reference types and original types (or built-in types). INT is the original data type of Java, and Integer is a package class provided by Java for INT. Java provides package classes for each original type. The original type package BooleanBooleanCharChacterbytebyteshortShortintintegerlongLongFloatFloatDoubledouble reference type and the original type of behavior is completely different, and they have different semantics. Reference Types and Original Types have different features and usage, including: size and speed problems, this type of data structure store, when the reference type and the original type are used as an instance data of a class Default. The default value of the object reference instance variable is NULL, and the default value of the original type instance variable is related to their type. 4, the difference between String and StringBuffer Java platform provides two classes: String and StringBuffer, which can store and operate strings, which contain characters data of multiple characters. This String class provides a string of values ​​that cannot be changed. The string provided by this StringBuffer class is modified. You can use StringBuffer when you know that character data is changed. Typically, you can use StringBuffers to dynamically construct character data. 5. What is the difference between abnormality at runtime? An abnormality indicates the abnormal state of the program during operation, and the runtime exception indicates an exception that may be encountered in the usual operation of the virtual machine is a common run error. The Java compiler requires that the method must declare that the possible non-running abnormality, but does not require a statement that the abnormality that is not captured. 6. Say the life cycle of the servlet and say the difference between servlet and cgi.

After the servlet is instantiated by the server, the container runs its init method, the request is reached, the service method is automatically dispatched with the DOXXX method (Doget, DOPOST) corresponding to the request, and calls its Destroy when the server decides to destroy the instance. method. The difference from the CGI is that the servlet is in the server process, which runs its service method by multithreading, and an instance can serve multiple requests, and its instance is generally not destroyed, and CGI has a new process for each request. After the service is completed, it is destroyed, so it is less efficient than servlet. 7. Say that ArrayList, Vector, LinkedList's storage performance and feature ArrayList and Vector are stored in an array. The number of elements is greater than actually stored in order to increase and insert elements, they all allow direct sequence number index elements, but Inserting elements should involve memory operation such as array elements, so the index data is fast and inserted, and the vector is used by the Synchronized method (thread security), and LinkedList uses a two-way linked list to store, according to serial number index Need to be forward or rearward, but only the front and rear items of this item are required when inserting data, so the insert is faster. 8, EJB is based on which technologies are implemented? And said the difference between SessionBean and EntityBean, the difference between STATEFULBEAN and STATELESSBEAN. EJB includes session beans, Entity Beans, JNDI, RMI, JAT, etc. SessionBean is used in the J2EE application to complete some server-side business operations, such as accessing the database, calling other EJB components. EntityBean is used to represent the data used in the application system. For clients, SessionBean is a non-persistent object that implements certain business logic running on the server. For clients, EntityBean is a persistent object that represents an object view that stores entities in a persistent memory, or an entity implemented by existing enterprise applications. Session Bean can also be subdivided into Stateful Session Bean with Stateless Session Bean. Both Session beans can perform system logic in Method, and the different is the stateful session bean to record the caller's status, so usually Say, a user will have an entity of a corresponding Stateful Session bean. Although Stateless Session Bean is also a logical component, but he is not responsible for recording the user's state, that is, when the user calls Stateless Session Bean, EJB Container does not look for the specific STATELESS SESSION BEAN entity to perform this Method. In other words, it is very likely that several users are executing the same bean's instance when executing a STATELESS SESSION bean's Methods. From memory, Stateful Session Bean compares the STATELESS SESSION bean, and Stateful Session Bean consumes more memory more than J2EE Server, but the advantage of the Stateful Session bean is that he can maintain the status of the user.

9, the difference between Collection and Collectes. Collection is the superiors of the collection class, inheriting the interface with his interface, mainly SET and List.Collections are a help class for the collection class, and he provides a series of static methods to achieve search, sorting, thread security for various sets. . 10, & and &&. & A bit operator, representing bit and operation, && is a logical operator, representing logic and (AND). 11, the difference between HashMap and HashTable. HashMap is a lightweight implementation of HashTable (non-thread security), they all completed the MAP interface, mainly distinguishing the HashMap allows empty (NUY) key value (key), due to non-threaded security, efficiency may be higher than HashTable. Hashmap allows null as a key or value of Entry, while HashTable is not allowed. Hashmap removes the HashTable's Contains method, changed to ContainSvalue and Containskey. Because the Contains method is easy to cause misunderstandings. HashTable inherits from the Dictionary class, and HashMap is an implementation of the Map Interface introduced by Java 1.2. The biggest difference is that the HashTable method is Synchronize, and HashMap is not, when accessed HashTable, does not need to be synchronized for its method, and HashMap must provide external synchronization. Hash / rehash algorithms used by HashTable and Hashmap are probably, so performance will not have a big difference. 12, Final, Finally, Finalize distinction. Final is used to declare attributes, methods, and classes, indicate that attributes are unambiguous, and the method is not covered, and the class cannot be inherited. Finally is part of an exception handling statement structure, which is always executed. Finalize is a method of the Object class. This method of recycling object is called when the garbage collector is executed, and other resource recycles when this method is available, such as turning off files. 13, SLEEP () and WAIT () What is the difference? Sleep is a thread method, causing this thread to suspend the specified time, give other threads, but monitoring status remains, and automatically recovered . Calling SLEEP does not release the object lock. WAIT is the object of the object class. Call the WAIT method for this object causes the lecture to abandon the object lock. Enter the waiting lock pool waiting for this object, only the NOTIFY method (or NotifyAll) is issued after this object, after entering the object lock pool ready to get Object locks enter the operating state. 14, the difference between overload and override. OverLoaded method can change the type of return value? Override Overriding and overload overloading is a different manifestation of Java polymorphism. Overriding Overriding is a manifestation of polymorphism between parent class and subclasses, and overloading overloading is a manifestation in a class. If a method is defined in the subclass with the same name and parameters as its parent class, we say that this method is overriddled. When the subject of subclass uses this method, the definition of the subclass will be called. For it, the definition in the parent class is like "shielded". If a plurality of the same names are defined in a class, they or have different parameters or different parameter types, called overloading.

The way OVERLOADED is to change the type of return value. 15. What is the difference between ERROR and EXCEPTION? Error indicates a serious problem that recovery is not impossible but difficult. For example, memory is overflow. It is impossible to expect the program to handle this situation. Exception represents a design or implementation problem. That is, it means that if the program runs normally, it will never occur. 16. How is it in synchronization and asynchronous, in what circumstances use them? for example. If the data will be shared between the thread. For example, the data being written may 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 synchronously. When an application calls a method that takes a long time to perform, it is often used asynchronous programming when it takes a long time to perform, and it is often more efficient in many cases. 17. What is the difference between Abstract Class and Interface? The presence of a declaration method does not implement its class called an abstract class, which is used to create a class that reflects certain basic behaviors and declares the class declaration method. However, this class cannot be implemented in this class. An instance of the Abstract class cannot be created. However, you can create a variable, which is an abstract class and let it point to an instance of the specific subclass. There is no abstract constructor or abstract static method. Subclasses of the Abstract class provide implementation for all abstraction methods in their parent class, otherwise they are also abstract classes. Instead, this method is implemented in the subclass. Other classes that know their behavior can be implemented in the class. Interface is a variant of an abstract class. In the interface, all methods are abstract. Multiple inheritance can be obtained by achieving such an interface. All methods in the interface are abstract, no probabilities. The interface can only define the Static Final member variable. The implementation of the interface is similar to the subclass, except that the implementation class cannot inherit behavior from the interface definition. When the class implements a special interface, it defines the method of all such an interface (that is, the program body is given). Then, it can call the interface to call the interface on any object of the class of the interface. Because there is an abstract class, it allows the interface name as the type of reference variable. The usual dynamic cable will take effect. The reference can be converted to an interface type or a slave interface type, and the InstanceOf operator can be used to determine whether an object is implemented. 18. What is the difference between Heap and Stack. The stack is a linear set, and the operation of adding and deleting elements should be completed in the same paragraph. The stack is processed in the way in which it is advanced. Stack is a constituent element 19, forward and redirect's difference Forward is a server request resource. The server directly accesses the URL of the target address, reads the URL's response content, and then send these content to the browser, browser I don't know where the content sent by the server is from, so it is still the original address. Redirect is the server according to the logic, send a status code, telling the browser to re-request that address, generally saying that the browser re-requests all the parameters just requested, so session, the request parameter can be obtained. 20. The difference between EJB and Java Bean? Java bean is a reused component that does not have a strict specification for Java Bean. In theory, any Java class can be a bean. In general, since the Java bean is created (such as Tomcat) by the container, the Java Bean should have a 11-free constructor, in addition, the Java Bean also implements the Serializable interface to implement the persistence of beans. Java Bean is actually equivalent to the COM component in the local process in the Microsoft COM model, which cannot be accessed across the process.

Enterprise Java Bean is equivalent to DCOM, ie distributed components. It is based on Java-based remote method call (RMI) technology, so EJB can be remotely accessed (cross processes, cross-computers). But EJB must be deployed in a container such as WebSpere, WebLogic, and EJB customers never access true EJB components, but access them through their container. The EJB container is an agent of EJB components, and the EJB component is created and managed by the container. The client accesses the real EJB component through the container. 21, Static Nested Class and Inner Class are different. Static NESTED CLASS is an internal class that is declared as static (STATIC), which can not depend on external class instances being instantiated. The usual internal classes need to be instantiated after instantification of external classes. 22. Different Dynamic Include and Static Include in JSP? Dynamic include uses JSP: Include action to implement It always checks changes in the file included in the file, suitable for use with dynamic pages, and can with parameters. Static include 码 码 码.............................. Assertion is a commonly used commissioning in software development, and this mechanism is supported in many development languages. In the implementation, Assertion is a statement in the program that checks a Boolean expression. A correct program must ensure that this Boolean expression is true; if the value is false, the program is already in an incorrect state. Next, the system will give a warning or exit. In general, Assertion is used to ensure the most basic and key correctness of the program. Assertion checks are usually opened when developed and tested. In order to improve performance, the assertion check is usually closed after the software is released.

24. What is GC? Why do you have GC? GC is the meaning of garbage collection, memory processing is where programmers are prone to problems, and forget or erroneous memory recovery will cause the program or system unstable or even crash. The GC function provided by Java can automatically monitor whether objects exceed the scope to reach the automatic recycling memory, and the Java language does not provide a display operation method that has been allocated. 25, short s1 = 1; S1 = S1 1; What is wrong? SHORT S1 = 1; S1 = 1; What is wrong? Short S1 = 1; S1 = S1 1; (S1 1 calculation result is int Type, need forced conversion type) Short S1 = 1; S1 = 1; (can be correctly compiled) 26, Math.Round (11.5) is equal to how much? Math.Round (11.5) = = 12Math.Round (-11.5) == - 11Round method Returns the length of the parameters closest, the parameter plus 1/2 is followed by its floor.27, string s = new string ("xyz"); create a few String Object? Two 28, design 4 threads, two threads increase 1 each time two, and the other two threads are reduced each time. Write the program. The following procedure uses internal classes to implement threads, and no order issues are not considered when J is reduced. Public class threadtest1 {private int j; public static void main (string args []) {threadtest1 tt = new threadtest1 (); incin = tt.new inc (); DEC = tt.new dec (); for (int i = 0; i <2; i ) {thread t = new thread (inc); t.start (); t = new thread (dec); t.start ();}} private synchronized void inc () {J System.out.println (thread.currentthread (). GetName () "- inc:" J);} private synchronized void dec () {j -; system.out.println (thread.currentthread (). GetName () "- DEC:" J);} Class incmplements Runnable {public void run () {for (int i = 0; i <100; i ) {inc ();}}} Class Dec Implements Runnable {PUBLIC VOID RUN () {for (INT i = 0; i <100; I ) {dec ();}}}} 29. Is there a reserved word in goto? Java, and now not use in Java. 30. Starting a thread is Run () or start ()? Starting a thread is to call the start () method so that the virtual processor represented by the thread is in operation, which means it can be scheduled and executed by the JVM. This doesn't mean that the thread will run immediately. The Run () method can generate a flag that must be exited to stop a thread.

31, EJB includes (sessionbean, entitybean) says their life cycle, and how to manage transactions? The lifecycle of the STASSIONBEAN: STATELESS session bean is determined by the container. When the client issues a request to establish a bean instance, the EJB container does not have to create a new bean instance for client call, but a place to find a present Some instances are provided to the client. When the client calls a stateful session bean for the first time, the container must immediately create a new bean instance in the server, and related to the client, after this client calls the Stateful session bean method, the container will assign the call to This client is associated with a bean instance. EntityBean: Entity Beans can survive relatively long time, and status is continuous. Entity Beans has always survive as long as the data in the database exists. Not in accordance with the application or service process. Even if the EJB container crashes, Entity Beans is also survived. The Entity Beans life cycle can be managed by the container or Beans. EJB is implemented by the following technical management practices: Object Management (OMG) Object Service (OTS), Sun Microsystems Transaction Service (JTS), Java Transaction API (JTA), Development Group (X / Open) XA interface. 32. What are the application servers? BEA WebLogic Server, IBM WebSphere Application Server, Oracle9i Application Server, JBoss, Tomcat33, gives me a Runtime Exception you most often seen. ArithmeticException, ArrayStoreException, BufferOverflowException, BufferUnderflowException, CannotRedoException, CannotUndoException, ClassCastException, CMMException, ConcurrentModificationException, DOMException, EmptyStackException, IllegalArgumentException, IllegalMonitorStateException, IllegalPathStateException, IllegalStateException, ImagingOpException, IndexOutOfBoundsException, MissingResourceException, NegativeArraySizeException, NoSuchElementException, NullPointerException, ProfileDataException, ProviderException, RasterFormatException, SecurityException, SystemException, undeclaredthrowableException, unmodifiableSetException, UNSUPPORTEDOPERATIONEXCEPTION34, whether the interface can inherit the interface? Does the abstract class be implemented? Does the abstract class can inherit the physical class (Concrete Class)? The interface can inherit the interface.

Abstract classes can be implemented, whether abstract classes can inherit physical classes, but provided that the entity class must have a clear constructor. 35, List, SET, MAP inherits from the Collection interface? List, SET is not 36, how is the working mechanism of the data connection pool? J2EE server starts a certain number of pool connections, and maintain a lot Connects to this number of pools. When the client program needs to be connected, the pool driver returns an unused pool connection and exposes its expression as busy. If there is currently no idle connection, the pool driver has created a certain number of connections, and the number of new connections has configured parameters. When the pool connection call is used, the pool driver is idle, and this connection can be used in other calls. 37. Is Abstract's Method can be static at the same time, whether it is native at the same time, can you be synchronized? The array does not have Length () method, with the properties of the length. String has a length () method. 39, the elements in the set cannot be repeated, then what method is used to distinguish whether it is repeated? Is it == or equals ()? What is the difference? The element in the set cannot be repeated, then use Iterator () The method is distinguished from whether it is repeated. Equals () is the judgment of whether two SETs are equal. Equals () and == Method Decide whether the reference value points to the same object Equals () override in the class, which is the true value of the content and type of two separate objects. 40, whether the constructor can be ca not inherited by the Override® constructor constructor, so Overriding cannot be overridden, but Overloading can be overloaded. 41, can you inherit the String class? The String class is that Final is not inherited. 42. If SWTICH can act on Byte, whether it can act on long, whether it can act on String? Switch (expr1), EXPR1 is an integer expression. Therefore, the parameters passing to the Switch and the CASE statement should be int, short, char or byte. Long, String can not work on SWTICH. 43, Try {} has a return statement, then the code keeps in finally {} after this try, will not be executed, when is executed, before returnome or after it will execute, execute before returnrate. 44. Programming: 2 multiply 8 equal to a few? 2 << 345, two object values ​​(x.equals (y) == true, but there can be different Hash Code, This sentence is wrong? Is wrong, there is the same hash code. 46. ​​After an object is passed as a parameter to a method, this method can change the properties of this object and return the resulting result, then here is the value delivery or reference delivery? Is a value transfer. Java programming languages ​​only value pass parameters. When an object instance is transmitted to the method as a parameter, the value of the parameter is a reference to the object. The content of the object can be changed in the called method, but the reference to the object will never change. 47. After a thread enters an SYNCHRONIZED method of an object, other methods of other threads can enter this object? No, one Synchronized method of an object can only be accessed by one thread. 48. Program: Write a Singleton out. The main role of the Singleton mode is to ensure that only one example exists in a Java application.

General Singleton mode usually has several forms: the first form: Define a class, its constructor is private, it has a state of static private, instantoneation, and GetInstance through a public Method Get a reference to it, then calls it. Public class singleton {private singleton ()} // define one instance in itself, is it very strange? / Note This is private only for internal calling private static singleton instance = new singleton (); // here provides a static method for external access to this Class, you can directly access public static singleton getInstance () {return instance;}} The second form: public class singleleton {private static singleleton instance = null; public static synchronized singleton getInstance () {// This method is improved above, do not have to generate an object each time, only the first time // Generate an instance and improve efficiency! IF (instance == null) instance = new start;}} Other forms: Define a class, its constructor is private, all methods are static. It is generally considered that the first form is to be more securely 49, Java interface, and the virtual class of C . Since Java does not support multi-inheritance, it is possible to use a class or object to use a method or attribute in several classes or objects, and existing single inheritance mechanisms cannot meet the requirements. Compared to inheritance, the interface has higher flexibility because there is no implementation code in the interface. When a class implements an interface, this class is to implement all methods and properties in the interface, and the properties in the interface are all public static below, all methods are public. Public. A class can implement multiple interfaces. 50. Simple principle and application of exception handling mechanism in Java. When the Java program violates the semantic rules of Java, the Java virtual machine will represent an error as an exception. Violation of semantic rules include 2 cases. One is a semantic check in the Java class library. For example, the array subscript can trigger indexoutofboundsexception; nullpointerException will be triggered when accessing null objects. Another situation is that Java allows programmers to extend this semantic check, and programmers can create their own exceptions and freely choose to trigger exceptions with throw keywords. All exceptions are subclasses of java.lang.thowable. 51, the advantages and principles of garbage collection. And consider 2 recycling mechanisms. A significant feature in the Java language is to introduce the garbage collection mechanism, which makes the problem of the most headache of C programmers, making the Java programmers no longer need to consider memory management when writing programs. Since there is a garbage collection mechanism, the object in Java no longer has the concept of "scope", and only the reference to the object has a "scope". Garbage recycling can effectively prevent memory leaks, effective use of memory that can be used. The garbage collector is usually operated as a separate low-level thread. In the case of unpredictable objects that have been died or have not used for a long time for a long time for a long time, the programmer cannot call the garbage collector in real time. Object or all objects are garbage collection.

The recycling mechanism has a replica collection of garbage collection and marking garbage recovery, incremental garbage recovery. 52. Please tell us how the thread synchronization you know. Wait (): Make a thread in the waiting state and release the LOCK of the object held. Sleep (): Make a running thread in sleep state, is a static method, call this method to capture InterruptedException exceptions. NOTIFY (): Wake up a thread in a waiting state, note that when this method is called, it is not exactly the thread that is awakened, but is determined by the JVM which thread is awake, and is not pressed. AllNotity (): Wake all threads in the waiting state, not to give all the locks of all awakening threads, but let them compete. 53, what are your collection? Main method? The most commonly used collections are LIST and MAP. The specific implementation of List includes ArrayList and Vector, which are variable-sized lists, which are more suitable for build, store, and operate any type of objects for any type object. List is suitable for use in value to access elements. Map provides a more versatile element storage method. The MAP set class is used to store element pairs (called "keys" and "value"), where each key is mapped to a value. 54. Describe the principle mechanism of the JVM load Class file? The load in JVM is implemented by ClassLoader and its subclass, Java ClassLoader is an important Java runtime system component. It is responsible for finding and putting a class file at runtime. 55. Can a Chinese Chinese character can be stored in the CHAR type variable? Why? Can definition becoming a Chinese, because Java is encoded in Unicode, a char accounts for 16 bytes, so putting a Chinese is no problem 56, multi-thread There are several implementation methods, what is it? Synchronize several implementation methods, what is the multi-threaded implementation method, which inherits the Thread class and implementation of the implementation of the Runnable interface synchronization, Synchronized, WAIT and NOTIFY57, JSP built-in objects and methods. Request represents the HTTPSERVLETREQUEST object. It contains information about the browser request and provides a number of methods for obtaining cookie, header, and session data. Response represents the HTTPSERVLETRESPONSE object and provides several methods for setting the response to the browser (such as cookies, header information, etc.) OUT objects are an instance of javax.jsp.jspwriter, and provide several ways to make you Used to return the output result to the browser. PageContext represents a javax.servlet.jsp.pageContext object. It is an API for convenient access to various range spaces, servlet-related objects, and wraps a generic Servlet related feature. Session represents a request Javax.Servlet.http.httpSession object. Session can store the user's status information Applicat represents a javax.servle.ServletContext object. This helps find information about the Servlet engine and the servlet environment represents a javax.servlet.servletConfig object. This object is used to access the initialization parameters of the servlet instance. Page Represents a servlet instance 58 generated from this page, the basic concept of the thread, the basic state of the thread, and the state of the relationship between the state, in the program execution, the execution unit of the program code can be executed, each program is at least A thread, that is, the program itself. There are four states in Java, respectively, running, ready, hang, and end.

59. Common instructions for JSP <% @ page language = "java" contentYpe = "text / html; charset = GB2312" session = "true" buffer = "64kb" autoflush = "TRUE" iSthreadsafe = "True" info = "text "ErrorPage =" error.jsp "iesrrorpage =" true "iSelignored =" true "pageEncoding =" gb2312 "import =" java.sql. * "%> ISELRPAGE (Can I use an Exception object), iSelignored (ignore express) <% @ include file = "filename"%> <% @ taglib prefix = "c" URI = "http: // ..."%> 60, what is calling doget () and dopost ()? The Method property in the FORM tag in the JSP page is called DOGET (), and dopost () is called for POST. 61. The lifecycle Web container loads servlet, and the lifecycle begins. The initialization of the servlet is performed by calling the servlet's init () method. Different DO *** () methods are called depending on the request different by calling the service () method. End the service, the Web container calls the servlet's Destroy () method. 62. How do I actually servlet's single-thread mode <% @ page isthreadsafe = "false"%> 63, the page inter-page object delivery method Request, session, application, cookie, etc. What is the connection between? JSP is an extension of servlet technology, essentially a simple way of servlet, and emphasizes the application's appearance expression. After JSP compiles "class servlet". The most important point of Servlet and JSP is that the application logic of servlet is in the Java file and is completely separated from the HTML in the representation. The case of JSP is that Java and HTML can be combined into a file that extension .jsp. JSP focuses on views, servlet is mainly used to control logic. 65. Four session tracking technology session scope servletsJSP page Description Page No is a representative object and attribute related to a page. A page is represented by a compiled Java Servlet class (which can have any include instructions, but no include action). This includes both servlets and JSP pages that are compiled into a servlet, is an object and attribute that represents a request issued to a web client. A request may span multiple pages, involving multiple web components (because the relationship between Forward Directions and Include Actions) Session is object and attributes related to a user experience with a web client. A web session can often span multiple clients to request Application is the object and attribute that represents the entire web application.

This is essentially across the entire Web applications, including multiple pages, requests, and a global session scope 66, the main method of the Request object: setAttribute (String name, Object): set the name of the parameter values ​​getAttribute request the name of ( String name): Returns GetAttributeNames (): Returns the name collection of all attributes specified by Name, the result is an instance of an enumeration getCookies (): Returns all cookie objects of the client, the result is a cookie array getCharacterencoding () : Returns the character encoding method in the request getContentLength (): Returns the length of the requested body (String Name): Get the file header information of the HTTP protocol definition GetHeaders (String Name): Returns all values ​​of the request header of the specified name, the result is An instance of an enumeration getHeadernames (): Returns the name of the Request Header, the result is an instance of an enumeration GetInputStream (): Returns the requested input stream for obtaining the data in the request (): obtain the client to the server Method for transmitting data getParameter (String Name): Getting a client to send to the server-side parameter value getParameterNames (): Get the name of all parameters to the server to the server, the result is an enumerated instance getParameterValues ​​(String Name : Get all values ​​with Name specified parameters getProtocol (): Get the client to transfer data to the server to get QueryString (): get the query string getRequesturi (): Get the client address of the request string GetRemoteaddr (): Get the client's IP address getRemotehost (): Get the client's name GetSession ([Boolean Create]): Return and Request related sessiongetServerName (): Get the server's name GetServletPath (): Get the path to the script file requested by the client GetServerPort (): Get the port number of the server Removeattribute (String Name): Delete a property 67, J2EE is a technology or a platform or a framework? J2EE itself is a standard, a standard platform provided for the development of a distributed application. J2EE is also a framework, including JDBC, JNDI, RMI, JMS, EJB, JTA and other technologies. 68. We often encounter some coded characters in the web application development process, such as ISO8859-1, how to output a certain coded string? Public string translate (string str) {string tempstr = ""; try {tempstr = new string (Str.GetBytes ("ISO-8859-1"), "GBK"); Tempstr = Tempstr.trim ();} catch Exception E) {System.err.Println (E.GetMessage ());} Return Tempstr;} 69, a brief description logic operation (&, ^) and conditional operation (&&&, ||) distinguish.

The difference between the two points: a. Conditional operation can only be operated by Boolean, but logic operations can not only manipulate Boolean, but also operate value B. Logic operations do not generate short circuit 70, how many forms of XML document definitions? What is the essence difference between them? What kind of way to parse XML documents? A: Two forms of DTD Schema, B: Nature difference: Schema itself is XML, can be parsed by XML parser (this is also the fundamental purpose of developing SCHEMA from DTD), C: There are DOMs, SAX, Stax, etc. DOM: processing It is very powerful in large files. This problem is caused by the tree structure of the DOM. This structure is more memory, and the DOM must load the entire document into memory before parsing the file, suitable for the random access of XML SAX: not now in Dom, SAX is Event drive type XML parsing method. It sequentially reads the XML file, and does not need to load all files all. When encountered at the beginning of the file, the end of the document, or the label is ended, it triggers an event, the user handles the XML file by writing processing code in its callback event, suitable for the order of XML, Streaming API For XML (Stax) 71, briefly describe Synchronized and java.util.concurrent.locks.lock? The main same point: Lock can complete all the features implemented by Synchronized, and there is more accurate thread semantics and better performance than synchronized. Synchronized will automatically release the lock, and LOCK must request the programmer manually to release and must be released in the finally clause. 72, EJB role and three objects A complete EJB-based distributed computing structure consists of six roles, which can be provided by different developers, and each role works must follow the EJB provided by SUN. Specification to ensure compatibility between each other. These six characters are EJB component developers, Application ASSEMBLERs, deployers, EJB server providers, EJB container providers (EJB container providers, System Administrator's three objects are Remote (local) interface, home (localhome) interface, Bean class 73, EJB container provides service providing declaration cycle management, code generation, continuous management, security, transaction management, Lock and and issue management and other services. 74. What are the prohibition of the prohibited operation in EJB? 1. Can't operate threads and threads API (thread API means NOTINE, WAIT, etc.) IO operation directly access file system, 6. You can't load local libraries. 75. The Remote Interface and Home Interface The main role REMOTE interface defines the business method for the EJB client calling business method.

The Home interface is an EJB factory for creating and removing the EJB instance 76. The lifecycle of the Bean instance is typically buffer management for the Stateless Session bean, Entity Bean, and for the Entity Bean and StateFull Session Bean. Usually include the creation instance, set the context, create an EJB Object (CREATE), the business method call, the REMOVE, etc. For the bean in which the buffer is managed, the instance is not removed from memory after Create, but the buffer pool scheduling mechanism is constantly reused. Examples, the beans that exist Cache managed by activation and deactivation mechanisms and limit the number of instances in memory. 77, the activation mechanism of EJB is in the STATEFUL SESSION bean as an example: its Cache size determines the number of bean instances that can exist in memory, according to the MRU or NRU algorithm, the instance is migrated between activation and deactivation state, the activation mechanism is when When the client calls an EJB instance business method, if the corresponding EJB Object is found that the corresponding bean instance does not bind the corresponding bean instance (activated) (activation) this instance from it to activate the bean storage (by serializing mechanism). The corresponding EJBACTIVE and EJBPASSIVATE methods are called before the state change. 78. Several type sessions of EJB (session) bean, entity (Entity) bean-based bean can be divided into stateful and stateless, both entity beans can be divided into BEAN management persistence (BMP) and contufficient persistence (CMP) of container management (CMP) 2 79, several basic steps of the customer service call Set the JNDI service factory and the JNDI service address system properties, find the Home interface, call from the Home Interface Create method Create a Remote interface and calls its business method through the Remote interface. 80, how to specify the size of the size to WebLogic? In the start of WebLogic script (bitservername in the Domian corresponding server directory), add SET MEM_ARGS = -XMS32M

-Xmx

200M

, Adjust the minimum memory

32M

,maximum

200M

81. How to set WebLogic hot start mode (development mode) and product release mode? You can modify the startup mode of the corresponding server in the management console as one of the development or product modes. Or modify the service startup file or Comufact of the Commenv file, add set production_mode = true. 82. Do not enter the username and password when starting? Modify the service startup file, increase the WLS_USER and WLS_PW items. You can also add an encrypted username and password in the boot.properties file. 83, after the WebLogic Management Table, a application domain (or a website, Domain) is configured after configuring information about JMS and EJB or connection pools. What file is actually saved? Save in this Domain's config.xml file, it is the core configuration file of the server. 84, talk about a Domain default directory structure in WebLogic? For example, put a simple helloworld.jsp into the point of the directory, but you can be http: // host on the browser: port number // HelloWord .jsp You can see the results of the run? Another example in which you write JavaBean how to do? Domain Directory / Server Directory / Applications, place the application directory in this directory will be used as an application access, if it is web Application, the application directory needs to meet the web application directory requirements, the JSP file can be placed directly in the application directory, JavaBean needs to be placed in the CLASSES directory of the application directory, setting the server's default application will be implemented on the browser No need to enter an app name. 85. Publishing EJB in WebLogic to involve which profiles are different types of EJBs, all involved in the configuration files involved include EJB-jar.xml, weblogic-ejb-jar.xmlcmp entity beans generally need WebLogic- CMP-RDBMS-JAR.XML 86, how to make SSL configurations in WebLogic Configuration or J2EE (Standard) for the J2EE (Standard) to implement SSL in the default installation of demoidentity.jks and demotrust.jks KeyStore, need to configure The server uses Enable SSL, configures its port, and you need to get private key and digital certificate from CA in product mode, create IDentity and Trust KeyStore, load acquired key and digital certificate. You can configure this SSL connection to one-way or two-way. 87, how to view EJBs already released in WebLogic? You can use the management console, you can view all published EJB88, what is the use of the use? CORBA standard is a public object request agency structure (Common object Request Broker Architecture, standardized by the object management organization (Object Management Group, abbreviated as OMG). Its composition is the interface definition language (IDL), language binding (binding: also translated into a cable) and an agreement to interoperate interoperability. Its purpose is to use different programming languages ​​to run in different processes, develop in different operating systems.

89. Talk about several common modes in J2EE you are familiar with or have heard of J2EE? Some views of design patterns session facade pattern: Use sessionBean access EntityBeanMessage Facade Pattern: Implement asynchronous call EJB Command Pattern: Use Command JavaBeans to replace SessionBean To achieve a lightweight access Data Transfer Object Factory: Simplified EntityBean data by DTO Factory: Generic Attribute Access: Simplifying the EntityBean Data Provision for EntityBean Data Features Business Interface: The same interface specification business logic is implemented by remote (local) interface and Bean class. The design of sex EJB architecture will directly affect the performance, scalability, maintenanceability, component reuse and development efficiency. The more complex the project, the more important the project team, the more important it can reflect the importance of good design. 90. Talking about the MDB of the Persistent and Non-Persisten's Differential Persistent mode when developing message beans in WebLogic can guarantee the reliability of messaging, that is, if the EJB container has problems, the JMS server will still use the message in this MDB. When it is sent, the Non-Persistent method will be discarded. 91. What kind of method is generally implemented when the servlet is executed? public void init (ServletConfig config) public ServletConfig getServletConfig () public String getServletInfo () public void service (ServletRequest request, ServletResponse response) public void destroy () 92, j2ee common design patterns? Description plant mode.

23 design patterns in Java: Factory, Builder, FactoryMethod, Prototype, Singleton, Facade, Adapter ( Adapter mode), Bridge (Bridge mode), Composite, Decorator, Flyweight, Proxy, Command, Interpreter, Visitor (Interpreter Mode), Visitor Visitor Mode CHAIN ​​OF RESPONSIBLEITY Factory mode: Factory mode is a model that is often used, and the class implemented according to the factory mode can generate an instance of a class in a set of classes according to the provided data, usually this The group has a common abstract parent class and implements the same method, but these methods have different operations for different data. First, you need to define a base class that the subclass of the class implements the method in the base class through a different method. Then need to define a factory class, and the factory class can generate different subclass examples depending on the conditions. When an example of a subclass is obtained, the developer can call the method in the base class without having to consider the instance of which a subclass is returned. 93, EJB needs to implement its business interface or home interface, please briefly describe the reasons. The remote interface and home interface do not need to be directly implemented, and their implementation code is generated by the server, and the implementation class in the program run is used as an instance of the corresponding interface type. 94. What kinds of methods are there? Please list it. Implement a rapid sort with Java. Sort by: Insert Sort (Direct Insert, Hill Sort), Switching Sort (Bubble Sort, Rapid Sort), Select Sort (Direct Selection Sort, Stack Sort), Multiple Sort, Distribution Sort (Sort, Base Sort ) Quickly sorted pseudo code.

/ / Use the quick sort method to sort the A [0: N- 1] from A [0: N- 1] as M i D D L e, the element is divided into two segments of elements into two segments And R i g h t, so that the elements in L E f T are less than equal to the fulcrum, and the elements in the RIGHT are greater than the rapid sorting method to use the fast sorting method to use the fast sorting method to use the fast sorting method to use the fast sorting method to use the fast sorting method to use the fast sort method. The result is LEF T M i D l E R I g H T95, please interpret the following noun commonly used in J2EE (simple description) Web container: Application components that are in it (JSP, servlet ) Provide an environment that interacts the JSP, Servlet to interact with environment variable interfaces in the container, and do not have to pay attention to other system issues. There is mainly a web server to achieve. For example: Tomcat, WebLogic, WebSphere, etc. The interface provided by the container strictly abides by the Web Application standard in the J2EE specification. We call the Web Server of the above standards called the web container in J2EE. EJB container: Enterprise Java Bean container. More industry segments. He provides various management functions that run the component EJB. As long as the EJB that satisfies the J2EE specification is placed in this container, it will be managed by the container. And you can obtain system level services through ready-made interfaces. For example, email services, transaction management. JNDI: (Java Naming & Directory Interface) Java Name Directory Service. The main functionality is: Provide a directory system that allows applications from all over its own index to meet the functionality of fast finding and positioning distributed applications. JMS: (Java Message Service) Java Message Service. It mainly implements communication between the various applications. Includes point-to-point and broadcast. JTA: (Java Transaction API) Java Transaction Services. Provide a variety of distributed transaction services. The application only needs to call the interface provided. JAF: (Java Action Framework) Java Security Authentication Framework. Provide some security control frames. Let developers implement their own personal safety control strategies through a variety of deployment and customization. RMI / IIOP: (Remote Method Invocation / Internet Object Request a Intermediary Protocol) They are primarily used to serve through remote calls. For example, remotely running a program, which provides stock analysis services, we can implement them directly on your local computer. Of course, this is to communicate between heterogeneous systems through a certain specification. RMI is unique to Java. 96. How does Java language processes an exception handle, keywords: throws, throw, try, catch, finally represents what significance? Can I throw an exception in the TRY block? Java processes abnormally by object-oriented methods, and classifies a variety of different exceptions and provides a good interface. In Java, each exception is an object, which is an instance of the throwable class or other subclass. When an abnormality occurs, an exception object is thrown, and the object contains abnormal information, and the method of calling this object can be captured and processed. Java's exception handling is achieved by 5 keywords: try, catch, throw, throws and finally.

Under normal circumstances, use TRY to perform a program, if an exception occurs, the system will throw an exception, then you can capture (catch) it through its type, or finally by default processor Treatment. Use TRY to specify a program that prevents all "exceptions". Keeping followed by the Try program, a Catch clause should be included to specify the type of "exception" you want to capture. The throw statement is used to clearly throw an "exception". Throws is used to indicate a variety of "exceptions" that may be thrown by a member function. Finally is executed to ensure that "exception" occurs regardless of the code. You can write a TRY statement outside in a member function call, write another TRY statement to protect other code inside this member function. Whenever you encounter a try statement, the "exception" frame is placed on the stack until all TRY sentences are completed. If the TRY statement at the next level does not process some "exception", the stack will be expanded until the TRY sentence with this "exception" is encountered. 97, can I include multiple classes (not internal classes) in a ".java" source file? What is the limit? can. There must be only one class name with the file name. 98. All parts of MVC have those technologies to implement? How to achieve? MVC is a short written by Model-View-Controller. "Model" is the application's business logic (implemented by javabean, ejb component), "view" is the application's representation surface (generated by JSP page), "Controller" is a process control (generally a servlet) The application logic, processing procedure, and display logic are achieved by this design model into different components. These components can interact and reuse. 99. How many ways to implement a thread in Java? What is the use of keyword modified synchronization methods? Stop () and SUSPEND () methods do not recommend it? There are two implementation methods, which are inheriting the Thread class and implementing the runnable interface with the synchronized keyword modification synchronization method against the use of STOP () because it is not safe. It will release all locks acquired by the thread, and if the object is in a non-connected state, then other threads can check and modify them in that state. It is difficult to check the real problem. The suspend () method is prone to dead locks. When you call suspend (), the target thread will stop, but still hold the lock before this. At this point, any other thread cannot access the locked resource unless the thread is restored to the thread. For any thread, if they want to resume the target thread, it will cause a deadlock to use any lock resources. So you should not use Suspend (), and you should place a sign in your own Thread class, pointing out that the thread should act or hang. If the flag indicates that the thread should hang, use Wait () to enter the waiting state. If the flag indicates that the thread should be restored, use a Notify () to restart the thread. 100. How many types of streams in Java? JDK provides some abstract classes for each type of stream for inheritance, please say which classes are they? Byte stream, character stream. Byte streams are inherited in InputStream / OutputStream, and the character stream is inherited in InputStreamWriter.

There are many other streams in Java.IO bag, mainly in improving performance and convenience. 101. Does memory leaks in Java? Please briefly describe it. meeting. Such as: INT I, I2; RETURN (I-I2); // when i is a positive number, i2 is a large negative number. The result will cause a seating, resulting in errors. 102. What is the mechanism for achieving polymorphism in Java? The method of rewriting Overriding and overloading overloading is a different manifestation of Java polymorphism. Overriding Overriding is a manifestation of polymorphism between parent class and subclasses, and overloading overloading is a manifestation in a class. 103. What is the basic principle of garbage collector? Can garbage collectors recycle memory immediately? Is there any way to actively notify the virtual machine for garbage collection? For GC, when the programmer creates an object, the GC starts to monitor the address, size, and usage of this object. Typically, the GC uses a map-like manner to record all objects in the heap (HEAP). In this way, it is determined which object is "can be reached", which object is "unreachable". When the GC determines that some objects are "unreachable", GC is responsible for reclaiming these memory spaces. can. The programmer can manually execute System.gc (), inform GC operation, but Java language specification does not guarantee that GC will be executed. 104, differences in static variables and instance variables? Static i = 10; // constant class a a a; A.i = 10; // variable 105, what is Java serialization, how to implement Java serialization? Serialization is a mechanism for processing the target stream, the so-called object stream is to fluidize the contents of the object. It is possible to read and write the fluidized object, and the flowable object can also be transmitted between the network. Serialization is to solve problems caused by read and write operations on object flows. Serialization Realization: The sequential class is required to implement the serializable interface. The interface does not need to be implemented. Implements Serializable is only serialized in order to mark the object, and then use an output stream (such as a fileoutputstream) to construct An ObjectOutputStream (Object Stream) Object, then use the ObjectOutputStream object's WriteObject (Object Obj) method to write the objects of the object (ie, save its status), if you want to recover, you can use the input stream. 106. Can I send a call to a non-Static method from one STITIC method? No, if included in the object's method (); does not guarantee the initialization of the object. 107, when writing the clone () method, what is the code? Clone has default behaviors, super.clone (); he is responsible for generating the right size space and copying in position. 108, in Java, how to jump out the current multi-nest loop? Use Break; Return method. 109, List, Map, SET three interfaces, how is it? List holds an element in a specific order, there can be repeated elements. SET cannot have a repeating element, internally sorted. Map saves the key-value value, Value can be more values. 110, what is J2EE? J2EE is a Multi-Diered, distributed, distributed, component-based, enterprise application model. In such an application system, it can be divided according to functionality. For different components, these components can be on different computers and are in the corresponding hierarchy (TIER).

The hierarchies are included in the ClientN Tier components, web layers, and components, Business layers, and components, and corporate information systems (EIS) layers. 111, UML standard modeling language UML. Modal example, static map (including class diagram, object map, and package), behavioral diagram, interaction map (sequential diagram, cooperation graph), implementation diagram. 112. Some commonly used classes, packages, interfaces, please raise 5 common classes: BufferedReader BufferedWriter FileReader Filewirter String Integer Common Package: Java.lang Java.awt java.io java.util java.sql common interface : Remote List Map Document NodeList 113, the development model uses those design mode? What are the occasion? Each mode describes a problem that has emerged in our environment and then describes the core of the solution. In this way, you can use the existing solutions countlessly without counting the same job. Mainly used in the design pattern of MVC. Used to develop JSP / Servlet or J2EE related applications. Simple factory model, etc. 114, what actions do you have? What is the role? JSP has the following six basic action JSP: include: Introduction: Introducing a file when the page is requested. JSP: Usebean: Find or instantiate a JavaBean. JSP: setProperty: Sets the properties of JavaBean. JSP: getProperty: Outputs the properties of a JavaBean. JSP: Forward: Turn the request to a new page. JSP: Plugin: Generate Object or Embed tags based on the browser type. 115, Anonymous Inner Class (anonymous internal class) Can be extends other classes, can IMPLEMENTS INTERFACE (interface) can inherit other classes or complete other interfaces, which are commonly used in Swing programming. 116. The difference between application servers and web Server? Application Server: WebLogic, Tomcat, JBossWeb Server: IIS, Apache117, Contacts and CS Differences between BS and CS. C / S is the abbreviation of Client / Server. Servers typically use high-performance PCs, workstations, or small machines, and use large database systems such as Oracle, Sybase, Informix, or SQL Server. The client needs to install a dedicated client software. B / S is an abbreviation of Brower / Server, just install a browser, such as Netscape Navigator or Internet Explorer, such as Netscape Navigator, or Internet Explorer, and a database such as Oracle, Sybase, Informix, or SQL Server. In this configuration, the user interface is implemented completely through the WWW browser, and the transaction logic is implemented at the front end, but the main transaction logic is implemented at the server. The browser interacts with the database with the database.

C / S and B / S distinguish: 1. Different hardware environments: C / S is typically established on a dedicated network, a small network environment, and the local area network will then provide connection and data exchange services through a dedicated server. B / S is built on the wide area network, does not have to be special Network hardware environment, examples of online Internet access, rent equipment. Information yourself. By more adaptable ranges than C / S, generally just operating systems and browsers 2. For security requirements, different C / S generally facing relatively fixed user groups, which is very controlled for information security. Generally high confidential information systems use C / S structures suitable. Open information can be publicly available via the B / S distribution section. B / S is built on the WAN, which is relatively weak for security control, and may facing unknown users. 3. Different C / S procedures for program architectures can be more payable, multi-level values ​​can be verified for permissions. The system runs can be less considered. B / S is a multi-consideration of security and access speed, based on the basis for more optimization Above it. The program architecture of the B / S structure than C / S is the development trend, from the MS .NET series BizTalk 2000 Exchange 2000, etc., the system fully supports the network components. Sun and IBM push JavaBean component technology, etc., make B / S mature. 4. Software reuses different C / S programs can inevitably considers, the reuse of components is not as low as reuse of components under B / S, and the multi-structure of B / S pairs, requires relatively independent functions of components. It is better to reuse. If you buy a table, you can use it, not the stone table 5 on the wall. System Maintenance Different C / S procedures Due to overall, the overall investigation, the problem and system upgrade. Upgrade is difficult. Maybe a new system B / S component composition, aspect component individual replacement, implementation system Sewing upgrade. System maintenance overhead is minimized. Users can upgrade from the online download and installation. 6. Different C / S procedures can handle user plane fixation, and high demand in the same area, security requirements, related to the operating system. It should be the same system B / S is built on wide-area network, facing different user groups, dispersing the region This is C / S unable to do. The relationship with the operating system platform is the smallest. 7. Different user interfaces are mostly established WINDOW platforms, the performance method is limited, and the programmer is universally required to establish a higher B / S on the browser, there is a richer and vivid manifestation and user communication. And most difficulty Reduce, reduce development costs. 8. Different information flows Different C / S procedures are generally a typical centralized mechanical treatment, and the relatively low interactive is relatively low. The flow direction of B-B B-C B-G, and the flow direction changes, more like the trading center. 118, Linux under the thread, the explanation of the GDI class. Linux implemented is based on the "one-to-one" thread model of the core lightweight process, and a thread entity corresponds to a core lightweight process, and the management between the thread is implemented in the nuclear external function library. The GDI class is an image device programming interface class library. 119, Struts Applications (such as Struts Architecture) Struts is a Framework for developing a web application to develop web applications. The Struts can develop an application architecture based on MODEL-View-Controller design mode. Struts has the following main functions: I contain a controller servlet to send the user's request to the corresponding Action object. II.Jsp Free Tag Library and provide association support in the Controller Servlet to help developers create interactive form applications. 3. Provide a series of practical objects: XML processing, automatically handle JavaBeans properties, international tips and messages through Java Reflection APIs.

120, JDO What is JDO is a new specification for the Java object persistence, which is a referred to as Java Data Object, and is also a standardized API for accessing objects in a certain data warehouse. JDO provides transparent object storage, so that the developer does not require additional code (such as the JDBC API). These cumbersome routines have been transferred to the JDO product provider, so that developers are freed out to concentrate on time and energy logically. In addition, JDO is flexible because it can run on any data underlayer. JDBC is just more common to relational database (RDBMS) JDO, providing storage capabilities of any data underlying, such as relational database, file, xml, and object database (ODBMS), etc., make it stronger to apply portability. 121, can the internal class can reference him members of the class? Is there any restriction? An internal class object can access the content 122 of the external class object that creates it, the web service noun explanates. JSWDL development package. JAXP, JAXM explanation. SOAP, UDDI, WSDL Explanation. Web ServiceWeb Service is a network-based, distributed modular component, which performs specific tasks, complies with specific technical specifications, which make Web Service interoperate with other compatible components. JAXP (Java API for XML PARSING) Defines the universal interface using DOM, SAX, XSLT in Java. This way in your program you only need to use these universal interfaces, and do not need to modify the code when you need to change the specific implementation. JAXM (Java API for XML Messaging is an API that provides access methods and transport mechanics for SOAP communication. WSDL is an XML format for describing network services as a set of endpoints that operate on messages that contain document information or process information. This format first abstracts the operation and message, then binds it to the specific network protocol and message format to define endpoints. The relevant specific endpoints are combined into an abstract endpoint (service). SOAP is a Simple Object Access Protocol, which is a lightweight protocol used to exchange XML encoded information. The purpose of UDDI is to establish standards for e-commerce; UDDI is a web-based, distributed, implementation standard specification provided by the information registry for Web Service, and also includes a group of web services that can provide themselves. Register to achieve the implementation of the access protocols that other companies can discover. Java code check error 1.Abstract class name {private string name; public abstract boolean isstupidName (String name) {}} heroes, what is wrong? Answer: wrong. Abstract Method must end with a semicolon and do not bring a curly bracket. 2.PUBLIC CLASS Something {Void Dosomething () {private string s = ""; int L = s.Length ();}} Is it wrong? Answer: wrong. Any access modifier (private, PUBLIC, and Protected) cannot be placed before the local variable. Final can be used to modify local variables (Final is like Abstract and Strictfp, all non-access modifiers, Strictfp can only modify Class and Method rather than variable). 3.Abstract Class Something {private abstract string dosomething ();} This seems to be nothing wrong? Answer: wrong.

Abstract Methods cannot be modified in private. Abstract Methods is the specific details of the subclass item, how can I use Private to block AbstractMethod? (Simply, you can't add Final before Abstract Method). 4.public class something {public int address (femal int x) {return x;}} This is more obvious. Answer: wrong. INT X is modified to Final, meaning X cannot be modified in Addone Method. 5.public class something {public static void main (String [] args) {other o = new other (); new thing (); public void addone (Final Other O) {O.}; } Class Other {public Int i;} is very similar to the above, is about Final's problem, is this wrong? answer: Correct. In Addone Method, the parameter O is modified into final. If we modified O's Reference in Addone Method (for example: o = new other ();), then this question is also wrong. But this is modified here that the MEMBER VAIRABLE (member variable) of O, while the REFERENCE does not change. 6.Class Something {Int i; public void dosomething () {system.out.println ("i =" i);}} Is there anything wrong? Can't see it. Answer: Correct. The output is "i = 0". INT i belongs to Instant Variable (instance variable, or a member variable). Instant variable has default value. INT's default value is 0.7.class something {final int i; public void dosomething () {system.out.println ("i =" i);}}} and topical only one place is different, that is, more A final. Is this wrong? Answer: wrong. Final INT i is a Final's Instant Variable (instance variable, or a member variable). Final Instant Variable No default value must be given a clear value before the constructor ends. Can be modified to "Final INT I = 0;". 8.public class something {public static void main (String [] args) {something s = new something (); system.out.println ("s.dosomething () returns" DOSMETHING ());} public string dosomething ) {Return "Do Something ...";}} It looks perfect. Answer: wrong. It seems that there is no problem in main dosomething in main, after all, two Methods are in the same class. But look carefully, main is static.

Static Method can't directly call Non-Static Methods. It can be changed to "S.DOSMETHING () Returns" S.DOSomething ()); ". Similarly, Static Method cannot access Non-Static Instant Variable. 9. Here, the file name of the Something class is Otherthing.javaclass Something {Private Static void Main (String [] Something_to_do) {system.out.println ("Do Something ...");}} This seems to be obvious. Answer: Correct. No one has said that the Java's Class name must be the same as its file name. But the name of the public class must be the same as the file name. 10. Interface A {int x = 0;} class b {int x = 1;} Class C Extends b IMPLEments A {public void px () {system.out.println (x);} public static void main (String [] args ) {New c (). Px ();}} answer: error. Errors occur when compiling (Error Description Different JVMs have different information, means that the unclear X call, two X matches (just like IMPORT JAVA.UTIL and Java.sql two packages Date Date) The same). For the variable of the parent class, you can use Super.x to explicit, and the attribute of the interface is implied as public static final. So you can clear .11.interface playable {void play (); interface bounceable { void play ();} interface Rollable extends Playable, Bounceable {Ball ball = new Ball ( "PingPang");} class Ball implements Rollable {private String name; public String getName () {return name;} public Ball (String name) {This.name = name;} public void play () {ball = new ball ("football"); system.out.println (ball.getname ());}} This error is not easy to discover. Answer: wrong. " Interface Rollable Extends Play, Bounceable "No problem. all can inherit multiple interfaces, so it is right. The problem is in the Interface Rollable" Ball Ball = New Ball ("pingpang"); "Any Interface declared in Interface Variable (interface variable, also known as a member variable), default is public static final.

That is, "Ball Ball = New Ball (" pingpang ");" actually "public static final ball ball = new ball (" pingpang ");". In the Play () method of the Ball class, "football"); "Change the Ball Reference, and the Ball from Rollable Interface, the ball in the Rollable Interface is public static final, Final Object It is not possible to change Reference. Therefore, the compiler will be "Ball = New Ball (" football ");" it is wrong here. Java program 1. Now enter N numbers, separately, separate; then select liter or descending order, press what order is displayed on another page, and the result is RESETIMPORT JAVA.UTIL. *; Public Class Bycomma {public static string [] SplitstringBYCOMMA (String Source) {if (source == null || source.trim (). Equals (")) Return Null; StringTokenizer Commatoker = New StringTokenizer (Source,", "); String [] Result = New String [commatoker.counttokens ()]; int i = 0; while (commatoker.hasmoretoKens ()) {result [i] = commatoker.nextToken (); i ;} return result;} public static void main (String args [] ) {String [] s = splitstringBYCOMMA ("5, 8, 7, 4, 3, 9, 1"); int [] ii = new int [S.LENGTH]; for (int i = 0; i = 0; i -) {system.out.println (II [i]);}} }2. The amount converted, the amount of the Arab figures converted into Chinese traditional forms such as (¥ 1011) -> (1 thousand and one yuan) output.

package test.format; import java.text.NumberFormat; import java.util.HashMap; public class SimpleMoneyFormat {public static final String EMPTY = ""; public static final String ZERO = "zero"; public static final String ONE = "One "; Public static final string tW =" "; public static final string three =" 叁 "; public static final string four =" "; public static final string file =" Wu "; public static final string Six =" land "; Public static final string seven =" 柒 "; public static final string eight =" 捌 "; public static final string nine =" 玖 "; public static final string ten =" Pick up "; public static final string hundred =" 佰"; public static final String tHOUSAND =" thousand "; public static final String TEN_THOUSAND =" Wan "; public static final String HUNDRED_MILLION =" one hundred million "; public static final String yUAN =" meta "; public static final String JIAO =" angle "; Public static final string fen =" points "; public static final string dot =". "; Private static simplemoneyformat formatter = null; private hashmap chineseNumberMap = new HashMap (); private HashMap chineseMoneyPattern = new HashMap (); private NumberFormat numberFormat = NumberFormat.getInstance (); private SimpleMoneyFormat () {numberFormat.setMaximumFractionDigits (4); numberFormat.setMinimumFractionDigits (2); numberFormat.setGroupingUsed (false CHINESENUMBERMAP.PUT ("0", ZERO); chinesenumbermap.put ("1", one); chinesenumbermap.put ("2", two); chinesenumbermap.put ("3", three);

ChineseNumbermap.Put ("4", FOUR); ChineseNumbermap.put ("5", FIVE); chinesenumbermap.put ("6", Six); chinesenumbermap.put ("7", seven); chinesenumbermap.put ("8 ", Elesenumbermap.put (" 9 ", nine); chineseumbermap.put (dot, dot); chinesemoneyPattern.put (" 1 ", ten); chinesemoneyPattern.put (" 2 ", hundred); chinesemoneyPattern.put; ChineseMoneyPattern.put ("3", THOUSAND); ChineseMoneyPattern.Put ("4", Ten_thousand); ChineseMoneyPattern.put ("5", TEN); chinesemoneyPattern.put ("6", hundred); chinesemoneyPattern.put ("7", THOUSAND ); chineseMoneyPattern.put ( "8", HUNDRED_MILLION);} public static SimpleMoneyFormat getInstance () {if (formatter == null) formatter = new SimpleMoneyFormat (); return formatter;} public String format (String moneyStr) {checkPrecision (moneyStr ); String result; result = convertTtochineseNumber (MoneyStr); Result = addunitstochineseMoneyString (Result); Return Result;} public string format;} {Return Forma {RETURN FORMA t (numberFormat.format (moneyDouble));} public String format (int moneyInt) {return format (numberFormat.format (moneyInt));} public String format (long moneyLong) {return format (numberFormat.format (moneyLong)); } public String format (Number moneyNum) {return format (numberFormat.format (moneyNum));} private String convertToChineseNumber (String moneyStr) {String result; StringBuffer cMoneyStringBuffer = new StringBuffer (); for (int i = 0; i

} // 拾 万 万 等 等 是 有 单 有 有;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -) {cMoneyStringBuffer.insert (i, chineseMoneyPattern.get (EMPTY moneyPatternCursor)); moneyPatternCursor = moneyPatternCursor == 8 1: moneyPatternCursor 1;?} String fractionPart = cMoneyStringBuffer.substring (cMoneyStringBuffer.indexOf ( ".")) ; cMoneyStringBuffer.delete (cMoneyStringBuffer.indexOf (), cMoneyStringBuffer.length () "."); while (! cMoneyStringBuffer.indexOf ( "zero pick") = -1) {cMoneyStringBuffer.replace (cMoneyStringBuffer.indexOf ( "zero pick" ), cMoneyStringBuffer.indexOf ( "zero pick") 2, zERO);} while (cMoneyStringBuffer.indexOf ( "zero Bai") = -1) {cMoneyStringBuffer.replace (cMoneyStringBuffer.indexOf ( "zero Bai"), cMoneyStringBuffer! .indexof ("Zero") 2, ZERO);} while (cmoney ")! = -1) {cmoneyStringBuffer.Replace (CmoneyStringBuffer.indexof (" zero "), cmoneyStringBuffer.indexof "Zero") 2, ZERO);} while (cmoney ")! = -1) {cmoneyStringBuffer.Replace (cmoneyStringBuffer.indexof (" 万 万), cmoneyStringBuffer.indexof ("零 万) 2, TEN_THOUSAND);} while (cMoneyStringBuffer.indexOf ( "zero one hundred million") = -1) {cMoneyStringBuffer.replace (cMoneyStringBuffer.indexOf ( "zero one hundred million"), cMoneyStringBuffer.indexOf ( "zero one hundred million") 2, HUNDRED_MILLION)!; WHILE (CmoneyStringBuffer.indexof ("zero zero")! = -1) {cmoneyStringBuffer.replace (cmoneyStringBuffer.indexof ("zero zero"

转载请注明原文地址:https://www.9cbs.com/read-33398.html

New Post(0)