Структура JVM
Структура памяти
В документации полностью описаны области памяти в JVM - https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-2.html
Сборщик мусора
Документация по GC - https://www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html
Строки
Интернирование
String s1 = "Hello, World";
String s2 = "test";
System.out.println("Comparing s1 and s2");
System.out.println(s1 == s2);
System.out.println(s1.equals(s2));
System.out.println("Comparing s1 and s3");
String s3 = new String(s1);
System.out.println(s1 == s3);
System.out.println(s1.equals(s3));
System.out.println("Interning s1 and s3");
System.out.println(s1 == s3.intern());
System.out.println("Comparing concatenated strings");
String s4 = s1+"!";
System.out.println(s4 == s1+"!");
System.out.println(s4 == (s1+"!").intern());
System.out.println(s4.intern() == (s1+"!").intern());
System.out.println(s4.equals(s1+"!"));
Полезные ссылки
- String pooling - http://java-performance.info/string-intern-in-java-6-7-8/
Методы
String description = "The class String includes methods for examining\n" +
" * individual characters of the sequence, for comparing strings, for\n" +
" * searching strings, for extracting substrings, and for creating a\n" +
" * copy of a string with all characters translated to uppercase or to\n" +
" * lowercase";
System.out.println("Length: "+description.length()+", is empty: "+description.isEmpty());
String[] words = description.split(" ");
for(String word : words) {
System.out.println(word);
}
String shortDescription = description.substring(10);
System.out.println(shortDescription);
shortDescription = description.substring(description.indexOf("String"));
System.out.println(shortDescription);
String usdNumber = "$101.78";
System.out.println(usdNumber.matches("\\$\\d*\\.\\d*"));
String stringWithPrice = "Cost is 101.56 USD in Target";
System.out.println(stringWithPrice.replaceAll("(\\d*\\.\\d*)( USD)", "\\$$1"));
String[] numbers = new String[] {"one", "two", "three"};
System.out.println(String.join(",", numbers));
StringBuilder и StringBuffer
Числа
Материалы
Презентация: Типы данных в Java
Полезные ссылки
- String pooling - http://java-performance.info/string-intern-in-java-6-7-8/