Java job interview questions

Source: Internet
Author: User
Tags bitwise operators try catch

Java job interview questions

Some questions are collected and sorted on the Internet. Some questions come from the ones I often encounter during interviews. I want to help and answer all questions. To be honest, there are many so-called interview questions, I doubt whether there is any value!

1. Can a ". java" source file contain multiple classes (not internal classes )? What are the restrictions?

There can be multiple classes, but only one public class is allowed, and the public class name must be consistent with the file name.

2. Does Java have a goto?

Reserved Words in java, which are not currently used in java.

3. What is the difference between "&" and?

& And & can both be used as operators of logic and, indicating logic and (and). When both expressions return true, the entire operation result is true. Otherwise, if either of them is false, the result is false.

& It also has the short circuit function, that is, if the first expression is false, the second expression is no longer calculated. For example, if (str! = Null &&! Str. equals ("") expression. When str is null, the following expression will not be executed,

Therefore, NullPointerException will not occur. If & is changed to &, an NullPointerException exception will be thrown. If (x = 33 & ++ y> 0) y will increase, If (x = 33 & ++ y> 0) will not increase

& Can also be used as bitwise operators. When the expressions on both sides of the & operator are not of the boolean type, & indicates bitwise AND operation. We usually use 0x0f to perform & operation with an integer, to obtain the minimum four bits of the integer,

For example, the result of 0x31 & 0x0f is 0x01. Note: This question first describes what they have in common, then describes what is special about & and, and lists some classic examples to show that you have a thorough understanding and rich practical experience.

4. How can I jump out of the current multi-nested loop in JAVA?

In Java, to jump out of multiple loops, you can define a label in front of an External Loop statement, and then use a break statement with a label in the code of the in-layer loop body to jump out of the outer loop.

5. Can the switch statement be applied to byte, long, or String?

In switch (expr1), expr1 can only be an Integer expression or enumeration constant (larger font). The Integer expression can be an int basic type or an Integer packaging type.

Byte, short, and char can be implicitly converted to int. Therefore, these types and their packaging types are also acceptable. Obviously, the long and String types do not comply with the switch syntax,

And cannot be implicitly converted to int type. Therefore, they cannot be applied to swtich statements.

6. short s1 = 1; s1 = s1 + 1; what is the error? Short s1 = 1; s1 + = 1; what is the error?

For short s1 = 1; s1 = s1 + 1; because the s1 + 1 operation will automatically increase the expression type, the result is int type, and then assigned to short type s1, the compiler will report errors that require forced conversion.

For short s1 = 1; s1 + = 1; Because ++ = is an operator specified by the java language, the java compiler will perform special processing on it, so it can be compiled correctly.

7. Can a Chinese character be stored in a char variable? Why?

The char variable is used to store Unicode characters. The unicode Character Set contains Chinese characters. Therefore, the char variable can certainly store Chinese characters.

However, if a special Chinese character is not included in the unicode Character Set, the special Chinese character cannot be stored in this char variable.

Note: unicode encoding occupies two bytes. Therefore, char variables also occupy two bytes.

Note, the words are endless.

8. How many equals 2x8 in the most efficient way?

2 <3,

Because shifting a number to the left is equivalent to multiplying it by the Npower of 2. Therefore, if a number is multiplied by 8, it only needs to be shifted to three places, while bit computing CPUs directly support this, the most efficient,

Therefore, the most efficient way to multiply 2 by 8 and so on is 2 <3.

9. Design a 10 billion Calculator

First, the computer uses a fixed number of several bytes to store the value, so the value that can be expressed in the computer has a certain range, in order to facilitate the explanation and understanding, take an integer of the byte type as an example,

It is stored in 1 byte, indicating the maximum value range is-128 to + 127. -1 indicates that the binary data corresponding to the memory is 11111111. If two-1 values are added, the type upgrade during Java operations is not considered,

After the operation, carry is generated, and the binary result is 11111110. Because the carry is beyond the byte storage space, the carry part is discarded, that is, the final result is, that is,-2,

This uses the overflow method to calculate the negative number. -128 the binary data corresponding to the memory is 10000000. If two-128 values are added together, the type upgrade during the Java operation is not considered. After the operation, carry is generated,

The binary result is 00000000 bytes 0000. Because the carry size exceeds the byte storage space, the carry size is discarded. That is, the final result is, that is, 0, this result is obviously not what we expect,

This indicates that arithmetic operations in the computer may cross the border. The calculation results of two values cannot exceed the value range of this type in the computer. Because the types involved in expression operations in Java are automatically upgraded,

We cannot use the byte type to demonstrate this problem and phenomenon. You can use the following example program to experiment with integers:

Inta = Integer. MAX_VALUE;

Intb = Integer. MAX_VALUE;

Intsum = a + B;

System. out. println ("a =" + a + ", B =" + B + ", sum =" + sum );

10. When a variable is modified using the final keyword, can the reference not be changed, or can the referenced object not be changed?

When you use the final keyword to modify a variable, it is suggested that the variable cannot be changed, and the content in the object to which the referenced variable points can still be changed. For example, for the following statement:

FinalStringBuffera = newStringBuffer ("immutable ");

Run the following statement to report compilation errors: a = newStringBuffer ("");

However, you can compile a. append ("broken! ");

When defining the parameters of a method, someone may want to use the following form to prevent the method from modifying the passed parameter object:

Publicvoid method (final StringBuffer param)

{

}

In fact, this cannot be done. In this method, you can add the following code to modify the parameter object: param. append ("");

11. What are the differences between the "=" and equals methods?

= The operator is used to compare whether the values of two variables are equal, that is, to compare whether the values stored in the memory corresponding to the variables are the same, to compare two basic types of data or two reference variables,

Only the = operator can be used.

The equals method is used to compare whether the content of two independent objects is the same, just like to compare whether two objects have the same looks. The two objects compared by equals are independent.

12. What are the differences between static variables and instance variables?

Syntax definition difference: the static keyword must be added before the static variable, but not before the instance variable.

Differences during program running: instance variables belong to the attributes of an object. You must create an instance object. Only instance variables in the instance can be allocated space to use this instance variable. Static variables do not belong to an instance object,

It is a class, so it is also called a class variable. As long as the program loads the class bytecode and does not need to create any instance object, static variables will be allocated space, static variables can be used.

In short, instance variables can be used only after an object is created. Static variables can be referenced directly by class names.

13. Can I call non-static methods from inside a static method?

No. Because a non-static method is associated with an object, you must create an object before you can call the method on the object. When a static method is called, you do not need to create an object, can be called directly.

That is to say, when a static method is called, no instance object may be created. If a non-static method is called from a static method, which object is associated with the non-static method?

This logic cannot be established. Therefore, a static method internally calls non-static methods.

14. What is the difference between Integer and int?

Int is one of the eight primitive data types provided by java. Java provides encapsulation classes for each original type, and Integer is the encapsulation class provided by java for int. The default value of int is 0, while that of Integer is null,

That is to say, Integer can distinguish between unassigned values and 0 values. int cannot express unassigned values.

15. How much is Math. round (11.5? Math. round (-11.5) and so on?

The Math class provides three methods related to rounding: ceil, floor, and round. The functions of these methods correspond to the meanings of their English names,

For example, if the English meaning of ceil is the ceiling, this method indicates to rounded up. Therefore, Math. the result of ceil (11.3) is 12, Math. the result of ceil (-11.3) is-11;

The English meaning of floor is floor. This method indicates downgrading. Therefore, Math. the result of floor (11.6) is 11, Math. the result of floor (-11.6) is-12;

The most difficult to master is the round method, which indicates "Rounding". The algorithm is Math. floor (x + 0.5 ),

Add 0.5 to the original number and then round down. Therefore, Math. round (11.5) returns 12 and Math. round (-11.5) returns-11.

16. What are the differences between the public, private, and protected scopes and when no data is written?

The visible scopes of these four scopes are shown in the following table. NOTE: If no access modifier is written on the modifier, friendly is displayed.

Scope: current class, same package, Child class, other package

Public √

Protected √ ×

Friendly √ ××

Private √ ×××

Note: you only need to remember that you have four access permissions and four access ranges, then, we can sort the entire selection and range in the horizontal and vertical directions from small to large or from large to small order, which makes it easy to draw the above figure.

17. Differences between Overload and Override. Can the Overloaded method change the type of the returned value?

Overload is the meaning of Overload, Override is the meaning of overwrite, that is, rewrite.

Overload indicates that multiple methods with the same name can exist in the same class, but the parameter lists of these methods are different (that is, the number or type of parameters are different ).

Override indicates that the method in the subclass can have the same name and parameter as a method in the parent class. When this method is called through the instance object created by the subclass, the definition method in the subclass is called,

This is equivalent to overwriting the exactly same method defined in the parent class, which is also a manifestation of object-oriented programming polymorphism. When a subclass overwrites the method of the parent class, it can only throw fewer exceptions than the parent class,

Or a child exception that throws the exception thrown by the parent class, because the child class can solve some problems of the parent class and cannot have more problems than the parent class. The access permission of the subclass method can only be larger than that of the parent class, and cannot be smaller.

If the method of the parent class is of the private type, there is no overwrite restriction on the subclass, which is equivalent to adding a new method to the subclass.

The question about whether the Overloaded method can change the type of the returned value depends on what you want to ask? This question is vague. If the parameter lists of several Overloaded methods are different,

Of course, their return types can be different.

18. Can Constructor be overwritten?

Constructor cannot be inherited, So Override cannot be overwritten, but Overload can be overloaded.

19. Can an interface inherit an interface? Can an abstract class implement the (implements) interface? Can an abstract class inherit a specific class (concrete class )? Can there be static main methods in abstract classes?

Interfaces can inherit interfaces. Abstract classes can be implemented (implements) interfaces. abstract classes can inherit object classes, provided that the object classes must have clear constructors. Abstract classes can have static main methods.

Only remember that the only difference between an abstract class and a common class is that you cannot create an instance object or enable abstract methods.

20. When writing the clone () method, there is usually a line of code. What is it?

Clone has a default behavior, super. clone (); because the Members in the parent class must be copied to the position, and then the members of the parent class should be copied.

21. What is the mechanism for implementing polymorphism in java?

The reference variables defined by the parent class or interface can point to the subclass or the Instance Object of the specific implementation class, and the method called by the program is dynamically bound at runtime, is the method to reference the specific instance object pointed to by the variable,

That is, the method of the object that is running in the memory, instead of referencing the method defined in the variable type.

22. What is the difference between abstract class and interface?

The class containing the abstract modifier is an abstract class, and the abstract class cannot create instance objects. Classes that contain abstract methods must be defined as abstract class. Methods in abstract class do not need to be abstract.

Abstract methods defined in the abstract class must be implemented in the Concrete subclass. Therefore, there cannot be abstract constructor or abstract static methods. If the subclass does not implement all abstract methods in the abstract parent class,

The subclass must also be defined as abstract type.

An interface can be said to be a special case of an abstract class. All methods in an interface must be abstract. The method definition in the interface is public abstract by default,

The default member variable type in the interface is public static final.

The following compares the syntax differences between the two:

1. abstract classes can have constructor methods, and interfaces cannot have constructor methods.

2. abstract classes can contain common member variables. The interface does not contain common member variables.

3. abstract classes can contain non-Abstract Common methods. All methods in the interface must be abstract and cannot have non-Abstract Common methods.

4. abstract classes can access public, protected, and (default type, although there is no error in eclipse, but it should not), but the abstract methods in the interface can only be public,

The default value is public abstract.

5. abstract classes can contain static methods. Interfaces cannot contain static methods.

6. the abstract class and interface can contain static member variables. The access type of static member variables in the abstract class can be any, but the variables defined in the interface can only be of the public static final type,

The default value is public static final.

7. A class can implement multiple interfaces, but can inherit only one abstract class.

23. can abstract methods be both static, native, and synchronized?

Abstract methods cannot be static, because abstract methods must be implemented by the quilt class, but static and subclass cannot be connected!

The native method indicates that the method must be implemented in another programming language dependent on the platform. There is no problem with the implementation of the quilt class. Therefore, it cannot be abstract or mixed with abstract.

I don't think synchronized can be used with abstract, because I have never seen this in my years of study and development, and I think synchronized should be used in

The specific method makes sense. In addition, synchronized synchronization on the method uses the synchronization Lock Object this, while the abstract method cannot determine what this is.

24. What is an internal class? StaticNested Class and Inner Class are different.

An internal class is a class defined inside a class. A static member cannot be defined in an internal class. (a static member is not a feature of an object. It is just to find a reference, so you need to put it in a class,

You need to put this little thing into a class inside the class, too much! Provides internal classes, not to let you do such a thing, boring, not to let you do it.

I think it may be because static members are similar to global variables in C language, and internal classes are usually used to create internal objects. Therefore, putting "global variables" in an internal class is meaningless,

Since it is meaningless, it should be disabled), internal classes can directly access member variables in external classes, and internal classes can define external methods of external classes, you can also define the method bodies of external classes.

25. Can an internal class reference its members that contain classes? Are there any restrictions?

Yes. If it is not a static internal class, there is no limit!

26. Can Anonymous Inner Class (Anonymous internal Class) be extends (inherited) other classes, or implements (implemented) interface (interface )?

It can inherit other classes or implement other interfaces. Not only can, but must!

27. Which classes in jdk cannot be inherited?

Classes cannot be inherited from those modified with the final keyword. Generally, the basic types or the types that prevent extension classes from inadvertently damaging the implementation of the original method should be final,

In jdk, System, String, and StringBuffer are all basic types.

28. Is String the most basic data type?

Basic data types include byte, int, char, long, float, double, boolean, and short.

Java. lang. String class is of the final type. Therefore, it cannot be inherited or modified. To improve efficiency and save space, we should use the StringBuffer class

29. Strings = "Hello"; s = s + "world! "; After these two lines of code are executed, have the content in the original String object changed?

No. Because String is designed as an immutable class, all its objects are immutable objects.

30. Can I inherit the String class?

The String class is a final class, so it cannot be inherited.

31. String s = new String ("xyz"); how many String objects are created? What is the difference between the two?

Two, "xyz" corresponds to an object. This object is placed in the String constant buffer, and the constant "xyz" is the one in the buffer no matter how many times it appears. Each time a New String is written, a New object is created,

It refers to the content of the constant "xyz" object to create a New String object. If you have used 'xyz' before, this statement means that you will not create the "xyz" yourself and take it directly from the buffer zone.

32. What are the differences between String and StringBuffer?

The JAVA platform provides two classes: String and StringBuffer, which can store and operate strings, that is, character data containing multiple characters. String class indicates a String whose content cannot be changed.

The StringBuffer class indicates a string whose content can be modified. When you know that character data is changing, you can use StringBuffer.

33. Differences between StringBuffer and StringBuilder

Both the StringBuffer and StringBuilder classes indicate strings whose content can be modified. StringBuilder is thread-insecure and highly efficient. If a string variable is defined in a method,

In this case, only one thread may access it. If there is no unsafe factor, use StringBuilder. If you want to define member variables in the class and the instance objects of the class will be used in the multi-threaded environment,

StringBuffer is recommended.

34. How can I convert a comma-separated string into an array?

If you do not check the jdk api, it is hard to write it out! Let me talk about my ideas:

Use a regular expression. The code is probably String [] result = orgStr. split (",");

Use StingTokenizer. The code is StringTokenizertokener = StringTokenizer (orgStr ,",");

String [] result = newString [tokener. countTokens ()];

Int I = 0;

While (tokener. hasNext () {result [I ++] = toker. nextToken ();}

35. Does the array have the length () method? Does String have the length () method?

The data does not have the length () method. There is the length attribute, and the String has the length () method.

36. If there is a return statement in try {}, will the code in finally {} following this try be executed? When will it be executed, before or after return?

Will be executed, and will be executed before return.

37. What are the differences between final, finally, and finalize?

Final is used to declare attributes. Methods and classes indicate that attributes are unchangeable, methods cannot be overwritten, and classes cannot be inherited.

Finally is a part of the structure of the exception handling statement, indicating that it is always executed.

Finalize is a method of the Object class. This method is called when the garbage collector is executed. It can overwrite this method to collect other resources during garbage collection,

For example, close a file. JVM does not guarantee that this method is always called

38. What are the similarities and differences between runtime exceptions and general exceptions?

An exception indicates an abnormal state that may occur during the running of the program. An exception indicates an exception that may occur during common operations on the virtual machine. It is a common running error.

The java compiler requires that methods must declare and throw possible non-runtime exceptions, but do not require that they throw uncaptured runtime exceptions.

39. What is the difference between error and exception?

Error indicates that recovery is not a serious problem that is impossible but difficult. For example, memory overflow. It is impossible to expect the program to handle such a situation.

Exception indicates a design or implementation problem. That is to say, it indicates that if the program runs normally, it will never happen.

40. Write the five most common runtime exceptions.

This question mainly tests how large your code volume is. If you write code for a long time, you will often see system exceptions, you don't have to answer five specific system exceptions,

However, you need to be able to tell what a system exception is and how many system exceptions are required. Of course, these exceptions are best written in English. If they cannot be written, use Chinese. It's better than nothing!

The so-called system exception ....., They are all subclasses of RuntimeException. in jdk doc, you can view the list of RuntimeException classes, that is, all system exceptions.

I was impressed by the following system exceptions: NullPointerException, ArrayIndexOutOfBoundsException, and ClassCastException.

41. How to handle exceptions in JAVA? What are the meanings of keywords: throws, throw, try, catch, and finally? Can I throw an exception in the try block?

Throws capture and throw exceptions

Throw an exception

Try catch captures internal exceptions and performs custom processing.

Finally is a statement that is processed no matter whether an exception exists, except when System. exit (int I) is executed before finally.

42. How can I implement a thread in java? What keywords are used to modify the synchronization method? Why is the stop () and suspend () methods not recommended?

There are two implementation methods: Inheriting the Thread class and implementing the Runnable interface.

Synchronized keyword modification Synchronization Method

The use of stop () is opposed because it is insecure. The suspend () method is prone to deadlocks.

43. What is the difference between sleep () and wait?

Sleep () is to let the thread specify the sleep time, and then continue to work,

Wait () is waiting until a thread notifies notify () to wake up.

44. What are the similarities and differences between synchronization and Asynchronization? Under what circumstances should they be used separately? Example?

If data is shared among threads. For example, if the data being written may be read by another thread or the data being read may have been written by another thread, the data is shared data,

Synchronous access is required. When an application calls a method that takes a long time to execute on an object and does not want the program to wait for the return of the method, asynchronous programming should be used,

In many cases, adopting asynchronous channels is often more efficient.

45. Do I use run () or start () to start a thread ()?

To start a thread, call the start () method to make the thread ready. In the future, the thread can be scheduled to run. A thread must be associated with some specific Execution Code. run () the method is the Execution Code associated with the thread.

46. After a thread enters a synchronized method of an object, can other threads access other methods of this object?

In several cases: 1. Whether the synchronized keyword is added before other methods. If not, yes.

2. If this method calls wait internally, you can access other synchronized methods.

3. If the synchronized keyword is added to other methods and wait is not called internally, no.

4. if other methods are static, the synchronization lock is the bytecode of the current class. Non-static methods cannot be synchronized because non-static methods use this.

47. What are the similarities and differences between synchronized and java. util. concurrent. locks. Lock?

The main point is that Lock can complete all functions implemented by synchronized.

Major difference: Lock has more precise thread semantics and better performance than synchronized. Synchronized Automatically releases the Lock, which must be manually released by the programmer and must be released in the finally clause.

Lock also has more powerful functions. For example, its tryLock method can get the Lock in non-blocking mode.

48. What is the difference between ArrayList and Vector?

(1) Synchronization: the Vector is thread-safe, that is, its methods are thread-synchronized, And the ArrayList is thread-program unsafe, its methods are not synchronized between threads.

(2) Data growth: that is, doubling the original growth of Vector, and increasing the original ArrayList by 0.5 times.

49. What is the difference between HashMap and Hashtable?

HashMap and HashTable are mainly used in three aspects:

(1) historical reasons: Hashtable is based on the obsolete Dictionary class, And HashMap is an implementation of the Map interface introduced by Java 1.2;

(2) Synchronization: Hashtable is thread-safe, that is, synchronous, while HashMap is not secure or synchronized;

(3) value: Only HashMap allows you to use a null value as the key OR valu of a table entry.

50. What is the difference between List and Map?

One is a set of Single-Column data, and the other is a set of double-row data such as the storage key and value. The data stored in the List is ordered and repeat is allowed;

The data stored in Map has no sequence, and its keys cannot be repeated. Its values can be repeated.

51. Does List, Set, and Map inherit from the Collection interface?

List, Set is, Map is not.

52. What are the features of the interfaces List, Map, and Set when accessing elements?

List and Set are similar. They are a Set of single-column elements. Therefore, they have a common parent interface called Collection. Duplicate elements are not allowed in the Set. Two identical elements are not allowed.

A List holds elements in a specific order, and can contain duplicate elements. Set cannot have repeated elements and can be sorted internally. Map stores the key-value, which can be multiple values.

53. What are the storage performance and features of ArrayList, Vector, and sort list?

Both ArrayList and Vector use arrays to store data. The number of elements in the array is greater than that in the actual data storage to add and insert elements. They allow the element to be indexed by serial number directly,

However, inserting elements involves memory operations such as array element movement, so index data is fast and data insertion is slow. Because Vector uses the synchronized Method (thread-safe), its performance is generally inferior to that of ArrayList,

The sorted list uses a two-way linked list for storage. Data indexed by serial number needs to be traversed in the forward or backward direction. However, when inserting data, you only need to record the items before and after this item, so the insertion speed is fast.

The producer list is thread unsafe. The producer list provides some methods so that the producer list can be used as a stack and queue.

54. What is the difference between Collection and Collections?

Collection is the upper-level interface of the Collection class. Its inherited interfaces include Set and List.

Collections is a help class for collection classes. It provides a series of static methods for searching, sorting, thread security, and other operations on various sets.

55. The elements in the Set cannot be repeated. How can we distinguish whether the elements are repeated or not? Is = or equals () used ()? What are their differences?

The elements in the Set cannot be repeated. The equals () method is used to determine whether the elements are repeated.

The equals () and = Methods Determine whether the reference value points to the same object equals () is overwritten in the class, in order to return the true value when the content and type of the two separated objects match.

56. The two objects have the same value (x. equals (y) = true), but different hash codes are available, right?

No. Their hash code must be the same.

57. Can I name five common classes, packages, and interfaces?

Common classes: BufferedReader, BufferedWriter, FileReader, FileWirter, String Integer, java. util. Date, System, Class, List, HashMap

Common packages: java. lang, java. io, java. util, java. SQL, javax. servlet, org. apache. strtuts. action, org. hibernate

Common interfaces: Remote, List, Map, Document, NodeList, Servlet, HttpServletRequest, HttpServletResponse, Transaction (Hibernate), Session (Hibernate), and HttpSession

58. How many types of streams are there in java? JDK provides some abstract classes for each type of stream for inheritance. which classes are they?

Byte stream: bytes stream. Byte streams are inherited from InputStreamOutputStream, and bytes streams are inherited from InputStreamReaderOutputStreamWriter.

There are many other streams in the java. io package, mainly to improve performance and ease of use.

59. What is java serialization and how to implement java serialization? Or what is the role of the Serializable interface?

We sometimes convert a java object into a byte stream or restore it to a java object from a byte stream. For example, to store java objects on hard disks or to other computers on the network,

In this process, we can write code to convert a java object into a byte stream of a certain format for further transmission. However, jre itself provides this support. We can call the writeObject method of OutputStream to do this,

If you want java to help us, the object to be transmitted must implement the serializable interface, so that special processing will be performed during javac compilation, and the compiled class can be operated by the writeObject method,

This is the so-called serialization. The class to be serialized must implement the Serializable interface, which is a mini interface without implementation methods,

Implements Serializable is only used to indicate that the object can be serialized.

60. How does JVM load class files?

In JVM, class loading is implemented by ClassLoader and its subclass. Java ClassLoader is an important Java runtime system component. It is responsible for finding and loading classes of class files at runtime.

61. What is the difference between heap and stack?

Java memory is divided into two types: stack memory and stack memory. Stack memory refers to a private storage space allocated separately for the method when the program enters a method, used to store local variables in the method,

When this method ends, the stack assigned to this method will be released, and the variables in this stack will also be released. The heap memory is different from the stack memory. It is generally used to store data that is not placed in the current method stack,

For example, all objects created using new are stored in the heap, so it does not disappear as the method ends. The local variables in the method are modified using final and placed in the heap instead of the stack.

62. What is GC? Why does GC exist?

GC is the meaning of garbage Collection (Gabage Collection). Memory Processing is a place where programmers are prone to problems. Forgetting or wrong memory Collection can lead to instability or even crash of programs or systems,

The GC function provided by Java can automatically monitor whether the object exceeded the scope to automatically recycle the memory. the Java language does not provide a display operation to release the allocated memory.

63. When should I use assert?

Assertion is a common debugging method in software development. Many development languages support this mechanism. In implementation, assertion is a statement in the program,

It checks a boolean expression. A correct program must ensure that the value of this boolean expression is true. If the value is false, the program is already in an incorrect state,

Assert will give a warning or exit. Generally, assertion is used to ensure the most basic and critical correctness of the program. The assertion check is usually enabled during development and testing. To improve performance,

After the software is released, the assertion check is usually disabled.

64. Tomcat optimization experience?

Remove web. xml monitoring and edit jsp into Servlet in advance. Increase the jvm memory used by tomcat when there is excess physical memory

65. What is the difference between GET and POST methods in HTTP requests?

The post transmission data volume is large and safe. Use the request. form ("") value.

Get delivers a small amount of data without high post security. Use request. querystring ("value ").

66. What is servlet?

Servlet has a good life cycle definition, including loading and instantiation, initialization, request processing, and service termination. The lifetime is expressed by the init, service, and destroy methods of the javax. servlet. Servlet interface.

67. What is the Servlet lifecycle?

After the Servlet is instantiated by the server, the container runs its init method, runs its service method when the request arrives, and the service method automatically dispatches the doXXX method (doGet, doPost) corresponding to the request, etc,

The destroy method is called when the server decides to destroy the instance.

The web container loads the servlet and starts its lifecycle. Call the servlet init () method to initialize the servlet. You can call the service () method to call different do *** () methods based on different requests.

End the service. The web Container calls the servlet's destroy () method.

68. What is the difference between forward () and redirect?

Forward is a server request resource. The server directly accesses the URL of the target address, reads the response content of that URL, and then sends the content to the browser,

The browser does not know where the content sent by the server comes from, so its address bar is still the original address.

Redirect means that the server sends a status code based on logic to tell the browser to request the address again. Generally, the browser will re-request the address with all the parameters just requested,

Therefore, all session and request parameters can be obtained.

69. Under what circumstances do I call doGet () and doPost ()?

The method attribute in the FORM label in the Jsp page is doGet () when get is called, and doPost () is called when post is called ().

70. What built-in objects does jsp have? What are their roles? What are the methods?

JSP has the following nine built-in objects:

Request client request, which contains parameters from the GET/POST request

Response returned from the response webpage to the client

The pageContext page is managed here.

Session-related session Period

Content being executed by application servlet

Out is used to send response output.

Configuration servlet framework

Page JSP page itself

Exception for the error webpage, exceptions not captured

71. What actions does jsp have? What are their roles?

JSP has the following 6 basic actions:

Jsp: include: Introduce a file when the page is requested.

Jsp: useBean: Find or instantiate a JavaBean.

Jsp: setProperty: Set attributes of JavaBean.

Jsp: getProperty: outputs the attributes of a JavaBean.

Jsp: forward: Transfers requests to a new page.

Jsp: plugin: generate the OBJECT or EMBED tag for the Java Plug-in based on the browser type

72. What is the difference between dynamic INCLUDE and static INCLUDE in JSP?

Implement Dynamic INCLUDE with jsp: include action

It always checks the changes in the contained files and is suitable for containing dynamic pages. It can also be implemented by using the INCLUDE pseudo code with the static include parameter.

Does not check changes in the contained files, applicable to include static pages

<% @ File = "included.htm" include = "">

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.