There is a compilation error when trying to compile

String s = "65535 символов на одну больше чем 2 в степени 16" 

but 65,534 characters compiles, for some reason, why a string pool cannot contain more than two byte lines? plus it is logical that the maximum size of a string can only be Integer.MAX_VALUE, because string.length () returns an int, but something when trying to run

  while (true) {//делал такое и со String, сути и ошибки не меняются stringBuilder.append(stringBuilder); System.out.println(stringBuilder.length()); } 

gives an error message

 536829952 Exception in thread "main" java.lang.OutOfMemoryError: Java heap space 

Not even close to the maximum value of int.

  • You have two questions here that actually have very little in common with each other: the first refers to the compilation, the second to the execution. On Stack Overflow, it's not customary to ask a few questions in one. Try to ask them one by one. - default locale
  • one
    A question similar (but not quite) to the first part of your: ru.stackoverflow.com/questions/661454/… - default locale
  • one
    A question similar to the second part: ru.stackoverflow.com/questions/537294/… - default locale
  • @ default-locale you can actually find more questions if you look like this) - Alexander Belov

0