Java interview sunflower collection 58. Different information flows
C/S programs are generally typical centralized mechanical processing, with relatively low interaction.
B/S information flow to changeable, B-B B-C B-G and other information, flow changes, more like the transaction center.
118. Linux thread and GDI class explanation.
Linux implements the "one-to-one" thread model based on the core lightweight process. A thread entity corresponds to a core Lightweight Process, and management between threads is implemented in the off-core function library.
The GDI class is the image device programming interface class library.
119 struts applications (such as Struts Architecture)
Struts is an open source framework for developing Web applications using Java Servlet/JavaServer Pages technology. Struts can be used to develop an application architecture based on the Model-View-controller design pattern. Struts has the following main functions: 1. It includes a controller servlet that can send user requests to corresponding action objects. II. the JSP free tag Library provides Association support in the Controller servlet to help developers create interactive form applications. 3. provides a series of practical objects: XML processing, automatic processing of JavaBeans attributes through Java reflection APIs, and International prompts and messages.
120. What is JDO?
JDO is a new specification for Java object persistence. It is short for Java data object and is also a standardized API for accessing objects in a data warehouse. JDO provides transparent object storage. Therefore, for developers, no additional code (such as the use of JDBC APIs) is required to store data objects ). These tedious routine work has been transferred to the JDO product provider, freeing developers to concentrate their time and effort on business logic. In addition, JDO is flexible because it can run on any data underlying layer. JDBC is more common for Relational Database Service (RDBMS) JDO and provides underlying storage functions for any data, such as relational databases, files, XML, and object databases (odbms, makes applications more portable.
121 can an internal class reference its members in the class? Are there any restrictions?
An internal class object can access the content of its external Class Object
122. Web Service terminology. Jswdl Development Kit introduction. JAXP and jaxm. Soap, UDDI, and WSDL.
Web serviceweb service is a network-based, distributed modular component that executes specific tasks and complies with specific technical specifications. These specifications Enable Web service to interoperate with other compatible components.
JAXP (Java API for XML parsing) defines a common interface for using Dom, sax, and XSLT in Java. In this way, you only need to use these universal interfaces in your program, and you 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 transmission mechanisms for soap communication.
WSDL is an XML format used to describe network services as a group of endpoints that operate on messages that contain document-oriented or process-oriented information. This format first abstracts the operation and message, and then binds it to a specific network protocol and Message format to define the endpoint. The specific endpoints are combined into abstract endpoints (services ).
Soap is the Simple Object Access Protocol. It is a lightweight protocol used to exchange XML encoding information.
The purpose of UDDI is to establish standards for e-commerce. UDDI is a set of web-based, distributed, and standard standards for implementing information registration centers for Web Services, it also contains a set of access protocols that enable enterprises to register their own web services so that other enterprises can discover.
Java code error
1.
Abstract class name {
Private string name;
Public Abstract Boolean isstupidname (string name ){}
}
What's wrong with this?
Answer: Yes. Abstract method must end with a semicolon without curly braces.
2.
Public class something {
Void dosomething (){
Private string S = "";
Int L = S. Length ();
}
}
Is it wrong?
Answer: Yes. You cannot place any access modifiers (private, public, and protected) before local variables ). Final can be used to modify local variables.
(Like abstract and strictfp, final is not an access modifier. strictfp can only modify class and method rather than variable ).
3.
Abstract class something {
Private abstract string dosomething ();
}
Is there nothing wrong with this?
Answer: Yes. Abstract methods cannot be modified in private mode. Abstract METHODS is to make the sub-class implement (Implementation) specific details, how can I use private to abstract
What about method blocking? (Likewise, final cannot be added before abstract method ).
4.
Public class something {
Public int addone (final int X ){
Return ++ X;
}
}
This is obvious.
Answer: Yes. 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 something (). addone (O );
}
Public void addone (final other O ){
O. I ++;
}
}
Class other {
Public int I;
}
Similar to the above, they are all about final. Is this wrong?
Answer: Correct. In addone method, the parameter o is modified to final. If we modify the reference of o in addone method
(For example, O = new other. But here we modify the member vairable of O.
(Member variable), and O's reference has not changed.
6.
Class something {
Int I;
Public void dosomething (){
System. Out. println ("I =" + I );
}
}
What's wrong? It cannot be seen.
Answer: Correct. The output is "I = 0 ". Int I belongs to instant variable (instance variable, or member variable ). Instant variable has default value. The default value of int is 0.
7.
Class something {
Final int I;
Public void dosomething (){
System. Out. println ("I =" + I );
}
}
Unlike the above question, there is only one more final. Is that true?
Answer: Yes. Final int I is a final instant variable (instance variable, or member variable ). The instant variable of final has no default value and must be assigned a clear value before the constructor ends. It can be changed 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" + dosomething ());
}
Public String dosomething (){
Return "do something ...";
}
}
Looks perfect.
Answer: Yes. It seems that there is no problem with calling dosomething in Main. After all, both methods are in the same class. But take a closer look, main is static. Static method cannot call non-static methods directly. You can change it to "system. Out. println (" S. dosomething () returns "+ S. dosomething ());". Similarly, static method cannot access non-static instant variable.
9.
Here, the name of the something class is otherthing. java.
Class something {
Private Static void main (string [] something_to_do ){
System. Out. println ("do something ...");
}
}
This seems obvious.
Answer: Correct. No one has ever said that the Java class name must be the same as its file name. However, the public class name must be the same as the file name.
10.
Interface {
Int x = 0;
}
Class B {
Int x = 1;
}
Class C extends B implements {
Public void PX (){
System. Out. println (X );
}
Public static void main (string [] ARGs ){
New C (). PX ();
}
}
Answer: incorrect. An error occurs during compilation (the error description varies with the JVM, which means that the unspecified x call matches both of them (just like importing Java at the same time. util and Java. when two SQL packages are declared, the date is the same ). The variables of the parent class can be identified using super. X, and the interface property is implicitly public static final by default. Therefore, A. X can be used to specify the variables.
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: Yes. "Interface rollable extends playable, bounceable" is correct. The interface can inherit multiple interfaces, so this is correct. The problem lies in "ball = new ball (" pingpang ");" in interface rollable ");". The default value of interface variable declared in the interface is public static final. That is to say, "ball = new ball (" pingpang ");" is actually "public static final ball = new ball (" pingpang ");". In the play () method of the ball class, "ball = new ball (" football ");" changes the reference of the ball, and the ball here comes from the rollable interface, the ball in rollable interface is public static final, and the final object cannot be changed by reference. Therefore, the compiler will display errors in "ball = new ball (" football.
Java programming
1. Now enter n numbers separated by commas (,). Then you can select ascending or descending order. Press the submit key to display the sort order on the other page. The result is a reset.
Import 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= 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 <S. length; I ++ ){
II= Integer. parseint (S);
}
Arrays. Sort (II );
// ASC
For (INT I = 0; I <S. length; I ++ ){
System. Out. println (II);
}
// DESC
For (INT I = (S. Length-1); I> = 0; I --){
System. Out. println (II);
}
}
}
2. amount conversion: The amount of Arabic numerals is converted to the traditional Chinese format, for example: (¥1011)-> (one 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 two = "";
Public static final string three = "";
Public static final string four = "Si ";
Public static final string five = "Wu ";
Public static final string six = "";
Public static final string seven = "success ";
Public static final string eight = "success ";
Public static final string nine = "Hangzhou ";
Public static final string ten = "pick up ";
Public static final string hundred = "success ";
Public static final string thousand = "Hangzhou ";
Public static final string ten_thousand = "Ten Thousand ";
Public static final string hundred_million = "";
Public static final string yuan = "Yuan ";
Public static final string Jiao = "";
Public static final string Fen = "min ";
Public static final string dot = ".";
Private Static simplemoneyformat formatter = NULL;
Private hashmap chinesenumbermap = new hashmap ();
Private hashmap chinesemoneypattern = new hashmap ();
Private 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", 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 ){
Checkprecision (moneystr );
String result;
Result = converttochinesenumber (moneystr );
Result = addunitstochinesemoneystring (result );
Return result;
}
Public string format (double moneydouble ){
Return format (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 <moneystr. Length (); I ++ ){
Cmoneystringbuffer. append (chinesenumbermap. Get (moneystr. substring (I, I + 1 )));
}
// Hundreds of millions of characters are all units in Chinese characters.
Int indexofdot = cmoneystringbuffer. indexof (DOT );
Int moneypatterncursor = 1;
For (INT I = indexofdot-1; I> 0; I --){
Cmoneystringbuffer. insert (I, chinesemoneypattern. Get (empty + moneypatterncursor ));
Moneypatterncursor = 8? 1: moneypatterncursor + 1;
}
String fractionpart = cmoneystringbuffer. substring (cmoneystringbuffer. indexof ("."));
Cmoneystringbuffer. Delete (cmoneystringbuffer. indexof ("."), cmoneystringbuffer. Length ());
While (cmoneystringbuffer. indexof ("0 ")! =-1 ){
Cmoneystringbuffer. Replace (cmoneystringbuffer. indexof ("Zero pick"), cmoneystringbuffer. indexof ("Zero pick") + 2, zero );
}
While (cmoneystringbuffer. indexof ("0 bytes ")! =-1 ){
Cmoneystringbuffer. Replace (cmoneystringbuffer. indexof ("zero latency"), cmoneystringbuffer. indexof ("zero latency") + 2, zero );
}
While (cmoneystringbuffer. indexof ("0 bytes ")! =-1 ){
Cmoneystringbuffer. Replace (cmoneystringbuffer. indexof ("zero latency"), cmoneystringbuffer. indexof ("zero latency") + 2, zero );
}
While (cmoneystringbuffer. indexof ("0 thousand ")! =-1 ){
Cmoneystringbuffer. Replace (cmoneystringbuffer. indexof ("0 thousand"), cmoneystringbuffer. indexof ("0 thousand") + 2, ten_thousand );
}
While (cmoneystringbuffer. indexof ("0 billion ")! =-1 ){
Cmoneystringbuffer. Replace (cmoneystringbuffer. indexof ("0 billion"), cmoneystringbuffer. indexof ("0 billion") + 2, hundred_million );
}
While (cmoneystringbuffer. indexof ("0 ")! =-1 ){
Cmoneystringbuffer. Replace (cmoneystringbuffer. indexof ("zero"), cmoneystringbuffer. indexof ("zero") + 2, zero );
}
If (cmoneystringbuffer. lastindexof (zero) = cmoneystringbuffer. Length ()-1)
Cmoneystringbuffer. Delete (cmoneystringbuffer. Length ()-1, cmoneystringbuffer. Length ());
Cmoneystringbuffer. append (fractionpart );
Result = cmoneystringbuffer. tostring ();
Return result;
}
Private string addunitstochinesemoneystring (string moneystr ){
String result;
Stringbuffer cmoneystringbuffer = new stringbuffer (moneystr );
Int indexofdot = cmoneystringbuffer. indexof (DOT );
Cmoneystringbuffer. Replace (indexofdot, indexofdot + 1, Yuan );