Java interview set (4)

xiaoxiao2021-03-06  22

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 find. Answer: wrong.

"Interface Rollable Extends Play, Bounceable" is no problem. Interface can inherit multiple Interfaces, so it is right. The problem is in the Interface Rollable "Ball Ball = New Ball (" pingpang ");". Any Interface Variable (interface variable, or member variable) declared in Interface, the 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 =" division "; public static final string dot =". "; Private static simplemoneyformat formatter = null; private hashmap ch INESENUMBERMAP = New hashmap (); private hashmap chinesemoneyPattern = new hashmap (); private numberformat Numberformat = Numberformat.getInstance ();

Private SimpleMoneyformat () {Numberformat.SetMaximumFracthenDigits (4); Numberformat.SetMinimumfractionDigits (2); NumberFormat.SetGroupingUsesed (false);

ChineseUmbermap.put ("0", zero); chinesenumbermap.put ("1", one); chinesenumbermap.put ("2", two); chinesenumbermap.put ("3", three); chinesenumbermap.put ("4 ", Four); chinesenumbermap.put (" 5 ", FIVE); chineseumbermap.put (" 6 ", six); chinesenumbermap.put (" 7 ", seven); chinesenumbermap.put (" 8 ", eight); chinesenumbermap .put ("9", nine); chinesenumbermap.put (dot, dot); ChineseMoneyPattern.put ("1", ten); chinesemoneyPattern.put ("2", hundred); 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); string result; result = convertTochineseNumber (MoneyStr); result = addunitstochineseMoneyString (result); Return Result;}

Public String Format (Double Moneydouble) {Return Format (NumberFormat (Moneydouble));

Public String Format (INT Moneyint) {Return Format (NumberFormat (Moneyint));

Public String Format (Long Money) {Return Format (Numberformat.Format (Money));

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 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")! = -1) {cMoneyStringBuffer.replace (cMoneyStringBuffer.indexOf ( "zero Bai"), cMoneyStringBuffer.indexOf ( "zero Bai") 2, zERO);} (! cMoneyStringBuffer.indexOf ( "zero thousand") = -1) while {cMoneyStringBuffer. replace (cMoneyStringBuffer.indexOf ( "zero thousand"), cMoneyStringBuffer.indexOf ( "zero thousand") 2, zERO);} while (! cMoneyStringBuffer.indexOf ( "zero Wan") = -1) {cMoneyStringBuffer.replace (cMoneyStringBuffer .indexof ("万"), cmoneyStringBuffer.indexof ("万") 2, Ten_thousand);} while (cmoney ")! = -1) {cmoneyStringBuffer.Replace (cmoneyStringBuffer.indexof "亿"), cmoneyStringBuffer.indexo f ("零") 2, hundred_million;} while (cmoney "! = -1) {cmoneyStringBuffer.Replace (CmoneyStringBuffer.indexof (" zero zero), cmoneyStringBuffer.indexof (" dated ") 2, ZERO);} if (cMoneyStringBuffer.lastIndexOf (ZERO) == cMoneyStringBuffer.length () - 1) cMoneyStringBuffer.delete (cMoneyStringBuffer.length () - 1, cMoneyStringBuffer.length ()); cMoneyStringBuffer. Append (FRActionPART); Result = cmoneyStringBuffer.tostring (); returnrate;}

private String addUnitsToChineseMoneyString (String moneyStr) {String result; StringBuffer cMoneyStringBuffer = new StringBuffer (moneyStr); int indexOfDot = cMoneyStringBuffer.indexOf (DOT); cMoneyStringBuffer.replace (indexOfDot, indexOfDot 1, YUAN); cMoneyStringBuffer.insert (cMoneyStringBuffer.length () - 1, jiao); cmoneyStringBuffer.Insert (cmoneyStringBuffer.Length (), fen); if (cmoneyStringBuffer.indexof ("zero zero points")! = -1) // No zero head, add cmoneyStringBuffer.Replace CmoneyStringBuffer.indexOf ("zero zero points"), cmoneyStringBuffer.Length (), "whole"); Else IF (cmoneyStringBuffer.indexof ("zero")! = -1) // No zero, add CmoneyStringBuffer. replace (cMoneyStringBuffer.indexOf ( "zero"), cMoneyStringBuffer.length (), "whole"); else {if (! cMoneyStringBuffer.indexOf ( "zero angle") = - 1) cMoneyStringBuffer.delete (cMoneyStringBuffer.indexOf ( " Zero angle "), cmoneyStringBuffer.indexof (" zero angle ") 2); // TmpBuffer.Append (" whole ");} result = cmoneyStringBuffer.tostring (); return result;} private void Checkpr Ecision (String Moneystr) {Int FractionDigits = MoneyStr.Length () - MoneyStr.indexof (Dot) - 1; if (Fractigits> 2) Throw new runtimeException ("The amount" MoneyStr "is more than two digits. "); // Accuracy cannot be score low}

Public static void main (string args []) {system.out.println (getInstance (). Format (New Double (10010001.01)));}}

3, the execution order of the class is generally a choice question, ask you how to print it? A: Parent class: package test; public class fatherclass {public fatherclass () {system.out.println ("FatherClass Create ");}} subclasses: package test; import test.FatherClass; public class ChildClass extends FatherClass {public ChildClass () {System.out.println (" ChildClass Create ");} public static void main (String [] args) {FatherClass fc = new FatherClass (); ChildClass cc = new ChildClass ();}} the output:? C:> java test.ChildClass FatherClass Create FatherClass Create ChildClass Create 4, the internal implementation class a: the following sample code: package test; public class OuterClass {private class InterClass {public InterClass () {System.out.println ( "InterClass Create");}} public OuterClass () {InterClass ic = new InterClass (); System.out.println ( "OuterClass Create ");} public static void main (String [] args) {OuterClass oc = new OuterClass ();}} The output: C:> java test / OuterClass InterClass Create OuterClass Create a further example: public class OuterClass {private double D1 = 1.0; // INSERT CODE Here} You NEED TO INSE rt an inner class declaration at line 3. Which two inner class declarations are valid (Choose two.) A. class InnerOne {public static double methoda () {return d1;}}? B. public class InnerOne {static double methoda () {return d1;}} C. private class InnerOne {double methoda () {return d1;}} D. static class InnerOne {protected double methoda () {return d1;}} E. abstract class InnerOne {public abstract double methoda ( );} The description is as follows: 1. The static internal class can have a static member, not a static member. Therefore, A, B is wrong. The non-static member of the static internal class can access the external class static variables, and the non-static variables of the external class are not accessible; RETURN D1 error. Therefore, D is not three. Non-static members of non-static internal classes can access unstatic variables of external classes.

Therefore, C, E 5, Java communication programming, programming questions (or question and answer), programming, read servers, and write to local display with Java Socket A: Server side program: package test; import java.net *; import java.io. *; public class Server {private ServerSocket ss; private Socket socket; private BufferedReader in; private PrintWriter out; public Server () {try {. SS = New ServerSocket (1000); while (True) {socket = ss.accept (); string remoteip = socket.getinetaddress (). gethostaddress (); string remoteport = ":" socket.getlocalport (); system.out .println ( "A client come in IP:!" RemoteIP RemotePort); in = new BufferedReader (new InputStreamReader (socket.getInputStream ())); String line = in.readLine (); System.out.println ( " Cleint Send IS: " Line); OUT = New PrintWriter (Socket.getOutputStream (); out.println (" Your Message Received! "); Out.close (); in.close (); socket.close ()}}} Catch (IException E) {OUT.Println ("Wrong");}} public static void main (String [] args) {new server ();}} Client Director: Package Test; Import Java. IO. *; import java.net. *; public class client {socket socket; buffredreader in; printwriter out; public client () {try {s YSTEM.OUT.PRINTLN ("Try to Connect To 127.0.0.1:10000"); socket = new socket ("127.0.0.1", 10000); System.out.Println ("The Server Connected!"); System.out .println ( "Please enter some Character:"); BufferedReader line = new BufferedReader (new InputStreamReader (System.in)); out = new PrintWriter (socket.getOutputStream (), true); out.println (line.readLine () ); in = new buffreader (new input.getinputstream ())); system.out.println (in.readline ()); out.close (); in.close (); socket.close ();

} catch (ioException e) {outputln ("wrong");}} public static void main (String [] args) {new client ();}} 6, using Java implement a sort, Java class implements serialization Method (two)? As in the Collection framework, what kind of interface must be achieved? A: Sort by the insertion method is as follows Package Test; import java.util. *; Class insertsort {arraylist al; public insertsort (int Num, int mod) {al = new arraylist (num); random rand = new random () System.out.println ("The ArrayList Sort Before:"); for (int i = 0; i

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

New Post(0)