Using the static method and variables in a Java web application

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() {
  // fills ternary search tree with data.
  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, .

+4
2

, - , ?

, , , .

, . , , , . , .

, . , .

, . , JVM?

java - . - , , - , . . , , . , . .

, , , SuggestionBook . , , .

, webapp . , / /. , . , , ( ), static, , . , . , .

+4

, . , .

, , , , , .

1) . , .

2) fillTernary , i.e if (isTernaryEmpty). , if , .

0

Source: https://habr.com/ru/post/1569968/


All Articles