Standard 7-bit ASCII assigns a unique integer from 0 to 127 to 128 characters and control codes, and Java represents those same integers through its unsigned 16-bit char type and the int values produced by casting. To use ASCII code in Java, you need three things: the exact numeric value of a character or control code, a reliable way to look it up across decimal, hexadecimal, octal, and binary, and an understanding of how Java's primitive types expose those numbers. The decimal-to-glyph mapping is fixed by RFC 20 and the Unicode Basic Latin chart, so capital A is always 65 (0x41), lowercase a is always 97 (0x61), and digit 0 is always 48 (0x30). Control codes such as NUL, HT, LF, and CR use the abbreviations defined in RFC 20 because they have no printable glyph. Java code rarely hardcodes these values directly, but when it does, for protocol parsing, file-format checks, character-class tests, or log scrubbing, accuracy matters because the wrong byte silently corrupts data. The ASCII Table gives Java developers a fast, exact lookup for every value from 0 through 127, presented in the four notations Java source code actually uses.

how to use ascii code in java
how to use ascii code in java

ASCII Code Basics Every Java Developer Needs

The American Standard Code for Information Interchange, defined in RFC 20 and ISO/IEC 646, is a 7-bit code set with exactly 128 positions numbered decimal 0 through 127. The code chart is partitioned into four practical regions that matter when you write Java code: control codes from 0 to 31, the space character at 32, graphic characters from 33 to 126, and the delete character at 127. RFC 20 supplies the abbreviations and full names for the control region, while the Unicode Basic Latin chart supplies the names for printable punctuation, digits, and letters. ECMA-6 confirms the 7-bit, 128-character scope and is the reason the boundary at 127 is deliberate rather than accidental.

Values above 127 do not belong to standard ASCII. Byte values 128 through 255 represent different characters depending on whether a file or protocol uses ISO-8859-1, a Windows code page, or an IBM PC code page such as CP437. Treating them as "extended ASCII" hides that ambiguity. Java's char type can hold those higher values because it is a 16-bit unsigned type backed by UTF-16, but the codes themselves are outside the ASCII standard and depend on a separate encoding decision. For most Java work involving the Latin alphabet, punctuation, and digit checks, the 0 to 127 range is what you actually need to verify.

How Java Stores ASCII Values: char, int, and Casting

A Java char is an unsigned 16-bit integer that holds a UTF-16 code unit. When that code unit corresponds to an ASCII character, the numeric value matches ASCII exactly because Unicode assigns the same code points to ASCII characters as their standard decimal values. Casting a char to int widens without sign extension, so the result is always a non-negative integer in the 0 to 65535 range. There are no negative ASCII codes in Java, even though some other languages expose the same byte as a signed value.

The most common patterns when you use ASCII code in Java are casting, comparison, and parsing. Casting (int) 'A' yields 65. Comparing c >= '0' && c <= '9' checks whether a character is an ASCII digit without allocating strings. Parsing with Integer.parseInt(hex, 16) or Integer.parseInt(octal, 8) converts a textual representation into the same integer you would see in the ASCII Table. These patterns depend on having the correct reference value in front of you, which is where a structured lookup beats memory or guesswork.

Common ASCII Values Java Developers Reach For

The table below lists ASCII positions that Java code touches most often. Each value comes from RFC 20 or the Unicode Basic Latin chart, the same two sources used to build the ASCII Table. Memorize the patterns rather than every individual number: digits occupy 48 to 57, uppercase letters 65 to 90, and lowercase letters 97 to 122.

CharacterDecimalHexOctalBinaryCommon Java use
NUL00x000o0000b0000000C-string terminator, empty byte marker
HT (Tab)90x090o0110b0001001Column-aligned log fields, CSV scrubbing
LF100x0A0o0120b0001010Unix line terminator in BufferedReader
CR130x0D0o0150b0001101Carriage return, part of CRLF on Windows
SP (Space)320x200o0400b0100000Whitespace token boundary, String.trim()
'0' to '9'48 to 570x30 to 0x390o060 to 0o0710b0110000 to 0b0111001ASCII digit parsing, base-10 validation
'A' to 'Z'65 to 900x41 to 0x5A0o101 to 0o1320b1000001 to 0b1011010Identifier start checks, case folding
'a' to 'z'97 to 1220x61 to 0x7A0o141 to 0o1720b1100001 to 0b1111010Lowercase parsing, locale-independent comparisons
DEL1270x7F0o1770b1111111Backspace sentinel, terminal control sequences

Knowing these ranges lets you write range checks that are faster than regex and easier to read than Character.isLetter calls when you specifically need ASCII-only behavior. For broader character-class work beyond ASCII, the programming-focused ASCII guide walks through the same idea across multiple languages.

How to Look Up an ASCII Code for Java

The ASCII Table is a browser-based reference that contains all 128 standard code positions, each shown with the same four numeric notations Java source uses. Follow these steps when you need a verified value to drop into code.

  1. Open the ASCII Table in your browser. You will see the complete 128-row list, each row showing a character or control abbreviation, descriptive name, decimal, two-digit hex, three-digit octal, seven-bit binary, and a category.
  2. Decide whether you want the value of a specific character or you want to scan a category. To find one code, use the search box. To scan a group such as all digits or all uppercase letters, leave the search blank and pick a category from the filter.
  3. Type into the search box using whichever form you already have. Plain digits such as 65 are treated as exact decimal. Hexadecimal needs the 0x prefix, octal needs 0o, and binary needs 0b, so 0x41, 0o101, and 0b1000001 all return capital A. You can also type names such as line feed, abbreviations such as LF, or literal characters using the char:value syntax such as char:A or char:space.
  4. Confirm the matching row by reading the character column and the four numeric columns side by side. The decimal value is the source integer; hex is padded to two digits, octal to three, and binary to seven, which matches the fixed-width prefixes Java prints with Integer.toHexString, Integer.toOctalString, and Integer.toBinaryString.
  5. Select Copy on the row you need. The Copy button writes one complete row in a readable text format, including the display value, name, decimal, hex, octal, and binary. Paste that line directly into a code comment, a bug report, a protocol note, or a teaching slide.

Search terms and copied rows are processed inside the browser, so no code-point lookup is sent to a remote service. If clipboard permission is denied, the page reports the failure rather than reporting a successful copy, and changing the search or category clears the previous copy message so stale output does not leak into your editor.

Using ASCII Codes in Java: Practical Patterns

Once you have the exact value, a few patterns cover most real Java work. The first is the simple cast: int code = (int) 'A'; produces 65, which you can then format with String.format("0x%02X", code) to get 0x41, matching the hexadecimal column of the table. The second pattern is range testing for ASCII digits and letters, which avoids locale-sensitive methods when you specifically want ASCII behavior:

boolean isAsciiDigit(char c) { return c >= '0' && c <= '9'; } boolean isAsciiUpper(char c) { return c >= 'A' && c <= 'Z'; } boolean isAsciiLower(char c) { return c >= 'a' && c <= 'z'; }

The third pattern is conversion in the other direction, which you need when a protocol gives you an integer and you must produce a character. Because ASCII and Unicode agree on the 0 to 127 range, casting an int in that range to char produces the matching ASCII glyph. For control codes that have no printable glyph, the abbreviation from RFC 20, such as LF or CR, is the right label to log instead of attempting to print the byte.

The fourth pattern is line-ending handling. Java's BufferedReader reads LF on Unix-style files and CRLF on Windows-style files, while Scanner treats CR, LF, and CRLF as line terminators. Knowing that LF is decimal 10 and CR is decimal 13 lets you write explicit scanners that tokenize on either byte, which is useful when you parse network protocols or compact binary logs where mixed line endings carry meaning. The RFC 20 conventions apply here, but CR, LF, and CRLF are platform and protocol conventions that depend on context, so the table gives you the numbers while the surrounding code decides what they mean.

Search Tips and Edge Cases Worth Knowing

A few behaviors of the ASCII Table save time once you internalize them. The category filter narrows the table to controls, space, punctuation, digits, uppercase letters, lowercase letters, or Delete, and every matching row remains visible rather than being truncated, so a broad category like "punctuation" still shows the full punctuation range. Decimal 32 is shown explicitly as SP and lives in the Space category, while decimal 127 is shown as DEL in its own Delete category because RFC 20 notes that DEL is not a control character in the strict sense. These distinctions keep the table honest about what is printable, what is a control, and what is the historical delete sentinel.

When you paste a row into a comment, prefer the four numeric notations together rather than just the decimal. Code reviewers can spot a typo in 0x4A faster than in the bare number 74, and a bug report that lists decimal, hex, octal, and binary values survives reformatting by anyone reading the ticket. If a byte above 127 appears in a file you are decoding, the table will not have it because that range is outside standard ASCII; identify the actual encoding first, because the number alone does not tell you which glyph was meant. ECMA-6 documents the 7-bit scope that produces this boundary, and a copy of the relevant standards reference can sit next to the tool in your bookmarks for exactly those moments.