String4 for Java programmers and string4 for java programmers

Source: Internet
Author: User

String4 for Java programmers and string4 for java programmers

How does one Delete the repeated characters "good" in the String?

Thought 1: the brute force method performs a dual loop. The complexity of this algorithm is O (n ^ 2), and n refers to the length of the string.

public class RemoveSameChar {     public static String removeDuplicate(String s){     char[] c=s.toCharArray();     for(int i=0;i<c.length;i++){     if(c[i]=='\0'){     continue;     }     for(int j=i+1;j<c.length;j++){     if(c[i]=='\0'){         continue;         }     if(c[i]==c[j]){     c[j]='\0';     }     }     }     int n=0;     for(int i=0;i<c.length;i++){     if(c[i]!='\0'){     c[n++]=c[i];     }     }     return new String(c, 0, n);     }     public static void main(String args[]){          String s="good";     s = removeDuplicate(s);     System.out.println(s);     String s1="aabbcc";     s1=removeDuplicate(s1);     System.out.println(s1);     }}
Result: godabc



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>

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.