I have a search box in the title of my web application and use autocomplete to help users find books by author name or book title. When you enter the user, the function oninput()calls the servlet FindBooksthrough ajax. FindBooksservlet calls the static method of the suggest()class SuggestionBook, which returns an array of books matching the input string.
FindBooks.java
JSONArray books = SuggestionBook.suggest(inputString);
out.print(books);
SuggestionBook.java
private static boolean isTernaryEmpty = true;
private static Ternary ternary;
private static void fillTernary() {
isTernaryEmpty = false;
}
public static JSONArray suggest(String searchString) {
if(isTernaryEmpty) {
fillTernary();
}
return ternary.find(searchString);
}
static SuggestionBook.java, . , , . , static. , - , ? , . , JVM? , , , SuggestionBook . class variables, instance variables, .