Skip to content

Typos and small issues in Numbers and Strings -> Characters, Strings tutorial pages #239

@willy-b

Description

@willy-b

Hello dev.java team!

Just reporting a few typos and small content issues in the Characters and Strings pages of the Numbers and Strings introductory tutorial, in case they are of interest to fix. Thanks!


In the latest version of https://dev.java/learn/numbers-strings/characters/ (archived as is at https://web.archive.org/web/20260428024508/https://dev.java/learn/numbers-strings/characters/ ),

  • In the sentence

    This feature is called _autoboxing_—or unboxing, if the conversion goes the other way.

    It seems "_autoboxing_" was intended to be formatted rather than having literal underscores, maybe italicized or something.

  • FWIW, the escape sequences table is missing "\s" and "\ LineTerminator (line continuation, no Unicode representation)" despite the title implying it is a complete list of Java escape sequences:

    The following table shows the Java escape sequences:
    Escape Sequence Description
    \t Insert a tab in the text at this point.
    \b Insert a backspace in the text at this point.
    \n Insert a newline in the text at this point.
    \r Insert a carriage return in the text at this point.
    \f Insert a form feed in the text at this point.
    ' Insert a single quote character in the text at this point.
    " Insert a double quote character in the text at this point.
    \ Insert a backslash character in the text at this point.

    See https://docs.oracle.com/javase/specs/jls/se26/html/jls-3.html#jls-3.10.7 to see that "\s" (and "\ LineTerminator (line continuation, no Unicode representation)")) might be included for completeness.


In the latest https://dev.java/learn/numbers-strings/strings/ (archived as is at https://web.archive.org/web/20260503024147/https://dev.java/learn/numbers-strings/strings/ ) ,

  • There is a missing closing parenthesis at the end of "(Byte, Integer, Double, Float, Long, and Short":

    The Number subclasses that wrap primitive numeric types (Byte, Integer, Double, Float, Long, and Short each provide a class method named valueOf() that converts a string to an object of that type.

  • An absent figure is referenced ("shown in the following figure", where?) and StringIndexOutOfBoundsException is warned for the wrong method (should be the filename() method, NOT "extension method"/extension() that can throw an exception when there is no extension separator found):

    As shown in the following figure, our extension method uses lastIndexOf() to locate the last occurrence of the period (.) in the file name. Then substring uses the return value of lastIndexOf() to extract the file name extension — that is, the substring from the period to the end of the string. This code assumes that the file name has a period in it; if the file name does not have a period, lastIndexOf() returns -1, and the substring method throws a StringIndexOutOfBoundsException.

    No such Exception will be thrown for extension(), as long as the entire filename (fullPath) is not empty, as fullPath.lastIndexOf(extensionSeparator) will be -1 and so fullPath.substring(dot+1) will be fullPath.substring(0) which is just fullPath:

    public String extension() {
           int dot = fullPath.lastIndexOf(extensionSeparator);
           return fullPath.substring(dot + 1);
       }
    

    However, the filename() method WILL (unlike extension()) throw an Exception when called on a filename without an instance of extensionSeparator,
    as dot will be -1 and fullPath.substring(sep _+ 1, -1) will be called:

    public String filename() {
           int dot = fullPath.lastIndexOf(extensionSeparator);
           int sep = fullPath.lastIndexOf(pathSeparator);
           return fullPath.substring(sep + 1, dot);
       }
    
  • There is a missing closing parenthesis at the end of "(for example, append(), insert(), or setLength()":

    A number of operations (for example, append(), insert(), or setLength() can increase the length of the character sequence in the string builder so that the resultant length() would be greater than the current capacity(). When this happens, the capacity is automatically increased.


Thanks very much!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions