String3 for Java programmer test interview and string3 for java programmer

Source: Internet
Author: User

String3 for Java programmer test interview and string3 for java programmer

Public class SameString {// thought 2: each character corresponds to its own ASC code. The algorithm complexity of the first idea is O (nlogn ), generally, space can be used to reduce the time complexity. // an array space with a size of 256 can be opened up and 256 array elements are set to 0, traverse the first string and use ASC as the array subscript. Add 1 to all array elements. // then traverse the second string and subtract 1 from each value of the array element, if the value of the last array element is 0, it indicates the same string. The time complexity of this algorithm is O (n) public static void compare (String s1, String s2) {byte [] b1 = s1.getBytes (); byte [] b2 = s2.getBytes (); int [] bCount = new int [256]; for (int I = 0; I <256; I ++) {bCount [I] = 0 ;} for (int I = 0; I <b1.length; I ++) {bCount [b1 [I]-'0'] ++ ;}for (int I = 0; I <b2.length; I ++) {bCount [b2 [I]-'0'] --;} for (int I = 0; I <256; I ++) if (bCount [I]! = 0) {System. out. println ("not equal! "); Return;} System. out. println (" equal! ");} Public static void main (String args []) {String s1 =" aaabbbccc "; String s2 =" ababacbcc "; compare (s1, s2 ); string s3 = "aabbccdd"; String s4 = "abc"; compare (s3, s4 );}}
Result: partition not equal



What are all written test interviews for java programmers?

1) Basic Object-Oriented Knowledge
2) write a program in java, which is usually output after sorting or computing.
3) basic knowledge about web development, such as what is jsp, the difference between servlet and jsp, and the difference between session and cookie
4) understand Common open-source frameworks, such as struts, spring, hibernate, and ibatis.

Java programmer interview questions

Principles and Applications of java exception Mechanism
A: If the program does not handle any exceptions, the program will be interrupted.
In fact, after an exception is generated, the JVM will throw an exception class instantiation object. If a try statement is used to capture the object at this time, the exception can be processed. Otherwise, the exception is handed over to the JVM for processing. When an exception is caught by a try statement, it matches the exception type of the catch statement. If the exception type matches successfully, the catch statement is executed. Simple Application: Add try-catch to the throws statement. Standard Application: try-catch-finally-throw-throws.
2. Advantages of the garbage collection mechanism
A: Release the space occupied by useless objects. Method: Automatic Recovery and manual recovery. Use System. gc () to actually call Runtime. getRuntime (). gc ()
3. Difference between Error and Exception
A: The Error is handled by jvm, and the Error is a jvm Error.
Exception can be handled by a program and captured using try-catch.
4. final, finally, finallize
A: The final defined variable values cannot be changed, the defined methods cannot be overwritten, And the defined classes cannot be inherited.
Finally is the unified exit of exceptions. finallize is the final work before garbage collection and is defined by the Object class.
5. Does Anonymous Inner Class support extends and implements Interface?
A: inheritance and implementation are allowed, because anonymous internal classes are developed based on abstract classes and interfaces.
6. Differences between Static Nested Class and Inner Class
A: The Class defined using Static is an external Class, which can be directly accessed through an external Class. Internal Class
Inner Class cannot be accessed externally. It can only be found through external Class instances.
7. HashMap and HashTable?
A: HashMap: 1) released in jdk 1.2, new Class 2) asynchronous processing, high performance, non-thread-safe 3) Allow null
HashTable: 1) released in jdk 1.0, old Class 2) adopts synchronous processing mode with low performance and is thread-safe. 3) null is not allowed.
8. What does assert mean?
A: asserts is a New Keyword released after jdk 1.4. asserts indicates assertions, that is, the execution of a program to a certain place must be an expected value, which is rarely used in development. To use assert, the-ea parameter must be added.
9. What is gc?
A: gc is a garbage collection. garbage collection can be used to release junk space.
10. How many objects are generated by String s = new String ("xyz?
A: An anonymous object xyz is in the stack space. A new instantiated object is in the heap space.
11. sleep () and wait ()?
A: sleep () is the Thread class definition method. It indicates the Thread sleep and can be automatically awakened.
The wait () method is defined by the Object class. You need to manually release y () and policyall () // sleep () without releasing resources. wait () releases resources.
12. goto exists in java, but it cannot be used.
13. Does the array have length () and String have length ()?
A: The array has the length attribute and the String has the length () attribute ()
14. Differences between Overload and Override
Answer: Overload: Heavy Load
|-Several methods defined in a class
|-All methods have the same name, but different parameter types or numbers
|-Only the parameters are related and the return type is irrelevant.
Overrid ...... the remaining full text>

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.